Skip to content

Commit a0de251

Browse files
committed
Add primitive topic handling for mcap files
Signed-off-by: Pierre R. Mai <pmai@pmsf.de>
1 parent b48bbdd commit a0de251

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

qc_ositrace/checks/deserialization/deserialization_checker.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def run_checks(config: Configuration, result: Result) -> None:
2323
expected_type = OSITrace.map_message_type(expected_type_name)
2424

2525
trace = OSITrace(
26-
config.get_config_param("InputFile"), config.get_config_param("osiType")
26+
config.get_config_param("InputFile"),
27+
config.get_config_param("osiType"),
28+
False,
29+
config.get_config_param("osiTopic"),
2730
)
2831

2932
result.register_checker(

qc_ositrace/checks/osirules/osirules_checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,12 @@ def run_checks(config: Configuration, result: Result) -> None:
445445
)
446446
expected_type_name = config.get_config_param("osiType")
447447

448-
trace = OSITrace(config.get_config_param("InputFile"), expected_type_name)
448+
trace = OSITrace(
449+
config.get_config_param("InputFile"),
450+
expected_type_name,
451+
False,
452+
config.get_config_param("osiTopic"),
453+
)
449454

450455
result.register_checker(
451456
checker_bundle_name=constants.BUNDLE_NAME,

qc_ositrace/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def args_entrypoint() -> argparse.Namespace:
2828
type=pathlib.Path,
2929
help="Path to the input OSI Trace file.",
3030
)
31+
parser.add_argument(
32+
"--osiTopic",
33+
type=str,
34+
help="Channel topic of a multi-trace OSI Trace file to select.",
35+
)
3136
parser.add_argument(
3237
"--osiType",
3338
type=str,
@@ -101,6 +106,9 @@ def main():
101106
logging.info("Setting input file: %s", args.input_file)
102107
config.set_config_param("InputFile", str(args.input_file))
103108

109+
if args.osiTopic:
110+
logging.info("Setting OSI Topic: %s", args.osiTopic)
111+
config.set_config_param("osiTopic", args.osiTopic)
104112
if args.osiType:
105113
logging.info("Setting OSI Type: %s", args.osiType)
106114
config.set_config_param("osiType", args.osiType)

tests/test_deserialization_checks.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,37 @@ def test_deserialization_expected_version(
5858
launch_main(monkeypatch)
5959
check_issues(rule_uid, issue_count, issue_severity)
6060
cleanup_files()
61+
62+
63+
@pytest.mark.parametrize(
64+
"target_file,target_topic,target_type,target_version,issue_count",
65+
[
66+
("360", "MySensorView", "SensorView", "3.5.0", 547),
67+
("360", "MySensorView", "SensorView", "3.6.0", 0),
68+
("360", "Foo", "SensorView", "3.6.0", -1),
69+
],
70+
)
71+
def test_deserialization_mcap_topic(
72+
target_file: str,
73+
target_topic: str,
74+
target_type: str,
75+
target_version: str,
76+
issue_count: int,
77+
monkeypatch,
78+
) -> None:
79+
base_path = "tests/data/deserialization_expected_version/"
80+
target_file_name = f"deserialization_expected_version_{target_file}.mcap"
81+
rule_uid = "asam.net:osi:3.0.0:deserialization.expected_version"
82+
issue_severity = IssueSeverity.ERROR
83+
84+
target_file_path = os.path.join(base_path, target_file_name)
85+
create_test_config(
86+
target_file_path, target_type, target_version, None, target_topic
87+
)
88+
if issue_count < 0:
89+
with pytest.raises(ValueError):
90+
launch_main(monkeypatch)
91+
else:
92+
launch_main(monkeypatch)
93+
check_issues(rule_uid, issue_count, issue_severity)
94+
cleanup_files()

tests/test_setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from typing import Optional
55

6+
from contextlib import suppress
7+
68
import qc_ositrace.main as main
79

810
from qc_ositrace import constants
@@ -17,6 +19,7 @@ def create_test_config(
1719
target_file_type: str,
1820
target_file_version: Optional[str] = None,
1921
target_file_rules: Optional[str] = None,
22+
target_file_topic: Optional[str] = None,
2023
):
2124
test_config = Configuration()
2225
test_config.set_config_param(name="InputFile", value=target_file_path)
@@ -25,6 +28,8 @@ def create_test_config(
2528
test_config.set_config_param(name="osiVersion", value=target_file_version)
2629
if target_file_rules is not None:
2730
test_config.set_config_param(name="osiRulesFile", value=target_file_rules)
31+
if target_file_topic is not None:
32+
test_config.set_config_param(name="osiTopic", value=target_file_topic)
2833
test_config.register_checker_bundle(checker_bundle_name=constants.BUNDLE_NAME)
2934
test_config.set_checker_bundle_param(
3035
checker_bundle_name=constants.BUNDLE_NAME,
@@ -61,5 +66,6 @@ def launch_main(monkeypatch):
6166

6267

6368
def cleanup_files():
64-
os.remove(REPORT_FILE_PATH)
65-
os.remove(CONFIG_FILE_PATH)
69+
with suppress(Exception):
70+
os.remove(REPORT_FILE_PATH)
71+
os.remove(CONFIG_FILE_PATH)

0 commit comments

Comments
 (0)