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).
main
Sven Geboers 1 month ago
parent 847b783877
commit 5ad83ef1be
  1. 7
      outputs/political_axis_2025_Q1.html
  2. 7
      outputs/political_axis_2025_Q2.html
  3. 7
      outputs/political_axis_2025_Q3.html
  4. 7
      outputs/political_axis_2025_Q4.html
  5. 7
      outputs/political_axis_2026_Q1.html
  6. 7
      outputs/trajectories_top15.html
  7. 27
      tests/test_extract_mp_votes.py

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -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))

Loading…
Cancel
Save