Skip to content

Commit

Permalink
Added multiple negative case
Browse files Browse the repository at this point in the history
Signed-off-by: romanodanilo <[email protected]>
  • Loading branch information
romanodanilo committed Jul 10, 2024
1 parent 63790e5 commit ff0c9b8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ def check_rule(checker_data: models.CheckerData) -> None:
logging.error("Cannot find Catalog nodes in provided XOSC file. Skipping check")
return

print("catalogs_node : ", catalogs_node)
logging.debug(f"catalogs_node : {catalogs_node}")

for catalog_node in catalogs_node:

parameter_declaration_nodes = catalog_node.find(".//ParameterDeclarations")
print("parameter_declaration_nodes : ", parameter_declaration_nodes)
logging.debug(f"parameter_declaration_nodes : {parameter_declaration_nodes}")
# Get parameters declarations and check if they have default value
defined_parameters_with_default = set()
if parameter_declaration_nodes is not None:
for declaration_node in list(parameter_declaration_nodes):
current_name = declaration_node.get("name")
current_default_value = declaration_node.get("value")
print("current_default_value : ", current_default_value)

if (
current_name is not None
Expand All @@ -83,11 +82,16 @@ def check_rule(checker_data: models.CheckerData) -> None:
):
defined_parameters_with_default.add(current_name)

xpath_expr = './/*[starts-with(@*, "$")]'
# Expression selecting when a node attribute value starts with $, indicating a parameter usage
xpath_expr = './/*[@*[starts-with(., "$")]]'

print("defined_parameters_with_default: ", defined_parameters_with_default)
logging.debug(
f"defined_parameters_with_default: {defined_parameters_with_default}"
)
nodes_with_parameters_attributes = catalog_node.xpath(xpath_expr)
print("nodes_with_parameters_attributes: ", nodes_with_parameters_attributes)
logging.debug(
f"nodes_with_parameters_attributes: {nodes_with_parameters_attributes}"
)

for node_with_parameter_attribute in nodes_with_parameters_attributes:
xpath = root.getpath(node_with_parameter_attribute)
Expand All @@ -110,5 +114,5 @@ def check_rule(checker_data: models.CheckerData) -> None:
checker_id=parameters_constants.CHECKER_ID,
issue_id=issue_id,
xpath=xpath,
description=f"Parameter {attr_value[1:]} for attribute {attr_name} not defined in Catalog or with no default value",
description=f"Parameter value {attr_value[1:]} for attribute {attr_name} not defined in Catalog or with no default value",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='UTF-8'?>
<OpenSCENARIO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../qc_openscenario/schema/1.3.0/OpenSCENARIO.xsd">
<FileHeader author="ASAM e.V." date="2021-02-05T18:50:17" description="Simple Overtaker example"
revMajor="1" revMinor="3" />
<Catalog name="PositiveCatalog">
<Vehicle name="Vehicle 1" vehicleCategory="car">
<ParameterDeclarations>
<ParameterDeclaration name="centerBoundingBoxX" parameterType="double" value="1.3" />
<ParameterDeclaration name="centerBoundingBoxY" parameterType="double" value="1.3" />
<ParameterDeclaration name="centerBoundingBoxZ" parameterType="double" value="1.3" />
</ParameterDeclarations>
<BoundingBox>
<!-- Inserted rule violation since the parameter "centerBoundingBoxZ" was not
declared. -->
<Center x="$centerBoundingBoxZ" y="0.0" z="0.75" />
<Dimensions width="1.8" length="4.5" height="1.5" />
</BoundingBox>
<Performance maxSpeed="200.0" maxDeceleration="30.0" maxAcceleration="200.0" />
<Axles>
<FrontAxle positionZ="$centerBoundingBoxZ" trackWidth="1.68" positionX="2.98"
maxSteering="$maxVehicleSteeringParam" wheelDiameter="0.8" />
<RearAxle positionZ="0.4" trackWidth="$trackWidthParam" positionX="0.0"
maxSteering="0.5235987756" wheelDiameter="0.8" />
</Axles>
</Vehicle>
</Catalog>
</OpenSCENARIO>
44 changes: 38 additions & 6 deletions tests/test_parameters_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def test_valid_parameter_declaration_in_catalogs_negative(
checker_id=parameters_constants.CHECKER_ID,
)

reference_issues = result.get_issues_by_rule_uid(
parameters_issues = result.get_issues_by_rule_uid(
"asam.net:xosc:1.2.0:parameters.valid_parameter_declaration_in_catalogs"
)
assert len(reference_issues) == 1
assert reference_issues[0].level == IssueSeverity.ERROR
assert len(parameters_issues) == 1
assert parameters_issues[0].level == IssueSeverity.ERROR
test_utils.cleanup_files()


Expand All @@ -84,9 +84,41 @@ def test_valid_parameter_declaration_in_catalogs_negative_no_default(
checker_id=parameters_constants.CHECKER_ID,
)

reference_issues = result.get_issues_by_rule_uid(
parameters_issues = result.get_issues_by_rule_uid(
"asam.net:xosc:1.2.0:parameters.valid_parameter_declaration_in_catalogs"
)
assert len(reference_issues) == 1
assert reference_issues[0].level == IssueSeverity.ERROR
assert len(parameters_issues) == 1
assert parameters_issues[0].level == IssueSeverity.ERROR
test_utils.cleanup_files()


def test_valid_parameter_declaration_in_catalogs_negative_multiple(
monkeypatch,
) -> None:
base_path = "tests/data/valid_parameter_declaration_in_catalogs/"
target_file_name = (
f"parameters.valid_parameter_declaration_in_catalogs.negative.multiple.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=parameters_constants.CHECKER_ID,
)

parameters_issues = result.get_issues_by_rule_uid(
"asam.net:xosc:1.2.0:parameters.valid_parameter_declaration_in_catalogs"
)
assert len(parameters_issues) == 2
assert parameters_issues[0].level == IssueSeverity.ERROR
assert parameters_issues[1].level == IssueSeverity.ERROR
assert "maxSteering" in parameters_issues[0].locations[0].description
assert "trackWidth" in parameters_issues[1].locations[0].description
test_utils.cleanup_files()

0 comments on commit ff0c9b8

Please sign in to comment.