70 lines
3.0 KiB
Python
70 lines
3.0 KiB
Python
|
|
"""Tests für wahlprogramm_check.py (#128) — Erkennung fehlender Wahlprogramme."""
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from app.wahlprogramm_check import check_missing_programmes
|
||
|
|
from app.wahlprogramme import WAHLPROGRAMME
|
||
|
|
from app.bundeslaender import BUNDESLAENDER
|
||
|
|
|
||
|
|
|
||
|
|
class TestCheckMissingProgrammes:
|
||
|
|
"""Einheitstests für check_missing_programmes()."""
|
||
|
|
|
||
|
|
def test_all_covered_returns_empty(self):
|
||
|
|
"""Alle Fraktionen haben ein hinterlegtes Programm → leere Liste."""
|
||
|
|
bl = "NRW"
|
||
|
|
# Nur Fraktionen übergeben, die in WAHLPROGRAMME["NRW"] liegen
|
||
|
|
indexed = list(WAHLPROGRAMME[bl].keys())
|
||
|
|
result = check_missing_programmes(bl, indexed)
|
||
|
|
assert result == [], (
|
||
|
|
f"Erwartet [], bekommen {result!r} — alle Fraktionen sollten abgedeckt sein"
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_one_missing_fraktion(self):
|
||
|
|
"""Eine Fraktion ohne Programm → wird in der Rückgabe gemeldet."""
|
||
|
|
bl = "NRW"
|
||
|
|
# AfD ist in NRW hinterlegt, BSW nicht
|
||
|
|
fraktionen = list(WAHLPROGRAMME[bl].keys()) + ["BSW"]
|
||
|
|
result = check_missing_programmes(bl, fraktionen)
|
||
|
|
assert "BSW" in result
|
||
|
|
|
||
|
|
def test_small_party_never_indexed(self):
|
||
|
|
"""BSW/FREIE WÄHLER/SSW sind typischerweise nicht in WAHLPROGRAMME —
|
||
|
|
werden korrekt als fehlend gemeldet."""
|
||
|
|
bl = "NRW"
|
||
|
|
unindexed_parties = ["BSW", "FREIE WÄHLER", "PIRATEN"]
|
||
|
|
for partei in unindexed_parties:
|
||
|
|
result = check_missing_programmes(bl, [partei])
|
||
|
|
assert partei in result, (
|
||
|
|
f"{partei!r} sollte als fehlend erkannt werden, war aber nicht in {result!r}"
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_empty_fraktionen_returns_empty(self):
|
||
|
|
"""Leere Fraktionsliste → immer leere Ausgabe, kein Fehler."""
|
||
|
|
result = check_missing_programmes("NRW", [])
|
||
|
|
assert result == []
|
||
|
|
|
||
|
|
def test_unknown_bundesland_raises_value_error(self):
|
||
|
|
"""Unbekanntes Bundesland → ValueError."""
|
||
|
|
with pytest.raises(ValueError, match="Unbekanntes Bundesland"):
|
||
|
|
check_missing_programmes("XX", ["CDU"])
|
||
|
|
|
||
|
|
def test_bundesland_without_wahlprogramme_entry(self):
|
||
|
|
"""Aktives Bundesland ohne WAHLPROGRAMME-Eintrag → alle Fraktionen fehlend."""
|
||
|
|
# Finde ein aktives BL, das keinen Eintrag in WAHLPROGRAMME hat
|
||
|
|
bl_without = next(
|
||
|
|
(code for code in BUNDESLAENDER if code not in WAHLPROGRAMME),
|
||
|
|
None,
|
||
|
|
)
|
||
|
|
if bl_without is None:
|
||
|
|
pytest.skip("Alle bekannten Bundesländer haben WAHLPROGRAMME-Einträge")
|
||
|
|
fraktionen = BUNDESLAENDER[bl_without].landtagsfraktionen[:2]
|
||
|
|
result = check_missing_programmes(bl_without, fraktionen)
|
||
|
|
assert result == fraktionen
|
||
|
|
|
||
|
|
def test_result_preserves_order(self):
|
||
|
|
"""Die Reihenfolge der fehlenden Fraktionen entspricht der Input-Reihenfolge."""
|
||
|
|
bl = "NRW"
|
||
|
|
missing_input = ["BSW", "FREIE WÄHLER", "PIRATEN"]
|
||
|
|
result = check_missing_programmes(bl, missing_input)
|
||
|
|
assert result == missing_input
|