Skip to content

Commit

Permalink
Extend check to all catalog children
Browse files Browse the repository at this point in the history
Signed-off-by: romanodanilo <[email protected]>
  • Loading branch information
romanodanilo committed Jun 19, 2024
1 parent 776fa20 commit 30b0e23
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,29 @@ def check_rule(checker_data: models.CheckerData) -> None:

root = checker_data.input_file_xml_root

# List to store problematic vehicle nodes
# List to store problematic nodes
errors = []

# Iterate over each 'Catalog' node
for catalog_node in root.findall(".//Catalog"):
# Dictionary to track 'vehicle' nodes by 'name' attribute
vehicle_names = {}
# Dictionary to track child nodes by 'name' attribute
child_names = {}

# Iterate over 'Vehicle' nodes within current 'Catalog' node
for vehicle_node in catalog_node.findall(".//Vehicle"):
name_attr = vehicle_node.attrib.get("name")
# Iterate catalog children within current 'Catalog' node
for child_node in catalog_node.iterchildren():
name_attr = child_node.attrib.get("name")
if name_attr:
if name_attr in vehicle_names:
if name_attr in child_names:
errors.append(
{
"name": name_attr,
"tag": vehicle_node.tag,
"first_xpath": get_xpath(root, vehicle_names[name_attr]),
"duplicate_xpath": get_xpath(root, vehicle_node),
"tag": child_node.tag,
"first_xpath": get_xpath(root, child_names[name_attr]),
"duplicate_xpath": get_xpath(root, child_node),
}
)
else:
vehicle_names[name_attr] = vehicle_node
child_names[name_attr] = child_node

if len(errors) > 0:
issue_id = checker_data.result.register_issue(
Expand All @@ -98,7 +98,9 @@ def check_rule(checker_data: models.CheckerData) -> None:
error_name = error["name"]
error_first_xpath = error["first_xpath"]
error_duplicate_xpath = error["duplicate_xpath"]
error_msg = f"Duplicate vehicle name {error_name}. First occurrence at {error_first_xpath} duplicate at {error_duplicate_xpath}"
error_msg = f"Duplicate name {error_name}. First occurrence at {error_first_xpath} duplicate at {error_duplicate_xpath}"
logging.error(f"- Error: {error_msg}")
logging.error(f"- Duplicate xpath: {error_duplicate_xpath}")
checker_data.result.add_xml_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=reference_constants.CHECKER_ID,
Expand Down
14 changes: 7 additions & 7 deletions qc_openscenario/checks/schema_checker/schema_is_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ def check_rule(checker_data: models.CheckerData) -> None:
)

if not schema_compliant:
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=schema_constants.CHECKER_ID,
description="Issue flagging when input file does not follow its version schema",
level=IssueSeverity.ERROR,
rule_uid=rule_uid,
)

for error in errors:
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=schema_constants.CHECKER_ID,
description="Issue flagging when input file does not follow its version schema",
level=IssueSeverity.ERROR,
rule_uid=rule_uid,
)
checker_data.result.add_file_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=schema_constants.CHECKER_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<OpenSCENARIO>
<FileHeader description="Vehicle Catalog" author="ASAM" revMajor="1" revMinor="2"
date="2023-11-15T11:00:00.000000" />
<Catalog name="VehicleCatalog_1">
<Vehicle name="car_white" vehicleCategory="car">
<BoundingBox>
<Center x="1.4" y="0.0" z="0.9" />
<Dimensions width="2.0" length="5.0" height="1.8" />
</BoundingBox>
<Performance maxSpeed="69" maxDeceleration="30" maxAcceleration="5" />
<Axles>
<FrontAxle maxSteering="30" wheelDiameter="0.8" trackWidth="1.68" positionX="2.98"
positionZ="0.4" />
<RearAxle maxSteering="30" wheelDiameter="0.8" trackWidth="1.68" positionX="0"
positionZ="0.4" />
</Axles>
<Properties>
<Property name="control" value="internal" />
<Property name="model_id" value="0" />
<File
filepath="../../../external/delivery/esmini-noosg/resources/osgb/car_white.osgb" />
</Properties>
</Vehicle>
<Vehicle name="car_red" />
<Controller name="abc" />
<Controller name="controller2" />
<Maneuver name="abc" />
<Maneuver name="maneuver2" />
<Route name="route1" />
<Route name="route2" />

</Catalog>
</OpenSCENARIO>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<OpenSCENARIO>
<FileHeader description="Vehicle Catalog" author="ASAM" revMajor="1" revMinor="2"
date="2023-11-15T11:00:00.000000" />
<Catalog name="VehicleCatalog_1">
<Vehicle name="car_white" vehicleCategory="car">
<BoundingBox>
<Center x="1.4" y="0.0" z="0.9" />
<Dimensions width="2.0" length="5.0" height="1.8" />
</BoundingBox>
<Performance maxSpeed="69" maxDeceleration="30" maxAcceleration="5" />
<Axles>
<FrontAxle maxSteering="30" wheelDiameter="0.8" trackWidth="1.68" positionX="2.98"
positionZ="0.4" />
<RearAxle maxSteering="30" wheelDiameter="0.8" trackWidth="1.68" positionX="0"
positionZ="0.4" />
</Axles>
<Properties>
<Property name="control" value="internal" />
<Property name="model_id" value="0" />
<File
filepath="../../../external/delivery/esmini-noosg/resources/osgb/car_white.osgb" />
</Properties>
</Vehicle>
<Vehicle name="car_red" />
<Controller name="controller1" />
<Controller name="controller2" />
<Maneuver name="maneuver1" />
<Maneuver name="maneuver2" />
<Route name="route1" />
<Route name="route2" />

</Catalog>
</OpenSCENARIO>
54 changes: 54 additions & 0 deletions tests/test_reference_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,57 @@ def test_uniquely_resolvable_negative(
assert len(reference_issues) == 1
assert reference_issues[0].level == IssueSeverity.WARNING
test_utils.cleanup_files()


def test_long_catalog_negative(
monkeypatch,
) -> None:
base_path = "tests/data/uniquely_resolvable_entity_references/"
target_file_name = f"long_catalog_negative.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)

result = Result()
result.load_from_file(test_utils.REPORT_FILE_PATH)

_ = result.get_checker_result(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=reference_constants.CHECKER_ID,
)
reference_issues = result.get_issues_by_rule_uid(
"asam.net:xosc:1.2.0:reference_control.uniquely_resolvable_entity_references"
)
assert len(reference_issues) == 1
assert reference_issues[0].level == IssueSeverity.WARNING
test_utils.cleanup_files()


def test_long_catalog_positive(
monkeypatch,
) -> None:
base_path = "tests/data/uniquely_resolvable_entity_references/"
target_file_name = f"long_catalog_positive.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)

result = Result()
result.load_from_file(test_utils.REPORT_FILE_PATH)

_ = result.get_checker_result(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=reference_constants.CHECKER_ID,
)
assert (
len(
result.get_issues_by_rule_uid(
"asam.net:xosc:1.2.0:reference_control.uniquely_resolvable_entity_references"
)
)
== 0
)

0 comments on commit 30b0e23

Please sign in to comment.