Skip to content

Commit

Permalink
fix(ahb): Bedingung text might be None in XML + SG AHB_Status is …
Browse files Browse the repository at this point in the history
…not always set (#84)
  • Loading branch information
hf-kklein authored Jan 30, 2025
1 parent bcaf402 commit 62b2c0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/fundamend/reader/ahbreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def _to_code(element: ET.Element) -> Code:
def _to_bedingung(element: ET.Element) -> Bedingung:
return Bedingung(
nummer=strip("[", element.attrib["Nummer"], "]"),
text=element.text.strip(), # type:ignore[union-attr]
text=(element.text or "").strip(),
)


def _to_ub_bedingung(element: ET.Element) -> UbBedingung:
return UbBedingung(
nummer=strip("[", element.attrib["Nummer"], "]"),
text=element.text.strip(), # type:ignore[union-attr]
text=(element.text or "").strip(),
)


Expand Down Expand Up @@ -148,7 +148,11 @@ def _to_segment_group(element: ET.Element) -> SegmentGroup:
return SegmentGroup(
id=lstrip("G_SG", element.tag),
name=element.attrib["Name"],
ahb_status=element.attrib["AHB_Status"],
ahb_status=(
element.attrib["AHB_Status"].strip() or None
if "AHB_Status" in element.attrib and element.attrib["AHB_Status"] is not None
else None
),
elements=tuple(list(segments_and_groups)),
)

Expand Down
24 changes: 24 additions & 0 deletions unittests/test_ahb_serialisierung.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
data_path: Path = Path(__file__).parent.parent / "xml-migs-and-ahbs"


def private_submodule_is_checked_out() -> bool:
return any(data_path.iterdir())


@pytest.mark.parametrize(
"ahb_xml_file_path, expected_date",
[
Expand Down Expand Up @@ -94,11 +98,21 @@
],
)
def test_read_ahb_xml(ahb_xml_file_path: Path, expected_date: date) -> None:
if not private_submodule_is_checked_out():
pytest.skip("Skipping test because of missing private submodule")
reader = AhbReader(ahb_xml_file_path)
actual = reader.get_publishing_date()
assert actual == expected_date


def test_deserializing_all_ahbs() -> None:
if not private_submodule_is_checked_out():
pytest.skip("Skipping test because of missing private submodule")
for ahb_file_path in data_path.rglob("**/*AHB*.xml"):
reader = AhbReader(ahb_file_path)
_ = reader.read() # must not crash


@pytest.mark.parametrize(
"mig_xml_file_path, expected_date",
[
Expand Down Expand Up @@ -185,6 +199,16 @@ def test_read_ahb_xml(ahb_xml_file_path: Path, expected_date: date) -> None:
],
)
def test_read_mig_xml(mig_xml_file_path: Path, expected_date: date) -> None:
if not private_submodule_is_checked_out():
pytest.skip("Skipping test because of missing private submodule")
reader = MigReader(mig_xml_file_path)
actual = reader.get_publishing_date()
assert actual == expected_date


def test_deserializing_all_migs() -> None:
if not private_submodule_is_checked_out():
pytest.skip("Skipping test because of missing private submodule")
for mig_file_path in data_path.rglob("**/*MIG*.xml"):
reader = MigReader(mig_file_path)
_ = reader.read() # must not crash

0 comments on commit 62b2c0e

Please sign in to comment.