You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
motief/tests/test_trajectory_label_confi...

69 lines
2.4 KiB

import sys
import types
# Provide a lightweight stub for heavy optional dependencies so unit tests can
# import explorer without requiring a full runtime environment.
for _mod in ("duckdb", "plotly", "plotly.express", "plotly.graph_objects"):
if _mod not in sys.modules:
sys.modules[_mod] = types.ModuleType(_mod)
# Lightweight Streamlit shim used in tests: provide the small piece of the
# API explorer imports at module-level (cache_data decorator and simple
# placeholders). This avoids importing the real streamlit package in CI.
if "streamlit" not in sys.modules:
_st = types.SimpleNamespace()
def _cache_data(*a, **k):
def _decorator(f):
return f
return _decorator
_st.cache_data = _cache_data
_st.info = lambda *a, **k: None
_st.caption = lambda *a, **k: None
_st.subheader = lambda *a, **k: None
_st.warning = lambda *a, **k: None
_st.plotly_chart = lambda *a, **k: None
_st.columns = lambda *a, **k: (lambda *x: (None, None))()
sys.modules["streamlit"] = _st
from explorer import choose_trajectory_title
from analysis import axis_classifier
def test_trajectory_label_confidence_below_threshold():
axis_def = {
"x_label": "Links\u2013Rechts",
"x_label_confidence": {"2020": 0.5, "2021": 0.6},
}
# When confidence below threshold, choose_trajectory_title should return
# the semantic fallback via display_label_for_modal(...) rather than literal "As 1".
assert choose_trajectory_title(
axis_def, "x", threshold=0.65
) == axis_classifier.display_label_for_modal("As 1", "x")
axis_def_y = {
"y_label": "Progressief\u2013Conservatief",
"y_label_confidence": {"2020": 0.5, "2021": None},
}
assert choose_trajectory_title(
axis_def_y, "y", threshold=0.65
) == axis_classifier.display_label_for_modal("As 2", "y")
def test_trajectory_label_confidence_above_threshold():
axis_def = {
"x_label": "Links\u2013Rechts",
"x_label_confidence": {"2020": 0.7, "2021": 0.65},
}
assert choose_trajectory_title(axis_def, "x", threshold=0.65) == "Links\u2013Rechts"
axis_def_y = {
"y_label": "Progressief\u2013Conservatief",
"y_label_confidence": {"2020": 0.8},
}
assert (
choose_trajectory_title(axis_def_y, "y", threshold=0.65)
== "Progressief\u2013Conservatief"
)