fix(tests): update test_extract_mp_votes for party-level actor inclusion

New extract_mp_votes behavior inserts all actors (party + individual MPs),
not only comma-name MPs. Test now validates both types and their party column.
Also adds generated HTML visualizations (political axis x5 windows + trajectories).
This commit is contained in:
2026-03-21 23:25:27 +01:00
parent 847b783877
commit 5ad83ef1be
7 changed files with 57 additions and 12 deletions
+15 -12
View File
@@ -47,26 +47,29 @@ def test_extract_mp_votes(tmp_path):
# Run extraction
res = extract_mp_votes(db_path=str(db_file))
# Expected MP rows: count keys that contain a comma in fixtures
expected_mp_count = 0
for item in fixtures:
for k in item.get("voting_results", {}).keys():
if "," in k:
expected_mp_count += 1
# Expected rows: ALL actors (both individual MPs and party-level), across all motions
expected_total = sum(len(item.get("voting_results", {})) for item in fixtures)
assert res["mp_rows_inserted"] == expected_mp_count
assert res["mp_rows_inserted"] == expected_total
assert res["motions_skipped"] == 0
# Verify mp_votes table contains only rows with comma in mp_name and count matches
# Verify row count matches and both comma-name (individual) and no-comma (party) actors present
conn = duckdb.connect(str(db_file))
try:
rows = conn.execute("SELECT mp_name FROM mp_votes").fetchall()
rows = conn.execute("SELECT mp_name, party FROM mp_votes").fetchall()
finally:
conn.close()
assert len(rows) == expected_mp_count
for (mp_name,) in rows:
assert "," in mp_name
assert len(rows) == expected_total
# Individual MPs (comma in name) should have party = None (metadata not yet fetched)
# Party-level actors (no comma) should have party = mp_name
for mp_name, party in rows:
if "," not in mp_name:
# Party-level actor: party column should equal the actor name
assert party == mp_name, (
f"Party actor '{mp_name}' should have party=mp_name, got {party!r}"
)
# Running again should be idempotent: no new mp rows, motions_skipped > 0
res2 = extract_mp_votes(db_path=str(db_file))