refactor: use svd_labels for fallback labels in explorer and axis_classifier (Task 4)

This commit is contained in:
2026-04-02 21:05:30 +02:00
parent 36b58ad50d
commit 5b3cf23d36
3 changed files with 58 additions and 30 deletions
+35 -17
View File
@@ -4,21 +4,34 @@ from analysis import axis_classifier
def test_display_label_for_modal():
assert axis_classifier.display_label_for_modal("As 1", "x") == "Links\u2013Rechts"
assert (
axis_classifier.display_label_for_modal("Stempatroon As 1", "x")
== "Links\u2013Rechts"
)
assert (
axis_classifier.display_label_for_modal("As 2", "y")
== "Conservatief\u2013Progressief"
)
assert (
axis_classifier.display_label_for_modal("Stempatroon As 2", "y")
== "Conservatief\u2013Progressief"
)
# None maps to conventional fallback
assert axis_classifier.display_label_for_modal(None, "x") == "Links\u2013Rechts"
"""Test that display_label_for_modal uses SVD_THEMES for fallback labels."""
# None should return fallback from SVD_THEMES
x_label = axis_classifier.display_label_for_modal(None, "x")
y_label = axis_classifier.display_label_for_modal(None, "y")
# Should return component 1 and 2 labels from SVD_THEMES
assert "EU-integratie" in x_label or "Nationalisme" in x_label
assert "Populistisch" in y_label or "Institutioneel" in y_label
def test_display_label_for_modal_maps_as_labels():
"""Test that 'As 1' and 'As 2' are mapped to semantic labels."""
x_label = axis_classifier.display_label_for_modal("As 1", "x")
y_label = axis_classifier.display_label_for_modal("As 2", "y")
# Should return component 1 and 2 labels
assert "EU-integratie" in x_label or "Nationalisme" in x_label
assert "Populistisch" in y_label or "Institutioneel" in y_label
def test_display_label_for_modal_stempatroon():
"""Test that 'Stempatroon As N' are mapped to semantic labels."""
x_label = axis_classifier.display_label_for_modal("Stempatroon As 1", "x")
y_label = axis_classifier.display_label_for_modal("Stempatroon As 2", "y")
# Should return component 1 and 2 labels
assert "EU-integratie" in x_label or "Nationalisme" in x_label
assert "Populistisch" in y_label or "Institutioneel" in y_label
def test_classify_axes_modal_fallback(monkeypatch, tmp_path):
@@ -69,5 +82,10 @@ def test_classify_axes_modal_fallback(monkeypatch, tmp_path):
if not enriched or not isinstance(enriched, dict):
pytest.skip("classify_axes returned no enrichment in this environment")
assert enriched["x_label"] == "Links\u2013Rechts"
assert enriched["y_label"] == "Progressief\u2013Conservatief"
# Should now return SVD component labels instead of hardcoded values
assert (
"EU-integratie" in enriched["x_label"] or "Nationalisme" in enriched["x_label"]
)
assert (
"Populistisch" in enriched["y_label"] or "Institutioneel" in enriched["y_label"]
)