From 48d2314929b0f29db99575dbb90ab9cdae5a2bff Mon Sep 17 00:00:00 2001 From: patrickpa Date: Tue, 11 Jun 2024 18:13:33 +0200 Subject: [PATCH] Update locations missing implementation Signed-off-by: patrickpa --- qc_baselib/models/result.py | 14 +++++++----- qc_baselib/result.py | 23 +++++++++++++++++++ tests/data/demo_checker_bundle_extended.xqar | 5 ++++ tests/data/result_test_output.xqar | 8 +++---- tests/test_result.py | 24 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/qc_baselib/models/result.py b/qc_baselib/models/result.py index 253ba6b..5f4238f 100644 --- a/qc_baselib/models/result.py +++ b/qc_baselib/models/result.py @@ -23,9 +23,9 @@ class XMLLocationType(BaseXmlModel, tag="XMLLocation"): class InertialLocationType(BaseXmlModel, tag="InertialLocation"): - x: float - y: float - z: float + x: float = attr(name="x") + y: float = attr(name="y") + z: float = attr(name="z") class FileLocationType(BaseXmlModel, tag="FileLocation"): @@ -34,16 +34,18 @@ class FileLocationType(BaseXmlModel, tag="FileLocation"): file_type: str = attr(name="fileType") -class LocationType(BaseXmlModel, tag="Location"): +class LocationType(BaseXmlModel, tag="Locations"): file_location: List[FileLocationType] = [] xml_location: List[XMLLocationType] = [] - road_location: List[InertialLocationType] = [] + inertial_location: List[InertialLocationType] = [] description: str = attr(name="description") @model_validator(mode="after") def check_at_least_one_element(self) -> Any: if ( - len(self.file_location) + len(self.xml_location) + len(self.road_location) + len(self.file_location) + + len(self.xml_location) + + len(self.inertial_location) < 1 ): raise ValueError( diff --git a/qc_baselib/result.py b/qc_baselib/result.py index df6b159..e5784be 100644 --- a/qc_baselib/result.py +++ b/qc_baselib/result.py @@ -288,6 +288,29 @@ def add_xml_location( result.LocationType(xml_location=[xml_location], description=description) ) + def add_inertial_location( + self, + checker_bundle_name: str, + checker_id: str, + issue_id: int, + x: float, + y: float, + z: float, + description: str, + ) -> None: + inertial_location = result.InertialLocationType(x=x, y=y, z=z) + + bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name) + + checker = self._get_checker(bundle=bundle, checker_id=checker_id) + issue = self._get_issue(checker=checker, issue_id=issue_id) + + issue.locations.append( + result.LocationType( + inertial_location=[inertial_location], description=description + ) + ) + def add_domain_specific_info( self, checker_bundle_name: str, diff --git a/tests/data/demo_checker_bundle_extended.xqar b/tests/data/demo_checker_bundle_extended.xqar index f868589..7fdf496 100644 --- a/tests/data/demo_checker_bundle_extended.xqar +++ b/tests/data/demo_checker_bundle_extended.xqar @@ -22,6 +22,10 @@ + + + + @@ -33,6 +37,7 @@ + diff --git a/tests/data/result_test_output.xqar b/tests/data/result_test_output.xqar index 59d1129..d67e3c4 100644 --- a/tests/data/result_test_output.xqar +++ b/tests/data/result_test_output.xqar @@ -4,12 +4,12 @@ - + - - + + - + diff --git a/tests/test_result.py b/tests/test_result.py index 5235a2f..f7eafae 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -367,6 +367,12 @@ def test_domain_specific_load(loaded_extended_result: Result): ) ) + # Evaluate if loading of issues with domain elements is properly done + assert ( + xml_text + == b'\n \n \n \n \n \n \n \n \n \n \n \n \n' + ) + def test_domain_specific_info_add(): result = Result() @@ -407,6 +413,14 @@ def test_domain_specific_info_add(): xml_info.append(etree.Element("NestedCustomTag", attrib={"test": "value"})) xml_info.append(etree.Element("NestedCustomTag", attrib={"test": "value"})) + result.add_xml_location( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + issue_id=issue_id, + xpath="/foo/test/path", + description="Location for issue", + ) + result.add_domain_specific_info( checker_bundle_name="TestBundle", checker_id="TestChecker", @@ -415,6 +429,16 @@ def test_domain_specific_info_add(): xml_info=xml_info, ) + result.add_file_location( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + issue_id=issue_id, + row=1, + column=0, + file_type="odr", + description="Location for issue", + ) + result.write_to_file(TEST_REPORT_OUTPUT_PATH) output_result = Result()