Umringsprüfung-Segmentbasiert
This commit is contained in:
@@ -4,27 +4,39 @@ Unit-Tests für :mod:`sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_kompl
|
||||
|
||||
Getestete Szenarien:
|
||||
|
||||
Erfolgsfall:
|
||||
- Vollständiger Workflow → enriched Layer + flst_layer + LoadStatus.FIRST
|
||||
Erfolgsfall (Flächenübereinstimmung):
|
||||
- Vollständiger Workflow → enriched Layer + flst_layer + bror_layer + LoadStatus.FIRST
|
||||
- VKZ aus Projektvariable wird als Feld gesetzt (wenn vorhanden)
|
||||
- Kein VKZ in Projektvariable → Feld wird nicht gesetzt (kein Fehler)
|
||||
|
||||
Abbruchpfade:
|
||||
- verfahrensgebiet_alkis gibt LoadStatus.NONE → (None, None, NONE)
|
||||
- flurstueck_alkis gibt LoadStatus.NONE → (None, None, NONE)
|
||||
- Keine Flurstücke selektiert → (None, flst_layer, NONE) + Warnung
|
||||
- erstelle_verfahrensgebiet_aus_auswahl liefert ungültigen Layer → (None, flst_layer, NONE)
|
||||
- Cleanup: ALKIS-VG-Hilfs-Layer wird in allen Fällen aus Projekt entfernt
|
||||
- verfahrensgebiet_alkis gibt LoadStatus.NONE → (None, None, None, NONE)
|
||||
- flurstueck_alkis gibt LoadStatus.NONE → (None, None, None, NONE)
|
||||
- Keine Flurstücke selektiert → (None, flst_layer, None, NONE) + Warnung
|
||||
- erstelle_verfahrensgebiet_aus_auswahl liefert ungültigen Layer → (None, flst_layer, None, NONE)
|
||||
- Progress-Abbruch nach Schritt 1 → sofortiger sauberer Rückgabestatus
|
||||
|
||||
Flächenvergleich:
|
||||
- Übereinstimmung → show_info_dialog, keine Umringsprüfung
|
||||
- Abweichung + Nein → kein Umringsprüfungs-Aufruf
|
||||
- Abweichung + Ja → umringspruefung aufgerufen, Ergebnislayer ins Projekt
|
||||
|
||||
Cleanup:
|
||||
- BROR-Layer wird bei Erfolg NICHT entfernt
|
||||
- BROR-Layer wird bei Fehler entfernt (wenn in diesem Lauf hinzugefügt)
|
||||
- TempVerfahrensgebiet wird stets entfernt
|
||||
|
||||
Hilfsfunktionen:
|
||||
- _select_by_location: processing-Fallback liefert 0 → keine Exception
|
||||
- _fuege_vkz_feld_hinzu: leeres VKZ wird ignoriert
|
||||
- _vergleiche_flaechen: korrekte Toleranzlogik
|
||||
- _lese_flaechen_toleranz: Default 0.0, parst Projektvariable
|
||||
"""
|
||||
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock, call
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Minimales QGIS-Mock-Setup
|
||||
@@ -46,6 +58,8 @@ from sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett import (
|
||||
verfahrensgebiet_alkis_komplett,
|
||||
_select_by_location,
|
||||
_fuege_vkz_feld_hinzu,
|
||||
_vergleiche_flaechen,
|
||||
_lese_flaechen_toleranz,
|
||||
)
|
||||
|
||||
|
||||
@@ -60,7 +74,8 @@ class _DummyRect:
|
||||
def yMaximum(self): return 5658000.0
|
||||
|
||||
|
||||
def _make_layer(valid=True, name="Layer", lid="L1", feature_count=1):
|
||||
def _make_layer(valid=True, name="Layer", lid="L1", feature_count=1, area=1000.0):
|
||||
"""Erzeugt einen konfigurierten Mock-Layer mit getFeatures-Support."""
|
||||
layer = MagicMock()
|
||||
layer.isValid.return_value = valid
|
||||
layer.id.return_value = lid
|
||||
@@ -68,6 +83,18 @@ def _make_layer(valid=True, name="Layer", lid="L1", feature_count=1):
|
||||
layer.extent.return_value = _DummyRect()
|
||||
layer.featureCount.return_value = feature_count
|
||||
layer.selectedFeatureCount.return_value = feature_count
|
||||
|
||||
mock_geom = MagicMock()
|
||||
mock_geom.isEmpty.return_value = False
|
||||
mock_geom.area.return_value = area
|
||||
mock_geom.boundary.return_value = MagicMock(isEmpty=lambda: True)
|
||||
mock_feat = MagicMock()
|
||||
mock_feat.geometry.return_value = mock_geom
|
||||
layer.getFeatures.return_value = [mock_feat]
|
||||
|
||||
mock_crs = MagicMock()
|
||||
mock_crs.authid.return_value = "EPSG:25833"
|
||||
layer.crs.return_value = mock_crs
|
||||
return layer
|
||||
|
||||
|
||||
@@ -90,6 +117,34 @@ class _DummyProject:
|
||||
return self
|
||||
|
||||
|
||||
def _make_progress_mock(canceled=False):
|
||||
prog = MagicMock()
|
||||
prog.is_canceled.return_value = canceled
|
||||
return prog
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Patch-Konstanten
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_MOD = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett"
|
||||
_PATCH_VG_ALKIS = f"{_MOD}.verfahrensgebiet_alkis"
|
||||
_PATCH_GEM = f"{_MOD}.gemarkung_schluessel_und_namen_von_vg_geometrie"
|
||||
_PATCH_FLST = f"{_MOD}.flurstueck_alkis"
|
||||
_PATCH_SELECT = f"{_MOD}._select_by_location"
|
||||
_PATCH_ERSTELLE = f"{_MOD}.erstelle_verfahrensgebiet_aus_auswahl"
|
||||
_PATCH_VKZ = f"{_MOD}._fuege_vkz_feld_hinzu"
|
||||
_PATCH_PROJECT = f"{_MOD}.QgsProject"
|
||||
_PATCH_MSGBOX = f"{_MOD}.QMessageBox"
|
||||
_PATCH_WARNING = f"{_MOD}.warning"
|
||||
_PATCH_GET_VAR = f"{_MOD}.get_variable"
|
||||
_PATCH_PROGRESS = f"{_MOD}.create_progress_dialog"
|
||||
_PATCH_VERGLEICHE = f"{_MOD}._vergleiche_flaechen"
|
||||
_PATCH_SHOW_INFO = f"{_MOD}.show_info_dialog"
|
||||
_PATCH_ASK_YES_NO = f"{_MOD}.ask_yes_no"
|
||||
_PATCH_UMRING = f"{_MOD}.umringspruefung"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tests: _select_by_location
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -97,35 +152,26 @@ class _DummyProject:
|
||||
class TestSelectByLocation(unittest.TestCase):
|
||||
|
||||
def test_processing_not_available_returns_zero(self):
|
||||
"""Wenn processing nicht importierbar ist → 0 ohne Exception."""
|
||||
flst = MagicMock()
|
||||
vg = MagicMock()
|
||||
flst, vg = MagicMock(), MagicMock()
|
||||
with patch.dict("sys.modules", {"processing": None}):
|
||||
result = _select_by_location(flst, vg)
|
||||
self.assertEqual(result, 0)
|
||||
|
||||
def test_processing_success_returns_count(self):
|
||||
"""processing.run erfolgreich → selectedFeatureCount des Layers."""
|
||||
flst = MagicMock()
|
||||
flst.selectedFeatureCount.return_value = 7
|
||||
vg = MagicMock()
|
||||
|
||||
mock_processing = MagicMock()
|
||||
with patch.dict("sys.modules", {"processing": mock_processing}):
|
||||
mock_proc = MagicMock()
|
||||
with patch.dict("sys.modules", {"processing": mock_proc}):
|
||||
result = _select_by_location(flst, vg)
|
||||
|
||||
self.assertEqual(result, 7)
|
||||
|
||||
def test_processing_exception_returns_zero(self):
|
||||
"""Exception in processing.run → 0 ohne Propagation."""
|
||||
flst = MagicMock()
|
||||
vg = MagicMock()
|
||||
|
||||
mock_processing = MagicMock()
|
||||
mock_processing.run.side_effect = RuntimeError("Kein QGIS")
|
||||
with patch.dict("sys.modules", {"processing": mock_processing}):
|
||||
flst, vg = MagicMock(), MagicMock()
|
||||
mock_proc = MagicMock()
|
||||
mock_proc.run.side_effect = RuntimeError("Kein QGIS")
|
||||
with patch.dict("sys.modules", {"processing": mock_proc}):
|
||||
result = _select_by_location(flst, vg)
|
||||
|
||||
self.assertEqual(result, 0)
|
||||
|
||||
|
||||
@@ -136,225 +182,427 @@ class TestSelectByLocation(unittest.TestCase):
|
||||
class TestFuegeVkzFeldHinzu(unittest.TestCase):
|
||||
|
||||
def test_empty_vkz_does_nothing(self):
|
||||
"""Leeres VKZ → kein Zugriff auf Layer."""
|
||||
layer = MagicMock()
|
||||
_fuege_vkz_feld_hinzu(layer, "")
|
||||
layer.dataProvider.assert_not_called()
|
||||
|
||||
def test_none_vkz_does_nothing(self):
|
||||
"""None-VKZ → kein Zugriff auf Layer."""
|
||||
layer = MagicMock()
|
||||
_fuege_vkz_feld_hinzu(layer, None)
|
||||
layer.dataProvider.assert_not_called()
|
||||
|
||||
def test_vkz_field_added(self):
|
||||
"""Nicht-leeres VKZ → Provider.addAttributes wird aufgerufen."""
|
||||
pr = MagicMock()
|
||||
pr.addAttributes.return_value = True
|
||||
pr.changeAttributeValues.return_value = True
|
||||
|
||||
layer = MagicMock()
|
||||
layer.dataProvider.return_value = pr
|
||||
layer.fields.return_value.indexFromName.return_value = 2
|
||||
layer.getFeatures.return_value = []
|
||||
|
||||
_fuege_vkz_feld_hinzu(layer, "VF-2024-001")
|
||||
|
||||
pr.addAttributes.assert_called_once()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tests: _vergleiche_flaechen / _lese_flaechen_toleranz
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestFlaechenvergleich(unittest.TestCase):
|
||||
|
||||
def _layer(self, area: float):
|
||||
layer = MagicMock()
|
||||
geom = MagicMock()
|
||||
geom.isEmpty.return_value = False
|
||||
geom.area.return_value = area
|
||||
feat = MagicMock()
|
||||
feat.geometry.return_value = geom
|
||||
layer.getFeatures.return_value = [feat]
|
||||
return layer
|
||||
|
||||
def test_gleiche_flaeche_stimmt_ueberein(self):
|
||||
self.assertTrue(_vergleiche_flaechen(self._layer(1234.5), self._layer(1234.5), 0.0)[2])
|
||||
|
||||
def test_verschiedene_flaeche_stimmt_nicht_ueberein(self):
|
||||
self.assertFalse(_vergleiche_flaechen(self._layer(1234.5), self._layer(1200.0), 0.0)[2])
|
||||
|
||||
def test_differenz_innerhalb_toleranz(self):
|
||||
self.assertTrue(_vergleiche_flaechen(self._layer(1234.5), self._layer(1234.8), 1.0)[2])
|
||||
|
||||
def test_differenz_ausserhalb_toleranz(self):
|
||||
self.assertFalse(_vergleiche_flaechen(self._layer(1234.5), self._layer(1236.0), 1.0)[2])
|
||||
|
||||
def test_flaechen_werte_korrekt(self):
|
||||
bror_f, vg_f, _ = _vergleiche_flaechen(self._layer(800.0), self._layer(750.0))
|
||||
self.assertAlmostEqual(bror_f, 800.0)
|
||||
self.assertAlmostEqual(vg_f, 750.0)
|
||||
|
||||
@patch(f"{_MOD}.get_variable", return_value=None)
|
||||
def test_lese_toleranz_default_ist_null(self, _):
|
||||
self.assertEqual(_lese_flaechen_toleranz(), 0.0)
|
||||
|
||||
@patch(f"{_MOD}.get_variable", return_value="2.5")
|
||||
def test_lese_toleranz_parst_string(self, _):
|
||||
self.assertAlmostEqual(_lese_flaechen_toleranz(), 2.5)
|
||||
|
||||
@patch(f"{_MOD}.get_variable", return_value="ungueltig")
|
||||
def test_lese_toleranz_ungueltig_fallback_null(self, _):
|
||||
self.assertEqual(_lese_flaechen_toleranz(), 0.0)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tests: verfahrensgebiet_alkis_komplett (Hauptworkflow)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_PATCH_VG_ALKIS = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.verfahrensgebiet_alkis"
|
||||
_PATCH_GEM_BY_BBOX = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.gemarkung_schluessel_und_namen_by_bbox"
|
||||
_PATCH_FLST = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.flurstueck_alkis"
|
||||
_PATCH_SELECT = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett._select_by_location"
|
||||
_PATCH_ERSTELLE = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.erstelle_verfahrensgebiet_aus_auswahl"
|
||||
_PATCH_VKZ = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett._fuege_vkz_feld_hinzu"
|
||||
_PATCH_PROJECT = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.QgsProject"
|
||||
_PATCH_MSGBOX = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.QMessageBox"
|
||||
_PATCH_INFO = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.info"
|
||||
_PATCH_WARNING = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.warning"
|
||||
_PATCH_GET_VAR = "sn_verfahrensgebiet.functions.verfahrensgebiet_alkis_komplett.get_variable"
|
||||
|
||||
|
||||
class TestVerfahrensgebietAlkisKomplett(unittest.TestCase):
|
||||
|
||||
def _make_project(self):
|
||||
proj = _DummyProject()
|
||||
mock = MagicMock()
|
||||
mock.instance.return_value = proj
|
||||
# Leere mapLayersByName für Cleanup
|
||||
proj._layers_by_name = {"Verfahrensgebiet": [], "TempVerfahrensgebiet": []}
|
||||
return mock, proj
|
||||
# ------------------------------------------------------------------ #
|
||||
# Abbruchpfade
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# 1. VG-ALKIS liefert NONE → sofortiger Abbruch #
|
||||
# ------------------------------------------------------------------ #
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_vg_alkis_none_aborts(self, mock_vg, mock_proj):
|
||||
def test_vg_alkis_none_aborts(self, mock_vg, mock_proj, mock_prog):
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
mock_vg.return_value = (None, LoadStatus.NONE)
|
||||
mock_vg.return_value = (None, LoadStatus.NONE, [])
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
enriched, flst, status = verfahrensgebiet_alkis_komplett(None)
|
||||
enriched, flst, bror, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIsNone(enriched)
|
||||
self.assertIsNone(flst)
|
||||
self.assertIsNone(bror)
|
||||
self.assertEqual(status, LoadStatus.NONE)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# 2. flurstueck_alkis liefert NONE → Abbruch nach Gemarkungsabfrage #
|
||||
# ------------------------------------------------------------------ #
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_GEM_BY_BBOX)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_flst_none_aborts(self, mock_vg, mock_gem, mock_flst, mock_proj):
|
||||
def test_flst_none_aborts(self, mock_vg, mock_gem, mock_proj, mock_prog):
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
vg_layer = _make_layer(name="Verfahrensgebiet")
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST)
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = [("1234", "Muster")]
|
||||
mock_flst.return_value = (None, LoadStatus.NONE)
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
enriched, flst, status = verfahrensgebiet_alkis_komplett(None)
|
||||
with patch(_PATCH_FLST, return_value=(None, LoadStatus.NONE)):
|
||||
enriched, flst, bror, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIsNone(enriched)
|
||||
self.assertIsNone(flst)
|
||||
self.assertEqual(status, LoadStatus.NONE)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# 3. Keine Selektion → Warnung + (None, flst_layer, NONE) #
|
||||
# ------------------------------------------------------------------ #
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_MSGBOX)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_GEM_BY_BBOX)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_no_selection_returns_none_enriched(
|
||||
self, mock_vg, mock_gem, mock_flst, mock_proj, mock_select, mock_msgbox
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select, mock_msgbox, mock_prog
|
||||
):
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
vg_layer = _make_layer(name="Verfahrensgebiet")
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST)
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 0 # keine Selektion
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 0
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
enriched, flst, status = verfahrensgebiet_alkis_komplett(None)
|
||||
enriched, flst, bror, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIsNone(enriched)
|
||||
self.assertIs(flst, flst_layer)
|
||||
self.assertIsNone(bror)
|
||||
self.assertEqual(status, LoadStatus.NONE)
|
||||
mock_msgbox.warning.assert_called_once()
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# 4. Vollständiger Erfolgsfall #
|
||||
# ------------------------------------------------------------------ #
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_GEM_BY_BBOX)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_success_full_workflow(
|
||||
self,
|
||||
mock_vg, mock_gem, mock_flst, mock_proj,
|
||||
mock_select, mock_erstelle, mock_get_var, mock_vkz_fn,
|
||||
):
|
||||
"""Vollständiger Workflow → enriched Layer + flst Layer + FIRST."""
|
||||
proj_instance = _DummyProject()
|
||||
mock_proj.instance.return_value = proj_instance
|
||||
|
||||
vg_layer = _make_layer(name="Verfahrensgebiet")
|
||||
flst_layer = _make_layer(name="Flurstücke", lid="FLST1")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", lid="VG_ENRICHED", valid=True)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST)
|
||||
mock_gem.return_value = [("1234", "Muster")]
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 3
|
||||
mock_erstelle.return_value = (enriched, 3, 0)
|
||||
mock_get_var.return_value = "VF-2024-001"
|
||||
|
||||
result_enriched, result_flst, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIs(result_enriched, enriched)
|
||||
self.assertIs(result_flst, flst_layer)
|
||||
self.assertEqual(status, LoadStatus.FIRST)
|
||||
mock_vkz_fn.assert_called_once_with(enriched, "VF-2024-001")
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# 5. Kein VKZ → _fuege_vkz_feld_hinzu mit leerem String #
|
||||
# ------------------------------------------------------------------ #
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_GEM_BY_BBOX)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_no_vkz_variable_passes_empty_string(
|
||||
self,
|
||||
mock_vg, mock_gem, mock_flst, mock_proj,
|
||||
mock_select, mock_erstelle, mock_get_var, mock_vkz_fn,
|
||||
):
|
||||
proj_instance = _DummyProject()
|
||||
mock_proj.instance.return_value = proj_instance
|
||||
|
||||
vg_layer = _make_layer(name="Verfahrensgebiet")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", valid=True)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST)
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 2
|
||||
mock_erstelle.return_value = (enriched, 2, 0)
|
||||
mock_get_var.return_value = "" # keine Projektvariable
|
||||
|
||||
verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
mock_vkz_fn.assert_called_once_with(enriched, "")
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# 6. erstelle_verfahrensgebiet liefert ungültigen Layer #
|
||||
# ------------------------------------------------------------------ #
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_MSGBOX)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_GEM_BY_BBOX)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_invalid_enriched_layer_returns_none(
|
||||
self, mock_vg, mock_gem, mock_flst, mock_proj, mock_select, mock_erstelle, mock_msgbox
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select, mock_erstelle, mock_msgbox, mock_prog
|
||||
):
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
vg_layer = _make_layer()
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
bad_enriched = _make_layer(valid=False)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST)
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 5
|
||||
mock_erstelle.return_value = (bad_enriched, 0, 5)
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 5
|
||||
mock_erstelle.return_value = (bad_enriched, 0, 5)
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
enriched, flst, status = verfahrensgebiet_alkis_komplett(None)
|
||||
enriched, flst, bror, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIsNone(enriched)
|
||||
self.assertIs(flst, flst_layer)
|
||||
self.assertIsNone(bror)
|
||||
self.assertEqual(status, LoadStatus.NONE)
|
||||
mock_msgbox.critical.assert_called_once()
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_progress_cancel_after_step1_returns_none(self, mock_vg, mock_proj, mock_prog):
|
||||
"""Abbruch nach Schritt 1 → sofortiger sauberer Rückgabestatus."""
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
|
||||
prog = MagicMock()
|
||||
prog.is_canceled.side_effect = [False, True] # 1. Aufruf False, 2. True
|
||||
mock_prog.return_value = prog
|
||||
|
||||
enriched, flst, bror, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIsNone(enriched)
|
||||
self.assertEqual(status, LoadStatus.NONE)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Flächenvergleich – Übereinstimmung
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_SHOW_INFO)
|
||||
@patch(_PATCH_VERGLEICHE)
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_success_flaechen_match_zeigt_info(
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select,
|
||||
mock_erstelle, mock_get_var, mock_vkz, mock_vergl, mock_info, mock_prog,
|
||||
):
|
||||
"""Flächenübereinstimmung → show_info_dialog mit erwartetem Text."""
|
||||
proj_inst = _DummyProject()
|
||||
mock_proj.instance.return_value = proj_inst
|
||||
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
flst_layer = _make_layer(name="Flurstücke", lid="FLST1")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", lid="VG_ENRICHED", valid=True)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = [("1234", "Muster")]
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 3
|
||||
mock_erstelle.return_value = (enriched, 3, 0)
|
||||
mock_get_var.return_value = "VF-2024-001"
|
||||
mock_vergl.return_value = (1234.5, 1234.5, True)
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
result_enriched, result_flst, result_bror, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIs(result_enriched, enriched)
|
||||
self.assertIs(result_flst, flst_layer)
|
||||
self.assertIs(result_bror, vg_layer)
|
||||
self.assertEqual(status, LoadStatus.FIRST)
|
||||
mock_vkz.assert_called_once_with(enriched, "VF-2024-001")
|
||||
mock_info.assert_called_once()
|
||||
self.assertIn("erwarteter Geometrie", mock_info.call_args[0][1])
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_SHOW_INFO)
|
||||
@patch(_PATCH_VERGLEICHE)
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_no_vkz_variable_passes_empty_string(
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select,
|
||||
mock_erstelle, mock_get_var, mock_vkz, mock_vergl, mock_info, mock_prog,
|
||||
):
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", valid=True)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 2
|
||||
mock_erstelle.return_value = (enriched, 2, 0)
|
||||
mock_get_var.return_value = ""
|
||||
mock_vergl.return_value = (1000.0, 1000.0, True)
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
mock_vkz.assert_called_once_with(enriched, "")
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Flächenvergleich – Abweichung + Nein
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_UMRING)
|
||||
@patch(_PATCH_ASK_YES_NO)
|
||||
@patch(_PATCH_VERGLEICHE)
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_flaechen_abweichung_nein_kein_umring(
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select,
|
||||
mock_erstelle, mock_get_var, mock_vkz, mock_vergl, mock_ask, mock_umring, mock_prog,
|
||||
):
|
||||
"""Abweichung + Nein → umringspruefung wird NICHT aufgerufen."""
|
||||
mock_proj.instance.return_value = _DummyProject()
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", valid=True)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 3
|
||||
mock_erstelle.return_value = (enriched, 3, 0)
|
||||
mock_get_var.return_value = ""
|
||||
mock_vergl.return_value = (1000.0, 800.0, False)
|
||||
mock_ask.return_value = False
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
result_enriched, _, _, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
mock_umring.assert_not_called()
|
||||
self.assertIs(result_enriched, enriched)
|
||||
self.assertEqual(status, LoadStatus.FIRST)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Flächenvergleich – Abweichung + Ja → Umringsprüfung
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_SHOW_INFO)
|
||||
@patch(_PATCH_UMRING)
|
||||
@patch(_PATCH_ASK_YES_NO)
|
||||
@patch(_PATCH_VERGLEICHE)
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_flaechen_abweichung_ja_startet_umringspruefung(
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select,
|
||||
mock_erstelle, mock_get_var, mock_vkz, mock_vergl, mock_ask,
|
||||
mock_umring, mock_info, mock_prog,
|
||||
):
|
||||
"""Abweichung + Ja → umringspruefung aufgerufen, Ergebnislayer ins Projekt,
|
||||
Abschlussmeldung mit Konfliktanzahl."""
|
||||
proj_inst = _DummyProject()
|
||||
mock_proj.instance.return_value = proj_inst
|
||||
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", valid=True)
|
||||
ergebnis_layer = _make_layer(name="Umringsprüfung", lid="UMRING_L")
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 3
|
||||
mock_erstelle.return_value = (enriched, 3, 0)
|
||||
mock_get_var.return_value = ""
|
||||
mock_vergl.return_value = (1000.0, 800.0, False)
|
||||
mock_ask.return_value = True
|
||||
mock_umring.return_value = (ergebnis_layer, 4)
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
result_enriched, _, _, status = verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
mock_umring.assert_called_once()
|
||||
self.assertIn(ergebnis_layer, proj_inst.added)
|
||||
mock_info.assert_called_once()
|
||||
self.assertIn("4", mock_info.call_args[0][1])
|
||||
self.assertIn("Konfliktstellen", mock_info.call_args[0][1])
|
||||
self.assertEqual(status, LoadStatus.FIRST)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Cleanup-Verhalten
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_SHOW_INFO)
|
||||
@patch(_PATCH_VERGLEICHE)
|
||||
@patch(_PATCH_VKZ)
|
||||
@patch(_PATCH_GET_VAR)
|
||||
@patch(_PATCH_ERSTELLE)
|
||||
@patch(_PATCH_SELECT)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_FLST)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_bror_layer_bleibt_bei_erfolg_im_projekt(
|
||||
self, mock_vg, mock_flst, mock_gem, mock_proj, mock_select,
|
||||
mock_erstelle, mock_get_var, mock_vkz, mock_vergl, mock_info, mock_prog,
|
||||
):
|
||||
"""Bei Erfolg darf der BROR-Layer NICHT entfernt werden."""
|
||||
proj_inst = _DummyProject()
|
||||
mock_proj.instance.return_value = proj_inst
|
||||
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)", lid="BROR_ID")
|
||||
flst_layer = _make_layer(name="Flurstücke")
|
||||
enriched = _make_layer(name="Verfahrensgebiet", valid=True)
|
||||
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_flst.return_value = (flst_layer, LoadStatus.FIRST)
|
||||
mock_select.return_value = 3
|
||||
mock_erstelle.return_value = (enriched, 3, 0)
|
||||
mock_get_var.return_value = ""
|
||||
mock_vergl.return_value = (1000.0, 1000.0, True)
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertNotIn("BROR_ID", proj_inst.removed)
|
||||
|
||||
@patch(_PATCH_PROGRESS)
|
||||
@patch(_PATCH_PROJECT)
|
||||
@patch(_PATCH_GEM)
|
||||
@patch(_PATCH_VG_ALKIS)
|
||||
def test_bror_layer_wird_bei_fehler_entfernt(
|
||||
self, mock_vg, mock_gem, mock_proj, mock_prog
|
||||
):
|
||||
"""Bei Fehler (flst_alkis NONE) wird der BROR-Layer aus dem Projekt entfernt."""
|
||||
proj_inst = _DummyProject()
|
||||
mock_proj.instance.return_value = proj_inst
|
||||
|
||||
vg_layer = _make_layer(name="BauRaumOrdnungsrecht (ALKIS)", lid="BROR_ERR")
|
||||
mock_vg.return_value = (vg_layer, LoadStatus.FIRST, [])
|
||||
mock_gem.return_value = []
|
||||
mock_prog.return_value = _make_progress_mock()
|
||||
|
||||
with patch(_PATCH_FLST, return_value=(None, LoadStatus.NONE)):
|
||||
verfahrensgebiet_alkis_komplett(None)
|
||||
|
||||
self.assertIn("BROR_ERR", proj_inst.removed)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user