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:
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
|
# Run extraction
|
||||||
res = extract_mp_votes(db_path=str(db_file))
|
res = extract_mp_votes(db_path=str(db_file))
|
||||||
|
|
||||||
# Expected MP rows: count keys that contain a comma in fixtures
|
# Expected rows: ALL actors (both individual MPs and party-level), across all motions
|
||||||
expected_mp_count = 0
|
expected_total = sum(len(item.get("voting_results", {})) for item in fixtures)
|
||||||
for item in fixtures:
|
|
||||||
for k in item.get("voting_results", {}).keys():
|
|
||||||
if "," in k:
|
|
||||||
expected_mp_count += 1
|
|
||||||
|
|
||||||
assert res["mp_rows_inserted"] == expected_mp_count
|
assert res["mp_rows_inserted"] == expected_total
|
||||||
assert res["motions_skipped"] == 0
|
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))
|
conn = duckdb.connect(str(db_file))
|
||||||
try:
|
try:
|
||||||
rows = conn.execute("SELECT mp_name FROM mp_votes").fetchall()
|
rows = conn.execute("SELECT mp_name, party FROM mp_votes").fetchall()
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
assert len(rows) == expected_mp_count
|
assert len(rows) == expected_total
|
||||||
for (mp_name,) in rows:
|
|
||||||
assert "," in mp_name
|
# 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
|
# Running again should be idempotent: no new mp rows, motions_skipped > 0
|
||||||
res2 = extract_mp_votes(db_path=str(db_file))
|
res2 = extract_mp_votes(db_path=str(db_file))
|
||||||
|
|||||||
Reference in New Issue
Block a user