Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: hoangtungdinh <[email protected]>
  • Loading branch information
hoangtungdinh committed Sep 16, 2024
1 parent 4321dff commit 359dd46
Show file tree
Hide file tree
Showing 39 changed files with 663 additions and 729 deletions.
217 changes: 109 additions & 108 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions qc_otx/checks/core_checker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from . import core_constants as core_constants
from . import core_checker as core_checker
from . import document_name_matches_filename as document_name_matches_filename
from . import document_name_package_uniqueness as document_name_package_uniqueness
from . import no_unused_imports as no_unused_imports
Expand Down
59 changes: 0 additions & 59 deletions qc_otx/checks/core_checker/core_checker.py

This file was deleted.

1 change: 0 additions & 1 deletion qc_otx/checks/core_checker/core_constants.py

This file was deleted.

36 changes: 17 additions & 19 deletions qc_otx/checks/core_checker/document_name_matches_filename.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import logging

from dataclasses import dataclass
from typing import List

from lxml import etree

from qc_baselib import Configuration, Result, IssueSeverity
from qc_baselib import IssueSeverity, StatusType

from qc_otx import constants
from qc_otx.checks import utils, models
from qc_otx.checks import models

from qc_otx.checks.core_checker import core_constants
from pathlib import Path

CHECKER_ID = "check_asam_otx_core_chk_001_document_name_matches_filename"
CHECKER_DESCRIPTION = "For OTX documents stored in a file system, the attribute name of the <otx> root element should match the filename of the containing file (without the extension '.otx')."
CHECKER_PRECONDITIONS = set()
RULE_UID = "asam.net:otx:1.0.0:core.chk_001.document_name_matches_filename"


def check_rule(checker_data: models.CheckerData) -> None:
"""
Expand All @@ -26,20 +26,18 @@ def check_rule(checker_data: models.CheckerData) -> None:
"""
logging.info("Executing document_name_matches_filename check")

rule_uid = checker_data.result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
emanating_entity="asam.net",
standard="otx",
definition_setting="1.0.0",
rule_full_name="core.chk_001.document_name_matches_filename",
)

root = checker_data.input_file_xml_root
root_attrib = root.getroot().attrib

if "name" not in root_attrib:
logging.error("No name attribute find in otx root node. Abort...")

checker_data.result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.SKIPPED,
)

return

document_name = root_attrib["name"]
Expand All @@ -52,15 +50,15 @@ def check_rule(checker_data: models.CheckerData) -> None:

issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
description="Issue flagging when document name does not match file name",
level=IssueSeverity.WARNING,
rule_uid=rule_uid,
rule_uid=RULE_UID,
)

checker_data.result.add_xml_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
issue_id=issue_id,
xpath="/otx",
description=f"Invalid otx name {document_name} detected. Do not match filename {filename}",
Expand Down
46 changes: 30 additions & 16 deletions qc_otx/checks/core_checker/document_name_package_uniqueness.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import logging, os

from dataclasses import dataclass
from typing import List

from lxml import etree

from qc_baselib import Configuration, Result, IssueSeverity
from qc_baselib import IssueSeverity, StatusType

from qc_otx import constants
from qc_otx.checks import utils, models
from qc_otx.checks import models

from qc_otx.checks.core_checker import core_constants
from pathlib import Path

CHECKER_ID = "check_asam_otx_core_chk_002_document_name_package_uniqueness"
CHECKER_DESCRIPTION = "The value of the <otx> attribute name shall be unique within the scope of all OTX documents belonging to the same package."
CHECKER_PRECONDITIONS = set()
RULE_UID = "asam.net:otx:1.0.0:core.chk_002.document_name_package_uniqueness"


def find_otx_files(directory: str) -> List:
Expand Down Expand Up @@ -55,25 +57,30 @@ def check_rule(checker_data: models.CheckerData) -> None:
"""
logging.info("Executing document_name_package_uniqueness check")

rule_uid = checker_data.result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
emanating_entity="asam.net",
standard="otx",
definition_setting="1.0.0",
rule_full_name="core.chk_002.document_name_package_uniqueness",
)

root = checker_data.input_file_xml_root.getroot()

document_name = root.get("name")
if document_name is None:
logging.error("No name attribute find in otx root node. Abort...")

checker_data.result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.SKIPPED,
)

return

package_name = root.get("package")
if package_name is None:
logging.error("No package attribute find in otx root node. Abort...")

checker_data.result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.SKIPPED,
)

return

document_package_dot_name = package_name + "." + document_name
Expand Down Expand Up @@ -107,6 +114,13 @@ def check_rule(checker_data: models.CheckerData) -> None:
f"Error in setting package root {package_root}. Folder not found. Abort..."
)
os.chdir(previous_wd)

checker_data.result.set_checker_status(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=CHECKER_ID,
status=StatusType.SKIPPED,
)

return
# Collect all otx file path from package root
package_otx_files = find_otx_files(package_root)
Expand All @@ -124,10 +138,10 @@ def check_rule(checker_data: models.CheckerData) -> None:
if not is_valid:
checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
description="Issue flagging when otx name is reused in the same package",
level=IssueSeverity.ERROR,
rule_uid=rule_uid,
rule_uid=RULE_UID,
)

os.chdir(previous_wd)
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import logging, os
import logging

from typing import List

from lxml import etree

from qc_baselib import Result, IssueSeverity
from qc_baselib import IssueSeverity

from qc_otx import constants
from qc_otx.checks import models

from qc_otx.checks.core_checker import core_constants
CHECKER_ID = "check_asam_otx_core_chk_007_have_specification_if_no_realisation_exists"
CHECKER_DESCRIPTION = "For all elements with specification and realisation parts in an OTX document: if there is no <realisation> given, the according <specification> element should exist and have content (no empty string)."
CHECKER_PRECONDITIONS = set()
RULE_UID = "asam.net:otx:1.0.0:core.chk_007.have_specification_if_no_realisation_exists"


NODES_WITH_SPECIFICATION_AND_REALISATION = [
"declaration",
Expand All @@ -29,17 +30,6 @@ def check_rule(checker_data: models.CheckerData) -> None:
"""
logging.info("Executing have_specification_if_no_realisation_exists check")

issue_severity = IssueSeverity.WARNING

rule_uid = checker_data.result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
emanating_entity="asam.net",
standard="otx",
definition_setting="1.0.0",
rule_full_name="core.chk_007.have_specification_if_no_realisation_exists",
)

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

Expand Down Expand Up @@ -70,15 +60,15 @@ def check_rule(checker_data: models.CheckerData) -> None:
if not is_valid:
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
description="Issue to check if empty realisation have content in specification",
level=issue_severity,
rule_uid=rule_uid,
level=IssueSeverity.WARNING,
rule_uid=RULE_UID,
)

checker_data.result.add_xml_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
issue_id=issue_id,
xpath=current_xpath,
description=f"Node {current_xpath} has no realisation and no specification or empty string in specification",
Expand Down
33 changes: 10 additions & 23 deletions qc_otx/checks/core_checker/mandatory_constant_initialization.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging, os
import logging

from typing import List

from lxml import etree

from qc_baselib import Result, IssueSeverity
from qc_baselib import IssueSeverity

from qc_otx import constants
from qc_otx.checks import models

from qc_otx.checks.core_checker import core_constants
CHECKER_ID = "check_asam_otx_core_chk_009_mandatory_constant_initialization"
CHECKER_DESCRIPTION = "Constant declarations shall always be initialized."
CHECKER_PRECONDITIONS = set()
RULE_UID = "asam.net:otx:1.0.0:core.chk_009.mandatory_constant_initialization"


def check_rule(checker_data: models.CheckerData) -> None:
Expand All @@ -20,19 +19,7 @@ def check_rule(checker_data: models.CheckerData) -> None:
"""
logging.info("Executing mandatory_constant_initialization check")

issue_severity = IssueSeverity.ERROR

rule_uid = checker_data.result.register_rule(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
emanating_entity="asam.net",
standard="otx",
definition_setting="1.0.0",
rule_full_name="core.chk_009.mandatory_constant_initialization",
)

tree = checker_data.input_file_xml_root
root = tree.getroot()
# Use XPath to find all nodes constant
constant_nodes = tree.xpath("//constant")

Expand All @@ -49,15 +36,15 @@ def check_rule(checker_data: models.CheckerData) -> None:
current_xpath = tree.getpath(constant_node)
issue_id = checker_data.result.register_issue(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
description="Issue flagging when a constant is not initialized",
level=issue_severity,
rule_uid=rule_uid,
level=IssueSeverity.ERROR,
rule_uid=RULE_UID,
)

checker_data.result.add_xml_location(
checker_bundle_name=constants.BUNDLE_NAME,
checker_id=core_constants.CHECKER_ID,
checker_id=CHECKER_ID,
issue_id=issue_id,
xpath=current_xpath,
description=f"Constant {constant_name} at {current_xpath} is not initialized",
Expand Down
Loading

0 comments on commit 359dd46

Please sign in to comment.