Skip to content

Commit

Permalink
Complete code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
the-other-james committed Sep 21, 2023
1 parent 3f294e3 commit 2be243f
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions onair/data_handling/parsers/csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def has_more(self):
return self.frame_index < len(self.sim_data)

# Return whether or not there is data
# TODO: This function may be removed with future clean-up
def has_data(self):
if self.sim_data == []:
return False
return True
86 changes: 86 additions & 0 deletions test/onair/data_handling/parsers/test_csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,89 @@ def test_CSV_get_vehicle_metadata_returns_list_of_headers_and_list_of_test_assig

# Assert
assert result == expected_result

# CSV get_next test
def test_CSV_get_next_increments_index_and_returns_current_frame_of_data(setup_teardown):
# Arrange
fake_frame_index = 10
fake_sim_data = []
for i in range(fake_frame_index + 1):
fake_sim_data.append(MagicMock())

expected_result = fake_sim_data[fake_frame_index]

pytest.cut.frame_index = fake_frame_index
pytest.cut.sim_data = fake_sim_data

# Act
result = pytest.cut.get_next()

# Assert
assert result == expected_result
assert pytest.cut.frame_index == fake_frame_index + 1

# CSV has_more test
def test_CSV_has_more_returns_true_when_index_less_than_number_of_frames(setup_teardown):
# Arrange
fake_frame_index = 10
fake_sim_data = []
for i in range(fake_frame_index + 1):
fake_sim_data.append(MagicMock())

expected_result = True

pytest.cut.frame_index = 5
pytest.cut.sim_data = fake_sim_data

# Act
result = pytest.cut.has_more()

# Assert
assert result == expected_result

def test_CSV_has_more_returns_false_when_index_equal_than_number_of_frames(setup_teardown):
# Arrange
fake_frame_index = 10
fake_sim_data = []
for i in range(fake_frame_index):
fake_sim_data.append(MagicMock())

expected_result = False

pytest.cut.frame_index = fake_frame_index
pytest.cut.sim_data = fake_sim_data

# Act
result = pytest.cut.has_more()

# Assert
assert result == expected_result

# CSV has_data test
def test_CSV_has_data_returns_true_sim_data_is_non_empty(setup_teardown):
# Arrange
fake_sim_data = MagicMock()

expected_result = True

pytest.cut.sim_data = fake_sim_data

# Act
result = pytest.cut.has_data()

# Assert
assert result == expected_result

def test_CSV_has_data_returns_false_sim_data_is_empty(setup_teardown):
# Arrange
fake_sim_data = []

expected_result = False

pytest.cut.sim_data = fake_sim_data

# Act
result = pytest.cut.has_data()

# Assert
assert result == expected_result
33 changes: 33 additions & 0 deletions test/onair/data_handling/parsers/test_on_air_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def test_OnAirDataSource_raises_error_because_of_unimplemented_abstract_methods(
assert "Can't instantiate abstract class OnAirDataSource with" in e_info.__str__()
assert "process_data_file" in e_info.__str__()
assert "parse_meta_data_file" in e_info.__str__()
assert "get_next" in e_info.__str__()
assert "has_more" in e_info.__str__()
assert "has_data" in e_info.__str__()

# Incomplete plugin call tests
def test_OnAirDataSource_raises_error_when_an_inherited_class_is_instantiated_because_abstract_methods_are_not_implemented_by_that_class():
Expand All @@ -111,6 +114,9 @@ def test_OnAirDataSource_raises_error_when_an_inherited_class_is_instantiated_be
assert "Can't instantiate abstract class IncompleteOnAirDataSource with" in e_info.__str__()
assert "process_data_file" in e_info.__str__()
assert "parse_meta_data_file" in e_info.__str__()
assert "get_next" in e_info.__str__()
assert "has_more" in e_info.__str__()
assert "has_data" in e_info.__str__()

def test_OnAirDataSource_raises_error_when_an_inherited_class_calls_abstract_method_process_data_file():
# Act
Expand All @@ -129,3 +135,30 @@ def test_OnAirDataSource_raises_error_when_an_inherited_class_calls_abstract_met
with pytest.raises(NotImplementedError) as e_info:
cut.parse_meta_data_file(None, None)
assert "NotImplementedError" in e_info.__str__()

def test_OnAirDataSource_raises_error_when_an_inherited_class_calls_abstract_method_get_next():
# Act
cut = BadFakeOnAirDataSource.__new__(BadFakeOnAirDataSource)

# populate list with the functions that should raise exceptions when called.
with pytest.raises(NotImplementedError) as e_info:
cut.get_next()
assert "NotImplementedError" in e_info.__str__()

def test_OnAirDataSource_raises_error_when_an_inherited_class_calls_abstract_method_has_more():
# Act
cut = BadFakeOnAirDataSource.__new__(BadFakeOnAirDataSource)

# populate list with the functions that should raise exceptions when called.
with pytest.raises(NotImplementedError) as e_info:
cut.has_more()
assert "NotImplementedError" in e_info.__str__()

def test_OnAirDataSource_raises_error_when_an_inherited_class_calls_abstract_method_has_data():
# Act
cut = BadFakeOnAirDataSource.__new__(BadFakeOnAirDataSource)

# populate list with the functions that should raise exceptions when called.
with pytest.raises(NotImplementedError) as e_info:
cut.has_data()
assert "NotImplementedError" in e_info.__str__()

0 comments on commit 2be243f

Please sign in to comment.