-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Test that known MP start/end dates that have been manually verified do not change in the metadata. | ||
""" | ||
from datetime import datetime | ||
from pytest_cfg_fetcher.fetch import fetch_config | ||
import json | ||
import pandas as pd | ||
import unittest | ||
import warnings | ||
|
||
|
||
|
||
|
||
class DateErrorWarning(Warning): | ||
def __init__(self, date_error): | ||
self.message = f"Date Error: {date_error}" | ||
|
||
def __str__(self): | ||
return self.message | ||
|
||
|
||
|
||
class Test(unittest.TestCase): | ||
|
||
def fetch_known_mandate_dates(self): | ||
return pd.read_csv("test/data/mandate-dates.csv", sep=';') | ||
|
||
|
||
def fetch_mep_meta(self): | ||
return pd.read_csv("data/member_of_parliament.csv") | ||
|
||
|
||
def test_manually_checked_mandates(self): | ||
mep = self.fetch_mep_meta() | ||
df = self.fetch_known_mandate_dates() | ||
config = fetch_config("mandates") | ||
counter = 0 | ||
rows = [] | ||
cols = ["person_id", "date", "type"] | ||
for i, r in df.iterrows(): | ||
fil = mep.loc[(mep['person_id'] == r["person_id"]) & (mep[r["type"].lower()] == r['date'])] | ||
if fil.empty: | ||
counter += 1 | ||
rows.append([r["person_id"], r["date"], r["type"]]) | ||
warnings.warn(f"({r['type']}): {r['date']}, {r['person_id']}" , DateErrorWarning) | ||
if len(rows) > 0: | ||
if config and config['write_errors']: | ||
now = datetime.now().strftime("%Y%m%d-%H%M") | ||
out = pd.DataFrame(rows, columns=cols) | ||
out.to_csv(f"{config['test_out_dir']}{now}_mandates-test.csv", index=False) | ||
|
||
self.assertEqual(counter, 0) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.test() |