Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maintenance work #64

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# asam-qc-openscenarioxml

This project implements the [ASAM OpenScenario XML Checker](checker_bundle_doc.md).
This project implements the [ASAM OpenScenario XML Checker Bundle](checker_bundle_doc.md).

- [asam-qc-openscenarioxml](#asam-qc-openscenarioxml)
- [Installation and usage](#installation-and-usage)
Expand All @@ -27,8 +27,11 @@ asam-qc-openscenarioxml can be installed using pip.
pip install asam-qc-openscenarioxml@git+https://github.com/asam-ev/qc-openscenarioxml@main
```

**Note**: To install from different sources, you can replace `@main` with
your desired target. For example, `develop` branch as `@develop`.
**Note:** The above command will install `asam-qc-openscenarioxml` from the `main` branch. If you want to install `asam-qc-openscenarioxml` from another branch or tag, replace `@main` with the desired branch or tag. It is also possible to install from a local directory.

```bash
pip install /home/user/qc-openscenarioxml
```

To run the application:

Expand Down
3 changes: 2 additions & 1 deletion checker_bundle_doc.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Checker bundle: xoscBundle

* Build version: 0.1.0
Expand Down Expand Up @@ -41,7 +42,7 @@

### check_asam_xosc_reference_control_uniquely_resolvable_entity_references

* Description: Input xml file must be valid according to the schema.
* Description: Reference names must be unique
* Addressed rules:
* asam.net:xosc:1.2.0:reference_control.uniquely_resolvable_entity_references

Expand Down
196 changes: 98 additions & 98 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions qc_openscenario/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import constants as constants
from . import checks as checks
from . import basic_preconditions as basic_preconditions
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from qc_openscenario.checks.schema_checker import valid_schema

PRECONDITIONS = {
CHECKER_PRECONDITIONS = {
valid_xml_document.CHECKER_ID,
root_tag_is_openscenario.CHECKER_ID,
fileheader_is_present.CHECKER_ID,
Expand Down
1 change: 0 additions & 1 deletion qc_openscenario/checks/basic_checker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import basic_checker as basic_checker
from . import valid_xml_document as valid_xml_document
from . import root_tag_is_openscenario as root_tag_is_openscenario
from . import fileheader_is_present as fileheader_is_present
Expand Down
63 changes: 0 additions & 63 deletions qc_openscenario/checks/basic_checker/basic_checker.py

This file was deleted.

55 changes: 15 additions & 40 deletions qc_openscenario/checks/basic_checker/fileheader_is_present.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import logging
from lxml import etree
from qc_baselib import IssueSeverity, Result, StatusType
from qc_baselib import IssueSeverity

from qc_openscenario import constants
from qc_openscenario.checks import models

from qc_openscenario.checks.basic_checker import (
valid_xml_document,
root_tag_is_openscenario,
)

CHECKER_ID = "check_asam_xosc_xml_fileheader_is_present"
PRECONDITIONS = {valid_xml_document.CHECKER_ID, root_tag_is_openscenario.CHECKER_ID}
CHECKER_DESCRIPTION = "Below the root element a tag with FileHeader must be defined."
CHECKER_PRECONDITIONS = {
valid_xml_document.CHECKER_ID,
root_tag_is_openscenario.CHECKER_ID,
}
RULE_UID = "asam.net:xosc:1.0.0:xml.fileheader_is_present"


def check_rule(tree: etree._ElementTree, result: Result) -> None:
def check_rule(checker_data: models.CheckerData) -> None:
"""
Below the root element a tag with FileHeader must be defined.

Expand All @@ -22,31 +27,7 @@ def check_rule(tree: etree._ElementTree, result: Result) -> None:
"""
logging.info("Executing fileheader_is_present check")

result.register_checker(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
description="Below the root element a tag with FileHeader must be defined.",
)

rule_uid = result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
emanating_entity="asam.net",
standard="xosc",
definition_setting="1.0.0",
rule_full_name="xml.fileheader_is_present",
)

if not result.all_checkers_completed_without_issue(PRECONDITIONS):
result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.SKIPPED,
)

return

root = tree.getroot()
root = checker_data.input_file_xml_root.getroot()

is_valid = False
# Check if root contains a tag 'FileHeader'
Expand All @@ -60,24 +41,18 @@ def check_rule(tree: etree._ElementTree, result: Result) -> None:

if not is_valid:

issue_id = result.register_issue(
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
description="Issue flagging when no FileHeader is found under root element",
description="No FileHeader found under root element",
level=IssueSeverity.ERROR,
rule_uid=rule_uid,
rule_uid=RULE_UID,
)

result.add_xml_location(
checker_data.result.add_xml_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
issue_id=issue_id,
xpath=tree.getpath(root),
xpath=checker_data.input_file_xml_root.getpath(root),
description=f'No child element "FileHeader"',
)

result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.COMPLETED,
)
52 changes: 12 additions & 40 deletions qc_openscenario/checks/basic_checker/root_tag_is_openscenario.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import logging
from lxml import etree
from qc_baselib import IssueSeverity, Result, StatusType
from qc_baselib import IssueSeverity

from qc_openscenario import constants
from qc_openscenario.checks import models

from qc_openscenario.checks.basic_checker import valid_xml_document

CHECKER_ID = "check_asam_xosc_xml_root_tag_is_openscenario"
PRECONDITIONS = {valid_xml_document.CHECKER_ID}
CHECKER_DESCRIPTION = "The root element of a valid XML document must be OpenSCENARIO."
CHECKER_PRECONDITIONS = {valid_xml_document.CHECKER_ID}
RULE_UID = "asam.net:xosc:1.0.0:xml.root_tag_is_openscenario"


def check_rule(tree: etree._ElementTree, result: Result) -> None:
def check_rule(checker_data: models.CheckerData) -> None:
"""
The root element of a valid XML document must be OpenSCENARIO

Expand All @@ -19,31 +21,7 @@ def check_rule(tree: etree._ElementTree, result: Result) -> None:
"""
logging.info("Executing root_tag_is_openscenario check")

result.register_checker(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
description="The root element of a valid XML document must be OpenSCENARIO.",
)

rule_uid = result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
emanating_entity="asam.net",
standard="xosc",
definition_setting="1.0.0",
rule_full_name="xml.root_tag_is_openscenario",
)

if not result.all_checkers_completed_without_issue(PRECONDITIONS):
result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.SKIPPED,
)

return

root = tree.getroot()
root = checker_data.input_file_xml_root.getroot()

is_valid = False
if root.tag == "OpenSCENARIO":
Expand All @@ -55,24 +33,18 @@ def check_rule(tree: etree._ElementTree, result: Result) -> None:

if not is_valid:

issue_id = result.register_issue(
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
description="Issue flagging when root tag is not OpenSCENARIO",
description="Root tag is not OpenSCENARIO",
level=IssueSeverity.ERROR,
rule_uid=rule_uid,
rule_uid=RULE_UID,
)

result.add_xml_location(
checker_data.result.add_xml_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
issue_id=issue_id,
xpath=tree.getpath(root),
xpath=checker_data.input_file_xml_root.getpath(root),
description=f"Root is not OpenSCENARIO",
)

result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.COMPLETED,
)
37 changes: 10 additions & 27 deletions qc_openscenario/checks/basic_checker/valid_xml_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

from lxml import etree

from qc_baselib import Result, IssueSeverity, StatusType
from qc_baselib import IssueSeverity
from qc_openscenario import constants
from qc_openscenario.checks import models

CHECKER_ID = "check_asam_xosc_xml_valid_xml_document"
CHECKER_DESCRIPTION = "The given file to check must be a valid XML document."
CHECKER_PRECONDITIONS = set()
RULE_UID = "asam.net:xosc:1.0.0:xml.valid_xml_document"


def _is_xml_doc(file_path: str) -> tuple[bool, tuple[int, int]]:
Expand All @@ -21,7 +25,7 @@ def _is_xml_doc(file_path: str) -> tuple[bool, tuple[int, int]]:
return False, (e.lineno, e.offset)


def check_rule(input_xml_file_path: str, result: Result) -> None:
def check_rule(checker_data: models.CheckerData) -> None:
"""
Implements a rule to check if input file is a valid xml document

Expand All @@ -30,44 +34,23 @@ def check_rule(input_xml_file_path: str, result: Result) -> None:
"""
logging.info("Executing valid_xml_document check")

result.register_checker(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
description="The given file to check must be a valid XML document.",
)

rule_uid = result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
emanating_entity="asam.net",
standard="xosc",
definition_setting="1.0.0",
rule_full_name="xml.valid_xml_document",
)

is_valid, error_location = _is_xml_doc(input_xml_file_path)
is_valid, error_location = _is_xml_doc(checker_data.xml_file_path)

if not is_valid:

issue_id = result.register_issue(
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
description="The input file is not a valid xml document",
level=IssueSeverity.ERROR,
rule_uid=rule_uid,
rule_uid=RULE_UID,
)

result.add_file_location(
checker_data.result.add_file_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
issue_id=issue_id,
row=error_location[0],
column=error_location[1],
description=f"Invalid xml file.",
)

result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.COMPLETED,
)
Loading