Skip to content

Commit

Permalink
Move where remove_none is being called so we stop trying to compare…
Browse files Browse the repository at this point in the history
… NoneTypes and Numbers
  • Loading branch information
erunks committed Sep 1, 2020
1 parent 5999d03 commit 9fe20f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/InternetStatusReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ def measure_latency(self):
from json import dumps
from sys import exc_info
from tcp_latency import measure_latency
from src.utils import calculate_standard_deviation
from src.utils import calculate_standard_deviation, remove_none

results = {}
for latency_address in self.latency_addresses:
try:
runs = int(getenv('LATENCY_RUNS'))
data = measure_latency(host=latency_address, port=80, runs=runs, timeout=2.5)
data = remove_none(data)
mean, deviation = calculate_standard_deviation(data, self.logger)
except:
self.logger.exception(f'Unexpected error: {exc_info()[0]}')
Expand Down
15 changes: 4 additions & 11 deletions src/tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,16 @@ def test_calculate_standard_deviation_when_an_array_of_numbers_is_passed(self, m
)

@patch('logging.Logger')
def test_calculate_standard_deviation_when_an_array_of_numbers_and_none_is_passed(self, mock_logger):
def test_calculate_standard_deviation_when_an_array_of_one_number_is_passed(self, mock_logger):
self.assertEqual(
calculate_standard_deviation([None,1.0,2,3,None,4.0,5], mock_logger),
(3.0, 1.5811388300841898)
)

@patch('logging.Logger')
def test_calculate_standard_deviation_when_an_array_of_one_number_and_none_is_passed(self, mock_logger):
self.assertEqual(
calculate_standard_deviation([None,1.0,None], mock_logger),
calculate_standard_deviation([1.0], mock_logger),
(1.0, 0)
)

@patch('logging.Logger')
def test_calculate_standard_deviation_when_an_array_of_none_is_passed(self, mock_logger):
def test_calculate_standard_deviation_when_an_empty_array_is_passed(self, mock_logger):
self.assertEqual(
calculate_standard_deviation([None, None, None, None], mock_logger),
calculate_standard_deviation([], mock_logger),
None
)

Expand Down
1 change: 0 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def calculate_standard_deviation(data, logger):
from math import sqrt
from sys import exc_info

data = remove_none(data)
length = len(data)

if length == 0:
Expand Down

0 comments on commit 9fe20f7

Please sign in to comment.