Skip to content

Commit

Permalink
Call abs on all tolerance values. Fix deprecation warning in SimpleCov
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Apr 29, 2016
1 parent e93f785 commit fb659fb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cosmos.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency 'listen', '~> 2.0'
s.add_development_dependency 'guard-bundler', '~> 2.0'
s.add_development_dependency 'guard-rspec', '~> 4.0'
s.add_development_dependency 'simplecov', '~> 0.10'
s.add_development_dependency 'simplecov', '~> 0.11'
s.add_development_dependency 'ruby-prof', '~> 0.15.0'
s.add_development_dependency 'coveralls', '~> 0.8'
s.add_development_dependency 'benchmark-ips', '~> 2.0'
Expand Down
10 changes: 5 additions & 5 deletions lib/cosmos/script/scripting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,13 @@ def check_tolerance_process_args(args, function_name)
when 3
target_name, packet_name, item_name = extract_fields_from_tlm_text(args[0])
expected_value = args[1]
tolerance = args[2]
tolerance = args[2].abs
when 5
target_name = args[0]
packet_name = args[1]
item_name = args[2]
expected_value = args[3]
tolerance = args[4]
tolerance = args[4].abs
else
# Invalid number of arguments
raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{function_name}()"
Expand Down Expand Up @@ -676,7 +676,7 @@ def wait_tolerance_process_args(args, function_name)
when 4, 5
target_name, packet_name, item_name = extract_fields_from_tlm_text(args[0])
expected_value = args[1]
tolerance = args[2]
tolerance = args[2].abs
timeout = args[3]
if args.length == 5
polling_rate = args[4]
Expand All @@ -688,7 +688,7 @@ def wait_tolerance_process_args(args, function_name)
packet_name = args[1]
item_name = args[2]
expected_value = args[3]
tolerance = args[4]
tolerance = args[4].abs
timeout = args[5]
if args.length == 7
polling_rate = args[6]
Expand Down Expand Up @@ -799,7 +799,7 @@ def cosmos_script_wait_implementation(target_name, packet_name, item_name, value

def cosmos_script_wait_implementation_tolerance(target_name, packet_name, item_name, value_type, expected_value, tolerance, timeout, polling_rate = DEFAULT_TLM_POLLING_RATE)
_cosmos_script_wait_implementation(target_name, packet_name, item_name, value_type, timeout, polling_rate) do
"((#{expected_value} - #{tolerance})..(#{expected_value} + #{tolerance})).include? value"
"((#{expected_value} - #{tolerance.abs})..(#{expected_value} + #{tolerance.abs})).include? value"
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/script/scripting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@ class ScriptRunner; end
stdout.rewind
end
end

it "handles a negative tolerance" do
capture_io do |stdout|
check_tolerance("INST HEALTH_STATUS TEMP1", -100.0, -1)
expect(stdout.string).to match "CHECK: INST HEALTH_STATUS TEMP1 was within range"
stdout.rewind

check_tolerance("INST", "HEALTH_STATUS", "TEMP1", -100.0, -1)
expect(stdout.string).to match "CHECK: INST HEALTH_STATUS TEMP1 was within range"
stdout.rewind

expect { check_tolerance("INST HEALTH_STATUS TEMP1", -200.0, -1) }.to raise_error(CheckError, /CHECK: INST HEALTH_STATUS TEMP1 failed to be within range/)
stdout.rewind

check_tolerance_raw("INST HEALTH_STATUS TEMP1", 0, -1)
expect(stdout.string).to match "CHECK: INST HEALTH_STATUS TEMP1 was within range"
stdout.rewind

expect { check_tolerance_raw("INST HEALTH_STATUS TEMP1", 100, -1) }.to raise_error(CheckError, /CHECK: INST HEALTH_STATUS TEMP1 failed to be within range/)
stdout.rewind
end
end
end

describe "check_expression" do
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def load(file, wrap = false)
require 'simplecov'
require 'coveralls'
Coveralls.wear!
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
])
SimpleCov.start do
merge_timeout 12 * 60 * 60 # merge the last 12 hours of results
add_filter '/spec/'
Expand Down

0 comments on commit fb659fb

Please sign in to comment.