From 21eacde17f5bb92da85c9a9dfe26b7c19cb47bcc Mon Sep 17 00:00:00 2001 From: konstantin Date: Sun, 19 May 2024 17:36:44 +0200 Subject: [PATCH] Add Test Case for Segment ID Parsing --- unittests/test_ahb_sub_table.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/unittests/test_ahb_sub_table.py b/unittests/test_ahb_sub_table.py index 2e703f43..d9010d0e 100644 --- a/unittests/test_ahb_sub_table.py +++ b/unittests/test_ahb_sub_table.py @@ -8,7 +8,8 @@ from docx.table import Table from kohlrahbi.ahbtable.ahbsubtable import AhbSubTable -from kohlrahbi.read_functions import get_all_paragraphs_and_tables +from kohlrahbi.read_functions import get_ahb_table, get_all_paragraphs_and_tables +from kohlrahbi.unfoldedahb import UnfoldedAhb class TestAhbSubTable: @@ -41,3 +42,20 @@ def test_from_table(self) -> None: assert isinstance(ahb_sub_table, AhbSubTable) else: raise TypeError("You did not pass a docx table instance.") + + def test_segment_id_parsing(self) -> None: + """ + https://github.com/Hochfrequenz/kohlrahbi/issues/304 + """ + ahb_file_path: Path = Path(__file__).parent / Path( + "test-files/docx_files/UTILMDAHBStrom-informatorischeLesefassung1.2a_99991231_20240403.docx" + ) + assert ahb_file_path.exists() + doc = docx.Document(str(ahb_file_path)) # Creating word reader object. + ahb_table = get_ahb_table(document=doc, pruefi="55109") + assert ahb_table is not None + unfolded_ahb = UnfoldedAhb.from_ahb_table(ahb_table=ahb_table, pruefi="55109") + assert unfolded_ahb is not None + flat_ahb = unfolded_ahb.convert_to_flat_ahb() + assert flat_ahb is not None + assert any(l for l in flat_ahb.lines if l.segment_id is not None)