From 9b0eb4f12859138e1b5cb45bd542b37ce5ce8e6f Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Thu, 14 Mar 2024 11:42:49 +0100 Subject: [PATCH 01/11] Move code to be reused in regression test --- tests/benchmark_otanalytics.py | 8 +++--- tests/conftest.py | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/tests/benchmark_otanalytics.py b/tests/benchmark_otanalytics.py index 363ed64e3..f28e5f486 100644 --- a/tests/benchmark_otanalytics.py +++ b/tests/benchmark_otanalytics.py @@ -15,7 +15,6 @@ CUTTING_SECTION_MARKER, ) from OTAnalytics.application.datastore import DetectionMetadata, TrackParser -from OTAnalytics.application.parser.cli_parser import CliArguments from OTAnalytics.application.run_configuration import RunConfiguration from OTAnalytics.application.use_cases.create_events import CreateEvents from OTAnalytics.application.use_cases.cut_tracks_with_sections import ( @@ -74,8 +73,8 @@ CLASS_SCOOTER, ) from OTAnalytics.plugin_ui.main_application import ApplicationStarter +from tests.conftest import NUM_PROCESSES, create_run_config -NUM_PROCESSES = 1 PYTHON = "PYTHON" PANDAS = "PANDAS" CURRENT_DATASET_TYPE = PANDAS @@ -112,7 +111,8 @@ class UseCaseProvider: @property def run_config(self) -> RunConfiguration: - cli_args = CliArguments( + return create_run_config( + flow_parser=self._flow_parser, start_cli=True, debug=False, logfile_overwrite=True, @@ -121,11 +121,9 @@ def run_config(self) -> RunConfiguration: otflow_file=str(self._otflow_file), save_dir=self._save_dir, event_formats=["otevents"], - num_processes=NUM_PROCESSES, include_classes=list(self._include_classes), exclude_classes=list(self._exclude_classes), ) - return RunConfiguration(self._flow_parser, cli_args) @property def sections(self) -> list[Section]: diff --git a/tests/conftest.py b/tests/conftest.py index a4addc456..1caa90453 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,9 @@ import pytest +from OTAnalytics.application.datastore import FlowParser +from OTAnalytics.application.parser.cli_parser import CliArguments +from OTAnalytics.application.run_configuration import RunConfiguration from OTAnalytics.domain.geometry import Coordinate from OTAnalytics.domain.section import LineSection, Section, SectionId from OTAnalytics.domain.track import Track, TrackId @@ -317,3 +320,49 @@ def pandas_track_segment_dataset_builder( track_segment_dataset_builder_provider: TrackSegmentDatasetBuilderProvider, ) -> TrackSegmentDatasetBuilder: return track_segment_dataset_builder_provider.provide(PANDAS) + + +NUM_PROCESSES = 1 + + +def create_run_config( + track_files: list[str], + otflow_file: str, + save_dir: str, + event_formats: list[str], + flow_parser: FlowParser, + start_cli: bool = True, + debug: bool = False, + logfile_overwrite: bool = True, + track_export: bool = False, + num_processes: int = NUM_PROCESSES, + count_intervals: list[int] | None = None, + config_file: str | None = None, + save_name: str | None = None, + save_suffix: str | None = None, + log_file: str | None = None, + include_classes: list[str] | None = None, + exclude_classes: list[str] | None = None, +) -> RunConfiguration: + cli_args = CliArguments( + start_cli=start_cli, + debug=debug, + logfile_overwrite=logfile_overwrite, + track_export=track_export, + track_files=track_files, + otflow_file=otflow_file, + save_dir=save_dir, + save_name=save_name, + count_intervals=count_intervals, + event_formats=event_formats, + num_processes=num_processes, + config_file=config_file, + save_suffix=save_suffix, + log_file=log_file, + include_classes=include_classes, + exclude_classes=exclude_classes, + ) + return RunConfiguration(flow_parser, cli_args) + + +NUM_PROCESSES = 1 From d6bc4b851908647851dcf4a18813c0e0eb5b14d2 Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Thu, 14 Mar 2024 11:43:00 +0100 Subject: [PATCH 02/11] Suppress future warnings --- OTAnalytics/__main__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OTAnalytics/__main__.py b/OTAnalytics/__main__.py index ee94fe406..0f1b33cdc 100644 --- a/OTAnalytics/__main__.py +++ b/OTAnalytics/__main__.py @@ -1,5 +1,9 @@ +import warnings + from OTAnalytics.plugin_ui.main_application import ApplicationStarter +warnings.simplefilter(action="ignore", category=FutureWarning) + def main() -> None: ApplicationStarter().start() From 7928b00bb248883cd4d1325a988820ca9eb81d7b Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Fri, 15 Mar 2024 14:59:33 +0100 Subject: [PATCH 03/11] Add regression test --- tests/regression_otanalytics.py | 155 ++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/regression_otanalytics.py diff --git a/tests/regression_otanalytics.py b/tests/regression_otanalytics.py new file mode 100644 index 000000000..4d6ae7f45 --- /dev/null +++ b/tests/regression_otanalytics.py @@ -0,0 +1,155 @@ +from pathlib import Path + +import pytest + +from OTAnalytics.application.datastore import FlowParser +from OTAnalytics.plugin_parser.otvision_parser import OtFlowParser +from OTAnalytics.plugin_ui.main_application import ApplicationStarter +from tests.conftest import create_run_config + + +def to_cli_path(test_data_dir: Path, input_file: str) -> str: + return str(Path(test_data_dir / input_file).absolute()) + + +@pytest.fixture(scope="module") +def track_file_15min(test_data_dir: Path) -> list[str]: + return [to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_08-00-00.ottrk")] + + +@pytest.fixture(scope="module") +def track_files_2hours(test_data_dir: Path) -> list[str]: + return [ + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_08-00-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_08-15-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_08-30-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_08-45-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_09-00-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_09-15-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_09-30-00.ottrk"), + to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24_09-45-00.ottrk"), + ] + + +@pytest.fixture(scope="module") +def otflow_file(test_data_dir: Path) -> str: + return to_cli_path(test_data_dir, "OTCamera19_FR20_2023-05-24.otflow") + + +@pytest.fixture +def otflow_parser() -> FlowParser: + return OtFlowParser() + + +class TestRegressionCompleteApplication: + def test_15_min( + self, + otflow_file: str, + test_data_dir: Path, + test_data_tmp_dir: Path, + track_file_15min: list[str], + otflow_parser: FlowParser, + ) -> None: + test_data = track_file_15min + test_interval = "15min" + self._execute_test( + otflow_file, + test_data, + test_data_dir, + test_data_tmp_dir, + test_interval, + otflow_parser, + count_interval=15, + ) + + def test_2_h_single( + self, + otflow_file: str, + test_data_dir: Path, + test_data_tmp_dir: Path, + track_files_2hours: list[str], + otflow_parser: FlowParser, + ) -> None: + for track_file in track_files_2hours: + test_data = [track_file] + test_interval = "15min" + self._execute_test( + otflow_file, + test_data, + test_data_dir, + test_data_tmp_dir, + test_interval, + otflow_parser, + count_interval=15, + ) + + def test_2_h( + self, + otflow_file: str, + test_data_dir: Path, + test_data_tmp_dir: Path, + track_files_2hours: list[str], + otflow_parser: FlowParser, + ) -> None: + test_data = track_files_2hours + test_interval = "2h" + self._execute_test( + otflow_file, + test_data, + test_data_dir, + test_data_tmp_dir, + test_interval, + otflow_parser, + count_interval=120, + ) + + def _execute_test( + self, + otflow_file: str, + test_data: list[str], + test_data_dir: Path, + test_data_tmp_dir: Path, + test_interval: str, + otflow_parser: FlowParser, + count_interval: int, + ) -> None: + save_name = f"{Path(test_data[0]).stem}_{test_interval}" + + run_config = create_run_config( + track_files=[str(_file) for _file in test_data], + otflow_file=str(otflow_file), + save_dir=str(test_data_tmp_dir), + save_name=save_name, + event_formats=["csv"], + count_intervals=[count_interval], + flow_parser=otflow_parser, + ) + ApplicationStarter().start_cli(run_config) + + actual_events_file = Path(test_data_tmp_dir / save_name).with_suffix( + ".events.csv" + ) + expected_events_file = Path(test_data_dir / save_name).with_suffix( + ".events.csv" + ) + with open(actual_events_file) as actual: + actual_lines = sorted(actual.readlines()) + with open(expected_events_file) as expected: + expected_lines = sorted(expected.readlines()) + assert actual_lines == expected_lines + + actual_counts_file = ( + Path(test_data_tmp_dir / save_name) + .with_suffix(f".counts_{count_interval}min.csv") + .absolute() + ) + expected_counts_file = ( + Path(test_data_dir / save_name) + .with_suffix(f".counts_{count_interval}min.csv") + .absolute() + ) + with open(actual_counts_file, mode="r") as actual: + actual_lines = sorted(actual.readlines()) + with open(expected_counts_file, mode="r") as expected: + expected_lines = sorted(expected.readlines()) + assert actual_lines == expected_lines From bd7a121ca64a4a7dd45b78cdd2ee3632fb7e404f Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Fri, 15 Mar 2024 15:05:43 +0100 Subject: [PATCH 04/11] Add github workflow to run regression test --- .github/workflows/regression-test.yml | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/regression-test.yml diff --git a/.github/workflows/regression-test.yml b/.github/workflows/regression-test.yml new file mode 100644 index 000000000..a35ac6297 --- /dev/null +++ b/.github/workflows/regression-test.yml @@ -0,0 +1,31 @@ +name: Benchmark Test With Pytest +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +jobs: + test: + name: Run pytest regression test + runs-on: [self-hosted] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.11 + - name: Download test data + run: gh release download --pattern '*.zip' -R platomo/OpenTrafficCam-testdata -D tests/data + env: + GH_TOKEN: ${{ secrets.PLATOMO_OTC_TESTDATA_ACCESS }} + - name: Unzip test data + run: | + cd tests/data + unzip \*.zip + rm *.zip + cd .. + - name: Install requirements + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: Run regression tests + run: pytest ./tests/regression_otanalytics.py From c41f9b532d95310c7506a4f7e6dd34a034abc5c4 Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Fri, 15 Mar 2024 15:07:06 +0100 Subject: [PATCH 05/11] Rename workflow --- .github/workflows/regression-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression-test.yml b/.github/workflows/regression-test.yml index a35ac6297..23db0d355 100644 --- a/.github/workflows/regression-test.yml +++ b/.github/workflows/regression-test.yml @@ -1,4 +1,4 @@ -name: Benchmark Test With Pytest +name: Regression Test With Pytest on: schedule: - cron: '0 0 * * *' From aec067b03df4522f0c5a3e5ed71822e72cbd8a5b Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Fri, 15 Mar 2024 15:08:45 +0100 Subject: [PATCH 06/11] Temporarily activate workflow on pull request --- .github/workflows/regression-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/regression-test.yml b/.github/workflows/regression-test.yml index 23db0d355..11a6be826 100644 --- a/.github/workflows/regression-test.yml +++ b/.github/workflows/regression-test.yml @@ -3,6 +3,8 @@ on: schedule: - cron: '0 0 * * *' workflow_dispatch: + pull_request: + workflow_call: jobs: test: From a3c020a9bde49b14ccb65fd8b126db54aff4eed5 Mon Sep 17 00:00:00 2001 From: Randy Seng <19281702+randy-seng@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:05:54 +0100 Subject: [PATCH 07/11] Remove already defined constant --- tests/conftest.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1caa90453..e3f081f66 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -363,6 +363,3 @@ def create_run_config( exclude_classes=exclude_classes, ) return RunConfiguration(flow_parser, cli_args) - - -NUM_PROCESSES = 1 From ee22390c19f11ba4e790d8e8cfd2d4796ed7e18d Mon Sep 17 00:00:00 2001 From: Randy Seng <19281702+randy-seng@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:45:45 +0100 Subject: [PATCH 08/11] Do not run regression test workflow on every pull request --- .github/workflows/regression-test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/regression-test.yml b/.github/workflows/regression-test.yml index 11a6be826..23db0d355 100644 --- a/.github/workflows/regression-test.yml +++ b/.github/workflows/regression-test.yml @@ -3,8 +3,6 @@ on: schedule: - cron: '0 0 * * *' workflow_dispatch: - pull_request: - workflow_call: jobs: test: From 09d032b3baaaee3889ac28115e948da8f72a39f2 Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Thu, 21 Mar 2024 09:14:36 +0100 Subject: [PATCH 09/11] Moved code into separate module --- tests/benchmark_otanalytics.py | 2 +- tests/conftest.py | 46 ----------------------- tests/regression_otanalytics.py | 2 +- tests/utils/builders/run_configuration.py | 45 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 48 deletions(-) create mode 100644 tests/utils/builders/run_configuration.py diff --git a/tests/benchmark_otanalytics.py b/tests/benchmark_otanalytics.py index f28e5f486..24fa8ca0b 100644 --- a/tests/benchmark_otanalytics.py +++ b/tests/benchmark_otanalytics.py @@ -73,7 +73,7 @@ CLASS_SCOOTER, ) from OTAnalytics.plugin_ui.main_application import ApplicationStarter -from tests.conftest import NUM_PROCESSES, create_run_config +from tests.utils.builders.run_configuration import NUM_PROCESSES, create_run_config PYTHON = "PYTHON" PANDAS = "PANDAS" diff --git a/tests/conftest.py b/tests/conftest.py index e3f081f66..a4addc456 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,9 +5,6 @@ import pytest -from OTAnalytics.application.datastore import FlowParser -from OTAnalytics.application.parser.cli_parser import CliArguments -from OTAnalytics.application.run_configuration import RunConfiguration from OTAnalytics.domain.geometry import Coordinate from OTAnalytics.domain.section import LineSection, Section, SectionId from OTAnalytics.domain.track import Track, TrackId @@ -320,46 +317,3 @@ def pandas_track_segment_dataset_builder( track_segment_dataset_builder_provider: TrackSegmentDatasetBuilderProvider, ) -> TrackSegmentDatasetBuilder: return track_segment_dataset_builder_provider.provide(PANDAS) - - -NUM_PROCESSES = 1 - - -def create_run_config( - track_files: list[str], - otflow_file: str, - save_dir: str, - event_formats: list[str], - flow_parser: FlowParser, - start_cli: bool = True, - debug: bool = False, - logfile_overwrite: bool = True, - track_export: bool = False, - num_processes: int = NUM_PROCESSES, - count_intervals: list[int] | None = None, - config_file: str | None = None, - save_name: str | None = None, - save_suffix: str | None = None, - log_file: str | None = None, - include_classes: list[str] | None = None, - exclude_classes: list[str] | None = None, -) -> RunConfiguration: - cli_args = CliArguments( - start_cli=start_cli, - debug=debug, - logfile_overwrite=logfile_overwrite, - track_export=track_export, - track_files=track_files, - otflow_file=otflow_file, - save_dir=save_dir, - save_name=save_name, - count_intervals=count_intervals, - event_formats=event_formats, - num_processes=num_processes, - config_file=config_file, - save_suffix=save_suffix, - log_file=log_file, - include_classes=include_classes, - exclude_classes=exclude_classes, - ) - return RunConfiguration(flow_parser, cli_args) diff --git a/tests/regression_otanalytics.py b/tests/regression_otanalytics.py index 4d6ae7f45..5f39fdd27 100644 --- a/tests/regression_otanalytics.py +++ b/tests/regression_otanalytics.py @@ -5,7 +5,7 @@ from OTAnalytics.application.datastore import FlowParser from OTAnalytics.plugin_parser.otvision_parser import OtFlowParser from OTAnalytics.plugin_ui.main_application import ApplicationStarter -from tests.conftest import create_run_config +from tests.utils.builders.run_configuration import create_run_config def to_cli_path(test_data_dir: Path, input_file: str) -> str: diff --git a/tests/utils/builders/run_configuration.py b/tests/utils/builders/run_configuration.py new file mode 100644 index 000000000..edb8bf28a --- /dev/null +++ b/tests/utils/builders/run_configuration.py @@ -0,0 +1,45 @@ +from OTAnalytics.application.datastore import FlowParser +from OTAnalytics.application.parser.cli_parser import CliArguments +from OTAnalytics.application.run_configuration import RunConfiguration + +NUM_PROCESSES = 1 + + +def create_run_config( + track_files: list[str], + otflow_file: str, + save_dir: str, + event_formats: list[str], + flow_parser: FlowParser, + start_cli: bool = True, + debug: bool = False, + logfile_overwrite: bool = True, + track_export: bool = False, + num_processes: int = NUM_PROCESSES, + count_intervals: list[int] | None = None, + config_file: str | None = None, + save_name: str | None = None, + save_suffix: str | None = None, + log_file: str | None = None, + include_classes: list[str] | None = None, + exclude_classes: list[str] | None = None, +) -> RunConfiguration: + cli_args = CliArguments( + start_cli=start_cli, + debug=debug, + logfile_overwrite=logfile_overwrite, + track_export=track_export, + track_files=track_files, + otflow_file=otflow_file, + save_dir=save_dir, + save_name=save_name, + count_intervals=count_intervals, + event_formats=event_formats, + num_processes=num_processes, + config_file=config_file, + save_suffix=save_suffix, + log_file=log_file, + include_classes=include_classes, + exclude_classes=exclude_classes, + ) + return RunConfiguration(flow_parser, cli_args) From 3a1b4f2003218845b104804e2ceffcc9f066bf50 Mon Sep 17 00:00:00 2001 From: Lars Briem Date: Thu, 21 Mar 2024 09:19:31 +0100 Subject: [PATCH 10/11] Remove duplicated code --- .../plugin_parser/test_otvision_parser.py | 44 +++++++------------ tests/regression_otanalytics.py | 13 ++---- tests/utils/assertions.py | 11 +++++ 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/tests/OTAnalytics/plugin_parser/test_otvision_parser.py b/tests/OTAnalytics/plugin_parser/test_otvision_parser.py index 632cc7352..dfe48bd99 100644 --- a/tests/OTAnalytics/plugin_parser/test_otvision_parser.py +++ b/tests/OTAnalytics/plugin_parser/test_otvision_parser.py @@ -23,7 +23,6 @@ SectionId, ) from OTAnalytics.domain.track import ( - Detection, Track, TrackClassificationCalculator, TrackId, @@ -141,9 +140,9 @@ def test_fix_occurrence( detection, False, False ) expected_detection = serialized_detection.copy() - serialized_detection[ - ottrk_dataformat.OCCURRENCE - ] = detection.occurrence.strftime(ottrk_dataformat.DATE_FORMAT) + serialized_detection[ottrk_dataformat.OCCURRENCE] = ( + detection.occurrence.strftime(ottrk_dataformat.DATE_FORMAT) + ) fixer = Otdet_Version_1_0_To_1_2() @@ -293,9 +292,9 @@ def test_parse_detections_output_has_same_order_as_input( track_builder_setup_with_sample_data: TrackBuilder, parser: PythonDetectionParser, ) -> None: - detections: list[ - dict - ] = track_builder_setup_with_sample_data.build_serialized_detections() + detections: list[dict] = ( + track_builder_setup_with_sample_data.build_serialized_detections() + ) metadata_video = track_builder_setup_with_sample_data.get_metadata()[ ottrk_dataformat.VIDEO ] @@ -326,9 +325,9 @@ def test_parse_tracks( parser: PythonDetectionParser, ) -> None: mocked_classificator.calculate.return_value = "car" - detections: list[ - dict - ] = track_builder_setup_with_sample_data.build_serialized_detections() + detections: list[dict] = ( + track_builder_setup_with_sample_data.build_serialized_detections() + ) metadata_video = track_builder_setup_with_sample_data.get_metadata()[ ottrk_dataformat.VIDEO ] @@ -350,9 +349,9 @@ def test_parse_tracks_merge_with_existing( mocked_classificator: Mock, parser: PythonDetectionParser, ) -> None: - detections: list[ - dict - ] = track_builder_setup_with_sample_data.build_serialized_detections() + detections: list[dict] = ( + track_builder_setup_with_sample_data.build_serialized_detections() + ) deserialized_detections = ( track_builder_setup_with_sample_data.build_detections() ) @@ -399,9 +398,9 @@ def test_parse_tracks_consider_minimum_length( mocked_track_repository, track_length_limit, ) - detections: list[ - dict - ] = track_builder_setup_with_sample_data.build_serialized_detections() + detections: list[dict] = ( + track_builder_setup_with_sample_data.build_serialized_detections() + ) metadata_video = track_builder_setup_with_sample_data.get_metadata()[ ottrk_dataformat.VIDEO @@ -410,19 +409,6 @@ def test_parse_tracks_consider_minimum_length( assert len(result_sorted_input) == 0 - def assert_detection_equal(self, d1: Detection, d2: Detection) -> None: - assert d1.classification == d2.classification - assert d1.confidence == d2.confidence - assert d1.x == d2.x - assert d1.y == d2.y - assert d1.w == d2.w - assert d1.h == d2.h - assert d1.frame == d2.frame - assert d1.occurrence == d2.occurrence - assert d1.video_name == d2.video_name - assert d1.interpolated_detection == d2.interpolated_detection - assert d1.track_id == d2.track_id - class TestOtFlowParser: def test_parse_sections_and_flows(self, test_data_tmp_dir: Path) -> None: diff --git a/tests/regression_otanalytics.py b/tests/regression_otanalytics.py index 5f39fdd27..9edee46d8 100644 --- a/tests/regression_otanalytics.py +++ b/tests/regression_otanalytics.py @@ -5,6 +5,7 @@ from OTAnalytics.application.datastore import FlowParser from OTAnalytics.plugin_parser.otvision_parser import OtFlowParser from OTAnalytics.plugin_ui.main_application import ApplicationStarter +from tests.utils.assertions import assert_two_files_equal_sorted from tests.utils.builders.run_configuration import create_run_config @@ -132,11 +133,7 @@ def _execute_test( expected_events_file = Path(test_data_dir / save_name).with_suffix( ".events.csv" ) - with open(actual_events_file) as actual: - actual_lines = sorted(actual.readlines()) - with open(expected_events_file) as expected: - expected_lines = sorted(expected.readlines()) - assert actual_lines == expected_lines + assert_two_files_equal_sorted(actual_events_file, expected_events_file) actual_counts_file = ( Path(test_data_tmp_dir / save_name) @@ -148,8 +145,4 @@ def _execute_test( .with_suffix(f".counts_{count_interval}min.csv") .absolute() ) - with open(actual_counts_file, mode="r") as actual: - actual_lines = sorted(actual.readlines()) - with open(expected_counts_file, mode="r") as expected: - expected_lines = sorted(expected.readlines()) - assert actual_lines == expected_lines + assert_two_files_equal_sorted(actual_counts_file, expected_counts_file) diff --git a/tests/utils/assertions.py b/tests/utils/assertions.py index 0d999521b..1da8d0889 100644 --- a/tests/utils/assertions.py +++ b/tests/utils/assertions.py @@ -1,3 +1,4 @@ +from pathlib import Path from typing import Iterable from unittest.mock import Mock @@ -56,3 +57,13 @@ def assert_track_dataset_has_tracks(dataset: TrackDataset, tracks: list[Track]) actual = dataset.get_for(expected.id) assert actual assert_equal_track_properties(actual, expected) + + +def assert_two_files_equal_sorted( + actual_counts_file: Path, expected_counts_file: Path +) -> None: + with open(actual_counts_file, mode="r") as actual: + actual_lines = sorted(actual.readlines()) + with open(expected_counts_file, mode="r") as expected: + expected_lines = sorted(expected.readlines()) + assert actual_lines == expected_lines From 67838dc7d5687baf69ceeb820595a9e9401853a7 Mon Sep 17 00:00:00 2001 From: Randy Seng <19281702+randy-seng@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:58:37 +0100 Subject: [PATCH 11/11] Fix import due to FlowParser having been moved to different location --- tests/regression_otanalytics.py | 2 +- tests/utils/builders/run_configuration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/regression_otanalytics.py b/tests/regression_otanalytics.py index 9edee46d8..f84df584b 100644 --- a/tests/regression_otanalytics.py +++ b/tests/regression_otanalytics.py @@ -2,7 +2,7 @@ import pytest -from OTAnalytics.application.datastore import FlowParser +from OTAnalytics.application.parser.flow_parser import FlowParser from OTAnalytics.plugin_parser.otvision_parser import OtFlowParser from OTAnalytics.plugin_ui.main_application import ApplicationStarter from tests.utils.assertions import assert_two_files_equal_sorted diff --git a/tests/utils/builders/run_configuration.py b/tests/utils/builders/run_configuration.py index edb8bf28a..138772deb 100644 --- a/tests/utils/builders/run_configuration.py +++ b/tests/utils/builders/run_configuration.py @@ -1,5 +1,5 @@ -from OTAnalytics.application.datastore import FlowParser from OTAnalytics.application.parser.cli_parser import CliArguments +from OTAnalytics.application.parser.flow_parser import FlowParser from OTAnalytics.application.run_configuration import RunConfiguration NUM_PROCESSES = 1