-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from OpenTrafficCam/task/4190-implement-regre…
…ssion-test-for-otanalytics-cli-using-test-data task/4190-implement-regression-test-for-otanalytics-cli-using-test-data
- Loading branch information
Showing
7 changed files
with
257 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Regression 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
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 | ||
from tests.utils.builders.run_configuration 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" | ||
) | ||
assert_two_files_equal_sorted(actual_events_file, expected_events_file) | ||
|
||
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() | ||
) | ||
assert_two_files_equal_sorted(actual_counts_file, expected_counts_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 | ||
|
||
|
||
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) |