|
| 1 | +from pathlib import Path |
| 2 | +from typing import Generator |
| 3 | + |
1 | 4 | import pytest |
2 | 5 |
|
3 | | -from fundamend.utils import remove_linebreaks_and_hyphens |
| 6 | +from fundamend import AhbReader |
| 7 | +from fundamend.models.anwendungshandbuch import Anwendungsfall, Kommunikationsrichtung |
| 8 | +from fundamend.utils import parse_kommunikation_von, remove_linebreaks_and_hyphens |
| 9 | + |
| 10 | +from .conftest import is_private_submodule_checked_out |
4 | 11 |
|
5 | 12 |
|
6 | 13 | @pytest.mark.parametrize( |
|
20 | 27 | def test_anwendungsfall_beschreibung_normalization(original: str, expected: str) -> None: |
21 | 28 | actual = remove_linebreaks_and_hyphens(original) |
22 | 29 | assert actual == expected |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize( |
| 33 | + "original, expected", |
| 34 | + [ |
| 35 | + pytest.param("", [], id="empty string = no directions"), |
| 36 | + pytest.param("LF an NB", [Kommunikationsrichtung(sender="LF", empfaenger="NB")], id="simple example"), |
| 37 | + pytest.param( |
| 38 | + "MSB an NB, LF", |
| 39 | + [ |
| 40 | + Kommunikationsrichtung(sender="MSB", empfaenger="NB"), |
| 41 | + Kommunikationsrichtung(sender="MSB", empfaenger="LF"), |
| 42 | + ], |
| 43 | + id="two receivers, comma separated", |
| 44 | + ), |
| 45 | + pytest.param( |
| 46 | + "MSB an NB / LF", |
| 47 | + [ |
| 48 | + Kommunikationsrichtung(sender="MSB", empfaenger="NB"), |
| 49 | + Kommunikationsrichtung(sender="MSB", empfaenger="LF"), |
| 50 | + ], |
| 51 | + id="two receivers, slash separated", |
| 52 | + ), |
| 53 | + pytest.param( |
| 54 | + "NB, LF an MSB", |
| 55 | + [ |
| 56 | + Kommunikationsrichtung(sender="NB", empfaenger="MSB"), |
| 57 | + Kommunikationsrichtung(sender="LF", empfaenger="MSB"), |
| 58 | + ], |
| 59 | + id="two senders, comma separated", |
| 60 | + ), |
| 61 | + pytest.param( |
| 62 | + "NB / LF an MSB", |
| 63 | + [ |
| 64 | + Kommunikationsrichtung(sender="NB", empfaenger="MSB"), |
| 65 | + Kommunikationsrichtung(sender="LF", empfaenger="MSB"), |
| 66 | + ], |
| 67 | + id="two senders, slash separated", |
| 68 | + ), |
| 69 | + pytest.param( |
| 70 | + "BIKO an NB / ÜNB", |
| 71 | + [ |
| 72 | + Kommunikationsrichtung(sender="BIKO", empfaenger="NB"), |
| 73 | + Kommunikationsrichtung(sender="BIKO", empfaenger="ÜNB"), |
| 74 | + ], |
| 75 | + id="two receivers, slash separated but with Umlaut", |
| 76 | + ), |
| 77 | + pytest.param( |
| 78 | + "NB an LF\nMSB an LF, NB, ESA", |
| 79 | + [ |
| 80 | + Kommunikationsrichtung(sender="NB", empfaenger="LF"), |
| 81 | + Kommunikationsrichtung(sender="MSB", empfaenger="LF"), |
| 82 | + Kommunikationsrichtung(sender="MSB", empfaenger="NB"), |
| 83 | + Kommunikationsrichtung(sender="MSB", empfaenger="ESA"), |
| 84 | + ], |
| 85 | + id="two lines", |
| 86 | + ), |
| 87 | + pytest.param( |
| 88 | + "NB an LF / MSB\r\nLF an NB, MSB", |
| 89 | + [ |
| 90 | + Kommunikationsrichtung(sender="NB", empfaenger="LF"), |
| 91 | + Kommunikationsrichtung(sender="NB", empfaenger="MSB"), |
| 92 | + Kommunikationsrichtung(sender="LF", empfaenger="NB"), |
| 93 | + Kommunikationsrichtung(sender="LF", empfaenger="MSB"), |
| 94 | + ], |
| 95 | + id="two lines with mixed separators", |
| 96 | + # shit is real, I'm not making this up |
| 97 | + ), |
| 98 | + pytest.param( |
| 99 | + "MSB an NB/LF/ÜNB/MSB/ESA", |
| 100 | + [ |
| 101 | + Kommunikationsrichtung(sender="MSB", empfaenger="NB"), |
| 102 | + Kommunikationsrichtung(sender="MSB", empfaenger="LF"), |
| 103 | + Kommunikationsrichtung(sender="MSB", empfaenger="ÜNB"), |
| 104 | + Kommunikationsrichtung(sender="MSB", empfaenger="MSB"), |
| 105 | + Kommunikationsrichtung(sender="MSB", empfaenger="ESA"), |
| 106 | + ], |
| 107 | + id="many receivers", |
| 108 | + ), |
| 109 | + pytest.param( |
| 110 | + "NB an LF, MSB an NB (Gas)", |
| 111 | + [ |
| 112 | + Kommunikationsrichtung(sender="NB", empfaenger="LF"), |
| 113 | + Kommunikationsrichtung(sender="MSB", empfaenger="NB (Gas)"), |
| 114 | + ], |
| 115 | + ), |
| 116 | + pytest.param("NB (VNB)an NB (LPB)", [Kommunikationsrichtung(sender="NB (VNB)", empfaenger="NB (LPB)")]), |
| 117 | + pytest.param("Beteiligte aus Ursprungs-nachricht", None), |
| 118 | + ], |
| 119 | +) |
| 120 | +def test_parsing_kommunikation_von(original: str, expected: list[Kommunikationsrichtung] | None) -> None: |
| 121 | + actual = parse_kommunikation_von(original) |
| 122 | + assert actual == expected |
| 123 | + |
| 124 | + |
| 125 | +def _all_anwendungsfaelle() -> Generator[Anwendungsfall, None, None]: |
| 126 | + if not is_private_submodule_checked_out(): |
| 127 | + pytest.skip("Skipping test because of missing private submodule") |
| 128 | + private_submodule_root = Path(__file__).parent.parent / "xml-migs-and-ahbs" |
| 129 | + assert private_submodule_root.exists() and private_submodule_root.is_dir() |
| 130 | + for ahb_file_path in private_submodule_root.rglob("**/*AHB*.xml"): |
| 131 | + ahb = AhbReader(ahb_file_path).read() |
| 132 | + for anwendungsfall in ahb.anwendungsfaelle: |
| 133 | + if anwendungsfall.is_outdated: |
| 134 | + continue |
| 135 | + yield anwendungsfall |
| 136 | + |
| 137 | + |
| 138 | +def test_parsing_all_kommunikation_von_there_is() -> None: |
| 139 | + """loop over all AHB files and read the 'Kommunikation Von' Attribute of all the Anwendungsfälle""" |
| 140 | + if not is_private_submodule_checked_out(): |
| 141 | + pytest.skip("Skipping test because of missing private submodule") |
| 142 | + for anwendungsfall in _all_anwendungsfaelle(): |
| 143 | + kommunikation_von = anwendungsfall.kommunikation_von |
| 144 | + if not isinstance(kommunikation_von, str): |
| 145 | + pytest.skip("Skipping test because 'Kommunikation Von' is not a string (anymore)") |
| 146 | + _ = parse_kommunikation_von(kommunikation_von) # must not crash |
0 commit comments