diff --git a/qc_openscenario/checks/utils.py b/qc_openscenario/checks/utils.py index 1bdb6e1..a615c24 100644 --- a/qc_openscenario/checks/utils.py +++ b/qc_openscenario/checks/utils.py @@ -17,7 +17,10 @@ def to_float(s): return None -def get_root_without_default_namespace(path: str) -> etree._ElementTree: +def get_root_without_default_namespace(path: str) -> Union[None, etree._ElementTree]: + if not os.path.exists(path): + return None + with open(path, "rb") as raw_file: xml_string = raw_file.read().decode() diff --git a/tests/data/non_existing_road_network_file/non_existing_road_network_file.xosc b/tests/data/non_existing_road_network_file/non_existing_road_network_file.xosc new file mode 100644 index 0000000..c2b4318 --- /dev/null +++ b/tests/data/non_existing_road_network_file/non_existing_road_network_file.xosc @@ -0,0 +1,46 @@ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_main_executor.py b/tests/test_main_executor.py new file mode 100644 index 0000000..260a48e --- /dev/null +++ b/tests/test_main_executor.py @@ -0,0 +1,21 @@ +import os +import pytest +import test_utils +from qc_baselib import Result, IssueSeverity, StatusType +from qc_openscenario.checks import basic_checker + + +def test_non_existing_road_network_file( + monkeypatch, +) -> None: + base_path = "tests/data/non_existing_road_network_file/" + target_file_name = f"non_existing_road_network_file.xosc" + target_file_path = os.path.join(base_path, target_file_name) + + test_utils.create_test_config(target_file_path) + + test_utils.launch_main(monkeypatch) + + # Should have no exception + assert True + test_utils.cleanup_files()