Skip to content

Commit

Permalink
Word smithing and update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Sep 27, 2017
1 parent f31547b commit f6cda81
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/cosmos/core_ext/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def is_printable?
# @return Converts the String into either a Float, Integer, or Array
# depending on what the String represents. It can successfully convert
# floating point numbers in both fixed and scientific notation, integers
# in hexadecimal notation, and Arrays. If it can not be converted into
# in hexadecimal notation, and Arrays. If it can't be converted into
# any of the above then the original String is returned.
def convert_to_value
return_value = self
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/packet_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ def process_current_item(parser, keyword, params)

# Define the units of the current telemetry item
when 'UNITS'
raise @parser.error("Items with STATES can not define UNITS") if @current_item.states
raise parser.error("Items with STATE can't define UNITS") if @current_item.states
usage = "UNITS <FULL UNITS NAME> <ABBREVIATED UNITS NAME>"
parser.verify_num_parameters(2, 2, usage)
@current_item.units_full = params[0]
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/parsers/format_string_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FormatStringParser
# @param parser [ConfigParser] Configuration parser
# @param item [Packet] The current item
def self.parse(parser, item)
raise parser.error("Items with STATES can not define FORMAT_STRING") if item.states
raise parser.error("Items with STATE can't define FORMAT_STRING") if item.states
@parser = FormatStringParser.new(parser)
@parser.verify_parameters()
@parser.create_format_string(item)
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/parsers/limits_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LimitsParser
# @param warnings [Array<String>] Array of string warnings which will be
# appended with any warnings found when parsing the limits
def self.parse(parser, packet, cmd_or_tlm, item, warnings)
raise parser.error("Items with STATES can not define LIMITS") if item.states
raise parser.error("Items with STATE can't define LIMITS") if item.states
@parser = LimitsParser.new(parser)
@parser.verify_parameters(cmd_or_tlm)
@parser.create_limits(packet, item, warnings)
Expand Down
6 changes: 3 additions & 3 deletions lib/cosmos/packets/parsers/state_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class StateParser
# @param warnings [Array<String>] Array of string warnings which will be
# appended with any warnings found when parsing the limits
def self.parse(parser, packet, cmd_or_tlm, item, warnings)
raise parser.error("Items with LIMITS can not define STATES") if item.limits.values
raise parser.error("Items with FORMAT_STRING can not define STATES") if item.format_string
raise parser.error("Items with UNITS can not define STATES") if item.units
raise parser.error("Items with LIMITS can't define STATE") if item.limits.values
raise parser.error("Items with FORMAT_STRING can't define STATE") if item.format_string
raise parser.error("Items with UNITS can't define STATE") if item.units
@parser = StateParser.new(parser)
@parser.verify_parameters(cmd_or_tlm)
@parser.create_state(packet, cmd_or_tlm, item, warnings)
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/tools/cmd_sequence/cmd_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def run_sequence(filename)
end

# Finds the given filename by looking in the system sequences path as
# well as in each target's sequences directory. If the file can not be
# well as in each target's sequences directory. If the file can't be
# found an Error dialog is created.
# @param filename [String] Filename to locate
def find_sequence(filename)
Expand Down
6 changes: 2 additions & 4 deletions lib/cosmos/top_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ def self.safe_thread(name, retry_attempts = 0)
#
# @param class_name_or_class_filename [String] The name of the class or the file which contains the
# Ruby class to require
# @param log_error [Boolean] Whether to log an error if we can not require
# the class
# @param log_error [Boolean] Whether to log an error if we can't require the class
def self.require_class(class_name_or_class_filename, log_error = true)
if class_name_or_class_filename.downcase[-3..-1] == '.rb' or (class_name_or_class_filename[0] == class_name_or_class_filename[0].downcase)
class_filename = class_name_or_class_filename
Expand All @@ -627,8 +626,7 @@ def self.require_class(class_name_or_class_filename, log_error = true)
# Requires a file with a standard error message if it fails
#
# @param filename [String] The name of the file to require
# @param log_error [Boolean] Whether to log an error if we can not require
# the class
# @param log_error [Boolean] Whether to log an error if we can't require the class
def self.require_file(filename, log_error = true)
begin
require filename
Expand Down
11 changes: 11 additions & 0 deletions spec/packets/packet_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,17 @@ module Cosmos
expect(@pc.telemetry["TGT1"]["PKT1"].read("ITEM1",:WITH_UNITS)).to eql "0 V"
tf.unlink
end

it "complains if STATE defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' ITEM item1 0 8 UINT'
tf.puts ' STATE ONE 1'
tf.puts ' UNITS Volts V'
tf.close
expect { @pc.process_file(tf.path, "TGT1") }.to raise_error(ConfigParser::Error, /Items with STATE can't define UNITS/)
tf.unlink
end
end

context "with META" do
Expand Down
11 changes: 11 additions & 0 deletions spec/packets/parsers/format_string_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ module Cosmos
tf.unlink
end

it "complains if STATE is defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts 'ITEM myitem 0 8 UINT "Test Item"'
tf.puts 'STATE ONE 1'
tf.puts "FORMAT_STRING '0x%x'"
tf.close
expect { @pc.process_file(tf.path, "TGT1") }.to raise_error(ConfigParser::Error, /Items with STATE can't define FORMAT_STRING/)
tf.unlink
end

it "complains about invalid format strings" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
Expand Down
31 changes: 21 additions & 10 deletions spec/packets/parsers/limits_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Cosmos
@pc = PacketConfig.new
end

it "raises if a current item is not defined" do
it "complains if a current item is not defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' LIMITS mylimits 1 ENABLED 0 10 20 30 12 18'
Expand All @@ -32,7 +32,7 @@ module Cosmos
tf.unlink
end

it "raises if there are not enough parameters" do
it "complains if there are not enough parameters" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' ITEM myitem 0 8 UINT "Test Item"'
Expand All @@ -50,7 +50,7 @@ module Cosmos
tf.unlink
end

it "raises if there are too many parameters" do
it "complains if there are too many parameters" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' ITEM myitem 0 8 UINT "Test Item"'
Expand All @@ -60,7 +60,7 @@ module Cosmos
tf.unlink
end

it "raises if applied to a command PARAMETER" do
it "complains if applied to a command PARAMETER" do
tf = Tempfile.new('unittest')
tf.puts 'COMMAND tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_PARAMETER item1 16 UINT 0 0 0 "Item"'
Expand All @@ -70,7 +70,7 @@ module Cosmos
tf.unlink
end

it "raises if a DEFAULT limits set isn't defined" do
it "complains if a DEFAULT limits set isn't defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_ITEM item1 16 UINT "Item"'
Expand All @@ -80,6 +80,17 @@ module Cosmos
tf.unlink
end

it "complains if STATES are defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_ITEM item1 16 UINT "Item"'
tf.puts ' STATE ONE 1'
tf.puts ' LIMITS TVAC 3 ENABLED 1 2 6 7 3 5'
tf.close
expect { @pc.process_file(tf.path, "TGT1") }.to raise_error(ConfigParser::Error, /Items with STATE can't define LIMITS/)
tf.unlink
end

it "sets a warning if a new limits set persistence isn't consistent with DEFAULT" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
Expand Down Expand Up @@ -116,7 +127,7 @@ module Cosmos
tf.unlink
end

it "raises if the second parameter isn't a number" do
it "complains if the second parameter isn't a number" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_ITEM item1 16 UINT "Item"'
Expand All @@ -126,7 +137,7 @@ module Cosmos
tf.unlink
end

it "raises if the third parameter isn't ENABLED or DISABLED" do
it "complains if the third parameter isn't ENABLED or DISABLED" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_ITEM item1 16 UINT "Item"'
Expand All @@ -136,7 +147,7 @@ module Cosmos
tf.unlink
end

it "raises if the fourth through ninth parameter aren't numbers'" do
it "complains if the fourth through ninth parameter aren't numbers'" do
msgs = ['','','','','red low','yellow low','yellow high','red high','green low','green high']
(4..9).each do |index|
tf = Tempfile.new('unittest')
Expand All @@ -151,7 +162,7 @@ module Cosmos
end
end

it "raises if the 4 limits are out of order" do
it "complains if the 4 limits are out of order" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_ITEM item1 16 UINT "Item"'
Expand Down Expand Up @@ -185,7 +196,7 @@ module Cosmos
tf.unlink
end

it "raises if the 6 limits are out of order" do
it "complains if the 6 limits are out of order" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' APPEND_ITEM item1 16 UINT "Item"'
Expand Down
10 changes: 5 additions & 5 deletions spec/packets/parsers/packet_item_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Cosmos
tf.unlink
end

it "raises if given an incomplete definition" do
it "complains if given an incomplete definition" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Description"'
tf.puts ' ITEM ITEM1 8 0'
Expand Down Expand Up @@ -63,7 +63,7 @@ module Cosmos
tf.unlink
end

it "raises if given a bad bit offset" do
it "complains if given a bad bit offset" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Description"'
tf.puts ' ITEM ITEM1 EIGHT 0 DERIVED'
Expand All @@ -72,7 +72,7 @@ module Cosmos
tf.unlink
end

it "raises if given a bad bit size" do
it "complains if given a bad bit size" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Description"'
tf.puts ' ITEM ITEM1 8 ZERO DERIVED'
Expand All @@ -81,7 +81,7 @@ module Cosmos
tf.unlink
end

it "raises if given a bad array size" do
it "complains if given a bad array size" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Description"'
tf.puts ' ARRAY_ITEM ITEM3 0 32 FLOAT EIGHT'
Expand Down Expand Up @@ -178,7 +178,7 @@ module Cosmos
tf.unlink
end

it "raises if given an incomplete definition" do
it "complains if given an incomplete definition" do
tf = Tempfile.new('unittest')
tf.puts 'COMMAND tgt1 pkt1 LITTLE_ENDIAN "Description"'
tf.puts ' PARAMETER ITEM1 8 0'
Expand Down
33 changes: 33 additions & 0 deletions spec/packets/parsers/state_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ module Cosmos
tf.unlink
end

it "complains if LIMITS defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' ITEM myitem 0 8 UINT "Test Item"'
tf.puts ' LIMITS DEFAULT 3 ENABLED 1 2 6 7 3 5'
tf.puts ' STATE ONE 1'
tf.close
expect { @pc.process_file(tf.path, "TGT1") }.to raise_error(ConfigParser::Error, /Items with LIMITS can't define STATE/)
tf.unlink
end

it "complains if FORMAT_STRING defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' ITEM myitem 0 8 UINT "Test Item"'
tf.puts ' FORMAT_STRING "0x%x"'
tf.puts ' STATE ONE 1'
tf.close
expect { @pc.process_file(tf.path, "TGT1") }.to raise_error(ConfigParser::Error, /Items with FORMAT_STRING can't define STATE/)
tf.unlink
end

it "complains if UNITS defined" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
tf.puts ' ITEM myitem 0 8 UINT "Test Item"'
tf.puts ' UNITS Kelvin K'
tf.puts ' STATE ONE 1'
tf.close
expect { @pc.process_file(tf.path, "TGT1") }.to raise_error(ConfigParser::Error, /Items with UNITS can't define STATE/)
tf.unlink
end

it "complains if there are too many parameters" do
tf = Tempfile.new('unittest')
tf.puts 'TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"'
Expand Down

0 comments on commit f6cda81

Please sign in to comment.