- compute_2d_axes (PCA + anchor) - compute_2d_trajectories - plot_political_compass, plot_2d_trajectories - unit test: tests/test_political_compass.pymain
parent
f7d806dc3a
commit
3551a82f83
@ -0,0 +1 @@ |
|||||||
|
OPENROUTER_API_KEY="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" |
||||||
Binary file not shown.
@ -0,0 +1,44 @@ |
|||||||
|
import numpy as np |
||||||
|
import types |
||||||
|
import sys |
||||||
|
|
||||||
|
import pytest |
||||||
|
|
||||||
|
|
||||||
|
def test_compute_2d_axes_pca_synthetic(monkeypatch): |
||||||
|
"""Synthetic test for compute_2d_axes using patched alignment helper.""" |
||||||
|
|
||||||
|
# Create a fake trajectory module with required helpers |
||||||
|
fake_traj = types.SimpleNamespace() |
||||||
|
|
||||||
|
# _load_window_ids should return ordered windows |
||||||
|
fake_traj._load_window_ids = lambda db: ["w1", "w2"] |
||||||
|
|
||||||
|
# _load_mp_vectors_for_window is not used because we patch _procrustes_align_windows |
||||||
|
fake_traj._load_mp_vectors_for_window = lambda db, w: {} |
||||||
|
|
||||||
|
# Provide aligned vectors directly |
||||||
|
aligned = { |
||||||
|
"w1": {"Alice": np.array([1.0, 0.0, 0.0]), "Bob": np.array([0.0, 1.0, 0.0])}, |
||||||
|
"w2": {"Alice": np.array([0.8, 0.2, 0.0]), "Bob": np.array([0.1, 0.9, 0.0])}, |
||||||
|
} |
||||||
|
|
||||||
|
fake_traj._procrustes_align_windows = lambda x: aligned |
||||||
|
|
||||||
|
# Insert fake module into sys.modules for import by analysis.political_axis |
||||||
|
monkeypatch.setitem(sys.modules, "analysis.trajectory", fake_traj) |
||||||
|
|
||||||
|
# Now import the function under test |
||||||
|
from analysis.political_axis import compute_2d_axes |
||||||
|
|
||||||
|
positions_by_window, axis_def = compute_2d_axes( |
||||||
|
db_path="dummy", window_ids=["w1", "w2"], method="pca" |
||||||
|
) |
||||||
|
|
||||||
|
assert "w1" in positions_by_window and "w2" in positions_by_window |
||||||
|
for wid in ("w1", "w2"): |
||||||
|
for name, coord in positions_by_window[wid].items(): |
||||||
|
assert len(coord) == 2 |
||||||
|
assert np.isfinite(coord[0]) and np.isfinite(coord[1]) |
||||||
|
|
||||||
|
assert axis_def.get("method") == "pca" |
||||||
Loading…
Reference in new issue