|
|
|
|
@ -8,8 +8,9 @@ from unittest.mock import MagicMock, patch |
|
|
|
|
|
|
|
|
|
# Import the functions to test |
|
|
|
|
import sys |
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
sys.path.insert(0, "/home/sgeboers/Projects/stemwijzer") |
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent)) |
|
|
|
|
|
|
|
|
|
from explorer_helpers import compute_party_centroids |
|
|
|
|
|
|
|
|
|
@ -50,38 +51,6 @@ class TestTrajectoryPlotRendering: |
|
|
|
|
|
|
|
|
|
assert "PartyA" in diagnostics.get("parties_all_nan", []) |
|
|
|
|
|
|
|
|
|
def test_name_normalization_improves_matching(self): |
|
|
|
|
"""Test that normalized names improve party matching.""" |
|
|
|
|
# Positions with slightly different name format |
|
|
|
|
positions_by_window = { |
|
|
|
|
"2024-Q1": {"Agema, M.": (1.0, 2.0)}, |
|
|
|
|
} |
|
|
|
|
# Party map with different spacing |
|
|
|
|
party_map = {"Agema, M.": "PVV"} # Without normalization, this might not match |
|
|
|
|
|
|
|
|
|
# After normalization, they should match |
|
|
|
|
def normalize_mp_name(name): |
|
|
|
|
if not name: |
|
|
|
|
return name |
|
|
|
|
name = name.strip() |
|
|
|
|
if "," in name and ", " not in name: |
|
|
|
|
name = name.replace(",", ", ") |
|
|
|
|
return name |
|
|
|
|
|
|
|
|
|
normalized_party_map = {normalize_mp_name(k): v for k, v in party_map.items()} |
|
|
|
|
normalized_positions = { |
|
|
|
|
window: {normalize_mp_name(k): v for k, v in positions.items()} |
|
|
|
|
for window, positions in positions_by_window.items() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Check matching |
|
|
|
|
all_mp_names = set() |
|
|
|
|
for positions in normalized_positions.values(): |
|
|
|
|
all_mp_names.update(positions.keys()) |
|
|
|
|
|
|
|
|
|
matched = sum(1 for mp in all_mp_names if mp in normalized_party_map) |
|
|
|
|
assert matched > 0, "Name normalization should improve matching" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
pytest.main([__file__, "-v"]) |
|
|
|
|
|