From f6cda81af51cf9ab05507ccd01b730a4438b5813 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Wed, 27 Sep 2017 16:16:19 -0600 Subject: [PATCH] Word smithing and update specs --- lib/cosmos/core_ext/string.rb | 2 +- lib/cosmos/packets/packet_config.rb | 2 +- .../packets/parsers/format_string_parser.rb | 2 +- lib/cosmos/packets/parsers/limits_parser.rb | 2 +- lib/cosmos/packets/parsers/state_parser.rb | 6 ++-- lib/cosmos/tools/cmd_sequence/cmd_sequence.rb | 2 +- lib/cosmos/top_level.rb | 6 ++-- spec/packets/packet_config_spec.rb | 11 +++++++ .../parsers/format_string_parser_spec.rb | 11 +++++++ spec/packets/parsers/limits_parser_spec.rb | 31 +++++++++++------ .../parsers/packet_item_parser_spec.rb | 10 +++--- spec/packets/parsers/state_parser_spec.rb | 33 +++++++++++++++++++ 12 files changed, 91 insertions(+), 27 deletions(-) diff --git a/lib/cosmos/core_ext/string.rb b/lib/cosmos/core_ext/string.rb index cee4c0c3a..ea97ef316 100644 --- a/lib/cosmos/core_ext/string.rb +++ b/lib/cosmos/core_ext/string.rb @@ -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 diff --git a/lib/cosmos/packets/packet_config.rb b/lib/cosmos/packets/packet_config.rb index 7b7a5a123..da4f0667e 100644 --- a/lib/cosmos/packets/packet_config.rb +++ b/lib/cosmos/packets/packet_config.rb @@ -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 " parser.verify_num_parameters(2, 2, usage) @current_item.units_full = params[0] diff --git a/lib/cosmos/packets/parsers/format_string_parser.rb b/lib/cosmos/packets/parsers/format_string_parser.rb index 1d299a266..08042a356 100644 --- a/lib/cosmos/packets/parsers/format_string_parser.rb +++ b/lib/cosmos/packets/parsers/format_string_parser.rb @@ -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) diff --git a/lib/cosmos/packets/parsers/limits_parser.rb b/lib/cosmos/packets/parsers/limits_parser.rb index 9cf74704a..bd7e2bff8 100644 --- a/lib/cosmos/packets/parsers/limits_parser.rb +++ b/lib/cosmos/packets/parsers/limits_parser.rb @@ -18,7 +18,7 @@ class LimitsParser # @param warnings [Array] 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) diff --git a/lib/cosmos/packets/parsers/state_parser.rb b/lib/cosmos/packets/parsers/state_parser.rb index e11464111..e1ffbd996 100644 --- a/lib/cosmos/packets/parsers/state_parser.rb +++ b/lib/cosmos/packets/parsers/state_parser.rb @@ -20,9 +20,9 @@ class StateParser # @param warnings [Array] 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) diff --git a/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb b/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb index c4e33446e..7fff5af05 100644 --- a/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb +++ b/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb @@ -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) diff --git a/lib/cosmos/top_level.rb b/lib/cosmos/top_level.rb index a1f7c5870..e796d487a 100644 --- a/lib/cosmos/top_level.rb +++ b/lib/cosmos/top_level.rb @@ -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 @@ -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 diff --git a/spec/packets/packet_config_spec.rb b/spec/packets/packet_config_spec.rb index ab757aea6..af3541f4e 100644 --- a/spec/packets/packet_config_spec.rb +++ b/spec/packets/packet_config_spec.rb @@ -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 diff --git a/spec/packets/parsers/format_string_parser_spec.rb b/spec/packets/parsers/format_string_parser_spec.rb index 12c8e1346..0eff03f22 100644 --- a/spec/packets/parsers/format_string_parser_spec.rb +++ b/spec/packets/parsers/format_string_parser_spec.rb @@ -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"' diff --git a/spec/packets/parsers/limits_parser_spec.rb b/spec/packets/parsers/limits_parser_spec.rb index e0af8a04b..fe29a9370 100644 --- a/spec/packets/parsers/limits_parser_spec.rb +++ b/spec/packets/parsers/limits_parser_spec.rb @@ -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' @@ -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"' @@ -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"' @@ -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"' @@ -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"' @@ -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"' @@ -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"' @@ -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"' @@ -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') @@ -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"' @@ -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"' diff --git a/spec/packets/parsers/packet_item_parser_spec.rb b/spec/packets/parsers/packet_item_parser_spec.rb index debbf883b..0e19ec89d 100644 --- a/spec/packets/parsers/packet_item_parser_spec.rb +++ b/spec/packets/parsers/packet_item_parser_spec.rb @@ -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' @@ -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' @@ -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' @@ -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' @@ -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' diff --git a/spec/packets/parsers/state_parser_spec.rb b/spec/packets/parsers/state_parser_spec.rb index 56f4b41a0..56c0c08ce 100644 --- a/spec/packets/parsers/state_parser_spec.rb +++ b/spec/packets/parsers/state_parser_spec.rb @@ -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"'