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.
44 lines
1.5 KiB
44 lines
1.5 KiB
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"
|
|
|