Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that CombinedProcessor reinitializes self.combined_maintenance_data #86

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions circuit_maintenance_parser/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class CombinedProcessor(GenericProcessor):
# The CombinedProcessor will consolidate all the parsed data into this variable
combined_maintenance_data: Dict = {}

def process(self, data: NotificationData, extended_data: Dict) -> Iterable[Maintenance]:
"""Extend base class process method to ensure that self.combined_maintenance_data is initialized correctly."""
self.combined_maintenance_data = {}
return super().process(data, extended_data)

def process_hook(self, maintenances_extracted_data, maintenances_data):
"""All the parsers contribute with a subset of data that is extended.

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class FakeParser1(FakeParser):
# Fake data used for SimpleProcessor
fake_data = NotificationData.init_from_raw("fake_type", b"fake data")
# Fake data used for CombinedProcessor
fake_data_type_0 = NotificationData.init_from_raw("fake_type_0", b"fake data")
fake_data_for_combined = NotificationData.init_from_raw("fake_type_0", b"fake data")
if fake_data_for_combined:
fake_data_for_combined.data_parts.append(DataPart("fake_type_1", b"fake data"))
Expand Down Expand Up @@ -107,3 +108,18 @@ def test_combinedprocessor_missing_data():
processor.process(fake_data_for_combined, EXTENDED_DATA)

assert "Not enough information available to create a Maintenance notification" in str(e_info)


def test_combinedprocessor_bleed():
"""Test CombinedProcessor to make sure that information from one processing doesn't bleed over to another."""
processor = CombinedProcessor(data_parsers=[FakeParser0, FakeParser1])

with patch("circuit_maintenance_parser.processor.Maintenance") as mock_maintenance:
processor.process(fake_data_for_combined, EXTENDED_DATA)
assert mock_maintenance.call_count == 1
mock_maintenance.assert_called_with(**{**PARSED_DATA[0], **PARSED_DATA[1], **EXTENDED_DATA})

with patch("circuit_maintenance_parser.processor.Maintenance") as mock_maintenance:
processor.process(fake_data_type_0, EXTENDED_DATA)
assert mock_maintenance.call_count == 1
mock_maintenance.assert_called_with(**{**PARSED_DATA[0], **EXTENDED_DATA})