feat: add axis swap — left-right goes on horizontal axis when detected
This commit is contained in:
@@ -111,6 +111,21 @@ except Exception:
|
||||
_go.Figure = lambda *a, **kw: None
|
||||
sys.modules["plotly.graph_objects"] = _go
|
||||
|
||||
# Provide a minimal streamlit stub so explorer imports succeed in the test env
|
||||
try:
|
||||
import streamlit as _st # noqa: F401
|
||||
except Exception:
|
||||
_st_stub = types.ModuleType("streamlit")
|
||||
_st_stub.cache_data = lambda **kw: lambda f: f
|
||||
_st_stub.plotly_chart = lambda *a, **kw: None
|
||||
_st_stub.markdown = lambda *a, **kw: None
|
||||
_st_stub.caption = lambda *a, **kw: None
|
||||
_st_stub.error = lambda *a, **kw: None
|
||||
_st_stub.warning = lambda *a, **kw: None
|
||||
_st_stub.info = lambda *a, **kw: None
|
||||
_st_stub.write = lambda *a, **kw: None
|
||||
sys.modules["streamlit"] = _st_stub
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -654,3 +669,58 @@ def test_classify_from_titles_low_confidence():
|
||||
label, confidence = _classify_from_titles(titles)
|
||||
assert label is None
|
||||
assert confidence < 0.4
|
||||
|
||||
|
||||
def test_axis_swap_when_y_is_left_right():
|
||||
"""When y_label is 'Links–Rechts' and x_label is not, positions must be swapped."""
|
||||
from explorer import _swap_axes
|
||||
|
||||
positions_by_window = {
|
||||
"2023": {
|
||||
"VVD": (0.5, 0.8),
|
||||
"PvdA": (-0.3, -0.6),
|
||||
}
|
||||
}
|
||||
axis_def = {
|
||||
"x_label": "Progressief\u2013Conservatief",
|
||||
"y_label": "Links\u2013Rechts",
|
||||
"x_quality": {"2023": 0.7},
|
||||
"y_quality": {"2023": 0.8},
|
||||
"x_interpretation": {"2023": "prog interpretation"},
|
||||
"y_interpretation": {"2023": "lr interpretation"},
|
||||
"x_top_motions": {"2023": {"+": [], "-": []}},
|
||||
"y_top_motions": {"2023": {"+": [], "-": []}},
|
||||
"x_label_confidence": {"2023": 0.5},
|
||||
"y_label_confidence": {"2023": 0.7},
|
||||
}
|
||||
|
||||
new_pos, new_ax = _swap_axes(positions_by_window, axis_def)
|
||||
|
||||
# Positions swapped: (x, y) → (y, x)
|
||||
assert new_pos["2023"]["VVD"] == (0.8, 0.5)
|
||||
assert new_pos["2023"]["PvdA"] == (-0.6, -0.3)
|
||||
|
||||
# Labels swapped
|
||||
assert new_ax["x_label"] == "Links\u2013Rechts"
|
||||
assert new_ax["y_label"] == "Progressief\u2013Conservatief"
|
||||
|
||||
# Quality swapped
|
||||
assert new_ax["x_quality"] == {"2023": 0.8}
|
||||
assert new_ax["y_quality"] == {"2023": 0.7}
|
||||
|
||||
|
||||
def test_axis_swap_not_applied_when_x_is_left_right():
|
||||
"""When x_label is already 'Links–Rechts', no swap should occur."""
|
||||
from explorer import _should_swap_axes
|
||||
|
||||
axis_def = {
|
||||
"x_label": "Links\u2013Rechts",
|
||||
"y_label": "Progressief\u2013Conservatief",
|
||||
}
|
||||
assert _should_swap_axes(axis_def) is False
|
||||
|
||||
axis_def2 = {
|
||||
"x_label": "Links\u2013Rechts",
|
||||
"y_label": "Links\u2013Rechts", # both LR — no swap
|
||||
}
|
||||
assert _should_swap_axes(axis_def2) is False
|
||||
|
||||
Reference in New Issue
Block a user