From ed014086b3cc9bff573943030b0e75b3c76946d3 Mon Sep 17 00:00:00 2001 From: patrickpa Date: Wed, 21 Aug 2024 17:06:17 +0200 Subject: [PATCH 1/5] Add search mode to config model for complete search Signed-off-by: patrickpa --- qc_baselib/models/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qc_baselib/models/config.py b/qc_baselib/models/config.py index ab2244f..001bbc0 100644 --- a/qc_baselib/models/config.py +++ b/qc_baselib/models/config.py @@ -40,7 +40,7 @@ def check_at_least_one_element(self) -> Any: return self -class Config(BaseXmlModel, tag="Config"): +class Config(BaseXmlModel, tag="Config", search_mode="ordered"): params: List[ParamType] = element(tag="Param", default=[]) reports: List[ReportModuleType] = element(tag="ReportModule", default=[]) checker_bundles: List[CheckerBundleType] = element(tag="CheckerBundle", default=[]) From ee32c0bf35d950856df320552401769c3e2e3335 Mon Sep 17 00:00:00 2001 From: patrickpa Date: Wed, 21 Aug 2024 17:09:22 +0200 Subject: [PATCH 2/5] Add search mode ordered for all models with more than one sub-element Signed-off-by: patrickpa --- qc_baselib/models/config.py | 2 +- qc_baselib/models/result.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qc_baselib/models/config.py b/qc_baselib/models/config.py index 001bbc0..216c0e3 100644 --- a/qc_baselib/models/config.py +++ b/qc_baselib/models/config.py @@ -26,7 +26,7 @@ class ReportModuleType(BaseXmlModel): application: str = attr(name="application") -class CheckerBundleType(BaseXmlModel): +class CheckerBundleType(BaseXmlModel, search_mode="ordered"): params: List[ParamType] = element(tag="Param", default=[]) checkers: List[CheckerType] = element(tag="Checker", default=[]) application: str = attr(name="application") diff --git a/qc_baselib/models/result.py b/qc_baselib/models/result.py index ff219ae..fe02311 100644 --- a/qc_baselib/models/result.py +++ b/qc_baselib/models/result.py @@ -33,7 +33,7 @@ class FileLocationType(BaseXmlModel): row: int = attr(name="row") -class LocationType(BaseXmlModel): +class LocationType(BaseXmlModel, search_mode="ordered"): file_location: List[FileLocationType] = element(tag="FileLocation", default=[]) xml_location: List[XMLLocationType] = element(tag="XMLLocation", default=[]) inertial_location: List[InertialLocationType] = element( @@ -44,7 +44,9 @@ class LocationType(BaseXmlModel): @model_validator(mode="after") def check_at_least_one_element(self) -> Any: if ( - len(self.file_location) + len(self.xml_location) + len(self.inertial_location) + len(self.file_location) + + len(self.xml_location) + + len(self.inertial_location) < 1 ): raise ValueError( @@ -225,7 +227,7 @@ def check_skipped_status_containing_issues(self) -> Any: return self -class CheckerBundleType(BaseXmlModel): +class CheckerBundleType(BaseXmlModel, search_mode="ordered"): params: List[ParamType] = element(tag="Param", default=[]) checkers: List[CheckerType] = element(tag="Checker", default=[]) build_date: str = attr(name="build_date") From e47dc68b9b35a184db887b0d58e7b0669245526e Mon Sep 17 00:00:00 2001 From: patrickpa Date: Wed, 21 Aug 2024 17:14:44 +0200 Subject: [PATCH 3/5] Move to unordered use for checking all elements Signed-off-by: patrickpa --- qc_baselib/models/config.py | 4 ++-- qc_baselib/models/result.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qc_baselib/models/config.py b/qc_baselib/models/config.py index 216c0e3..0ef4397 100644 --- a/qc_baselib/models/config.py +++ b/qc_baselib/models/config.py @@ -26,7 +26,7 @@ class ReportModuleType(BaseXmlModel): application: str = attr(name="application") -class CheckerBundleType(BaseXmlModel, search_mode="ordered"): +class CheckerBundleType(BaseXmlModel, search_mode="unordered"): params: List[ParamType] = element(tag="Param", default=[]) checkers: List[CheckerType] = element(tag="Checker", default=[]) application: str = attr(name="application") @@ -40,7 +40,7 @@ def check_at_least_one_element(self) -> Any: return self -class Config(BaseXmlModel, tag="Config", search_mode="ordered"): +class Config(BaseXmlModel, tag="Config", search_mode="unordered"): params: List[ParamType] = element(tag="Param", default=[]) reports: List[ReportModuleType] = element(tag="ReportModule", default=[]) checker_bundles: List[CheckerBundleType] = element(tag="CheckerBundle", default=[]) diff --git a/qc_baselib/models/result.py b/qc_baselib/models/result.py index fe02311..eccbf75 100644 --- a/qc_baselib/models/result.py +++ b/qc_baselib/models/result.py @@ -33,7 +33,7 @@ class FileLocationType(BaseXmlModel): row: int = attr(name="row") -class LocationType(BaseXmlModel, search_mode="ordered"): +class LocationType(BaseXmlModel, search_mode="unordered"): file_location: List[FileLocationType] = element(tag="FileLocation", default=[]) xml_location: List[XMLLocationType] = element(tag="XMLLocation", default=[]) inertial_location: List[InertialLocationType] = element( @@ -194,7 +194,7 @@ class StatusType(str, enum.Enum): SKIPPED = "skipped" -class CheckerType(BaseXmlModel, validate_assignment=True, search_mode="ordered"): +class CheckerType(BaseXmlModel, validate_assignment=True, search_mode="unordered"): addressed_rule: List[RuleType] = element(tag="AddressedRule", default=[]) issues: List[IssueType] = element(tag="Issue", default=[]) metadata: List[MetadataType] = element(tag="Metadata", default=[]) @@ -227,7 +227,7 @@ def check_skipped_status_containing_issues(self) -> Any: return self -class CheckerBundleType(BaseXmlModel, search_mode="ordered"): +class CheckerBundleType(BaseXmlModel, search_mode="unordered"): params: List[ParamType] = element(tag="Param", default=[]) checkers: List[CheckerType] = element(tag="Checker", default=[]) build_date: str = attr(name="build_date") From 894fc8eed6535355e7ded96dcb54f9546bf862c5 Mon Sep 17 00:00:00 2001 From: patrickpa Date: Wed, 21 Aug 2024 17:21:34 +0200 Subject: [PATCH 4/5] Add tests for order changes Signed-off-by: patrickpa --- tests/data/ordered_config.xml | 18 ++++++++++++++++++ tests/data/unordered_config.xml | 16 ++++++++++++++++ tests/test_configuration.py | 26 +++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/data/ordered_config.xml create mode 100644 tests/data/unordered_config.xml diff --git a/tests/data/ordered_config.xml b/tests/data/ordered_config.xml new file mode 100644 index 0000000..e25be6a --- /dev/null +++ b/tests/data/ordered_config.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/data/unordered_config.xml b/tests/data/unordered_config.xml new file mode 100644 index 0000000..74c932d --- /dev/null +++ b/tests/data/unordered_config.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 306ce10..6cd7a0c 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -8,7 +8,7 @@ from qc_baselib.models import config, result from qc_baselib import Configuration - +TEST_DATA_BASE_PATH = "tests/data" DEMO_CONFIG_PATH = "tests/data/demo_checker_bundle_config.xml" EXAMPLE_OUTPUT_CONFIG_PATH = "tests/data/config_test_output.xml" TEST_CONFIG_OUTPUT_PATH = "tests/config_test_output.xml" @@ -172,3 +172,27 @@ def test_config_write() -> None: assert output_xml_text == example_xml_text os.remove(TEST_CONFIG_OUTPUT_PATH) + + +def test_config_file_parse_order_independency() -> None: + config_unordered = Configuration() + config_unordered.load_from_file( + os.path.join(TEST_DATA_BASE_PATH, "unordered_config.xml") + ) + + config_ordered = Configuration() + config_ordered.load_from_file( + os.path.join(TEST_DATA_BASE_PATH, "ordered_config.xml") + ) + + assert len(config_ordered._configuration.reports) == len( + config_unordered._configuration.reports + ) + + assert len(config_ordered._configuration.checker_bundles) == len( + config_unordered._configuration.checker_bundles + ) + + assert len(config_ordered._configuration.params) == len( + config_unordered._configuration.params + ) From 9f96a098167f549e5a41d37a22672cabe47eb349 Mon Sep 17 00:00:00 2001 From: patrickpa Date: Wed, 21 Aug 2024 17:25:24 +0200 Subject: [PATCH 5/5] Fix function name typo Signed-off-by: patrickpa --- tests/test_configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 6cd7a0c..33fa3a8 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -174,7 +174,7 @@ def test_config_write() -> None: os.remove(TEST_CONFIG_OUTPUT_PATH) -def test_config_file_parse_order_independency() -> None: +def test_config_file_parse_order_independence() -> None: config_unordered = Configuration() config_unordered.load_from_file( os.path.join(TEST_DATA_BASE_PATH, "unordered_config.xml")