Skip to content

Commit 8da7dfb

Browse files
committed
Switch to keyword arguments on OSITrace, add tests
Add tests to ensure topic is correctly ignored for single trace files, also fix formatting error in related_to code. Signed-off-by: Pierre R. Mai <pmai@pmsf.de>
1 parent 9a30ae0 commit 8da7dfb

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

qc_ositrace/checks/deserialization/deserialization_checker.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ def run_checks(config: Configuration, result: Result) -> None:
6868
try:
6969
try:
7070
trace = OSITrace(
71-
config.get_config_param("InputFile"),
72-
config.get_config_param("osiType"),
73-
False,
74-
config.get_config_param("osiTopic"),
71+
path=config.get_config_param("InputFile"),
72+
type_name=config.get_config_param("osiType"),
73+
topic=config.get_config_param("osiTopic"),
7574
)
7675
except Exception as e:
7776
logging.error(f"Error reading input file: {e}")

qc_ositrace/checks/osirules/osirules_checker.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ def check_message_against_rules(
406406
)
407407
else:
408408
# Check if referred message matches one of the expected types
409-
expected_types = ["osi3." + t for t in rule['refers_to']] if isinstance(rule['refers_to'], list) else ["osi3." + rule['refers_to']]
409+
expected_types = (
410+
["osi3." + t for t in rule["refers_to"]]
411+
if isinstance(rule["refers_to"], list)
412+
else ["osi3." + rule["refers_to"]]
413+
)
410414
if referred_message.DESCRIPTOR.full_name not in expected_types:
411415
register_issue(
412416
result,
@@ -470,10 +474,9 @@ def run_checks(config: Configuration, result: Result) -> None:
470474
try:
471475
try:
472476
trace = OSITrace(
473-
config.get_config_param("InputFile"),
474-
expected_type_name,
475-
False,
476-
config.get_config_param("osiTopic"),
477+
path=config.get_config_param("InputFile"),
478+
type_name=expected_type_name,
479+
topic=config.get_config_param("osiTopic"),
477480
)
478481
except Exception as e:
479482
logging.error(f"Error reading input file: {e}")

tests/test_deserialization_checks.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,37 @@ def test_deserialization_mcap_topic(
9494
else:
9595
check_issues(rule_uid, issue_count, issue_severity)
9696
cleanup_files()
97+
98+
99+
@pytest.mark.parametrize(
100+
"target_file,target_topic,target_type,target_version,issue_count",
101+
[
102+
("360", "MySensorView", "SensorView", "3.5.0", 547),
103+
("360", "MySensorView", "SensorView", "3.6.0", 0),
104+
("360", "Foo", "SensorView", "3.5.0", 547),
105+
("360", "Foo", "SensorView", "3.6.0", 0),
106+
],
107+
)
108+
def test_deserialization_single_topic(
109+
target_file: str,
110+
target_topic: str,
111+
target_type: str,
112+
target_version: str,
113+
issue_count: int,
114+
monkeypatch,
115+
) -> None:
116+
base_path = "tests/data/deserialization_expected_version/"
117+
target_file_name = f"deserialization_expected_version_{target_file}.osi"
118+
rule_uid = "asam.net:osi:3.0.0:deserialization.expected_version"
119+
issue_severity = IssueSeverity.ERROR
120+
121+
target_file_path = os.path.join(base_path, target_file_name)
122+
create_test_config(
123+
target_file_path, target_type, target_version, None, target_topic
124+
)
125+
launch_main(monkeypatch)
126+
if issue_count < 0:
127+
check_failure(deserialization_checker_id)
128+
else:
129+
check_issues(rule_uid, issue_count, issue_severity)
130+
cleanup_files()

0 commit comments

Comments
 (0)