Skip to content

Commit

Permalink
Add support for multiple xpath on Result add_xml_location (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: patrickpa <[email protected]>
  • Loading branch information
patrickpa authored Jul 8, 2024
1 parent 74cd1b3 commit 839a1cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions qc_baselib/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,24 @@ def add_xml_location(
checker_bundle_name: str,
checker_id: str,
issue_id: int,
xpath: str,
xpath: Union[str, List[str]],
description: str,
) -> None:
xml_location = result.XMLLocationType(xpath=xpath)
xml_locations = []

if type(xpath) == str:
xml_locations.append(result.XMLLocationType(xpath=xpath))
elif type(xpath) == list:
for path in xpath:
xml_locations.append(result.XMLLocationType(xpath=path))

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(xml_location=[xml_location], description=description)
result.LocationType(xml_location=xml_locations, description=description)
)

def add_inertial_location(
Expand Down
4 changes: 4 additions & 0 deletions tests/data/result_test_output.xqar
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<Locations description="Location for issue">
<XMLLocation xpath="/foo/test/path"/>
</Locations>
<Locations description="Location for issue with list">
<XMLLocation xpath="/foo/test/path"/>
<XMLLocation xpath="/bar/test/path"/>
</Locations>
<Locations description="Location for issue">
<InertialLocation x="1.0" y="2.0" z="3.0"/>
</Locations>
Expand Down
7 changes: 7 additions & 0 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def test_result_write() -> None:
xpath="/foo/test/path",
description="Location for issue",
)
result.add_xml_location(
checker_bundle_name="TestBundle",
checker_id="TestChecker",
issue_id=issue_id,
xpath=["/foo/test/path", "/bar/test/path"],
description="Location for issue with list",
)
result.add_inertial_location(
checker_bundle_name="TestBundle",
checker_id="TestChecker",
Expand Down

0 comments on commit 839a1cf

Please sign in to comment.