Spaces:
Running
Running
Download tests/test_engine.py from Torres1980/alts-data-integrity: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/Torres1980/alts-data-integrity/resolve/main/tests/test_engine.py
- Command line
-
hf download hf://spaces/Torres1980/alts-data-integrity/tests/test_engine.py
-
curl -L -o test_engine.py https://huggingface.co/spaces/Torres1980/alts-data-integrity/resolve/main/tests/test_engine.py
2.38 kB
| """Every injected break must be caught, and nothing clean may be flagged. | |
| Run: python -m pytest tests/ (or: python tests/test_engine.py) | |
| """ | |
| import csv | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(ROOT / "recon")) | |
| from engine import load, reconcile # noqa: E402 | |
| EXPECTED_CHECK = { | |
| "Unbooked capital call": "Capital Call not booked", | |
| "Distribution misclassified": "Distribution classification", | |
| "Duplicate transaction": "Duplicate transaction", | |
| "Valuation lag": ("NAV lag", "Contract value lag"), | |
| "Rounding": "Rounding", | |
| "Value break": ("NAV break", "Contract value break"), | |
| "Commitment mismatch": "Commitment", | |
| "Stale valuation": "Stale valuation", | |
| "Unmapped security": "Security mapping", | |
| "Missing position": "Position setup", | |
| } | |
| def _result(): | |
| data = load(ROOT / "data") | |
| sm = {s["icapital_id"]: s["name"] for s in data["security_master"]} | |
| sm.update({s["addepar_id"]: s["name"] for s in data["security_master"] if s["addepar_id"]}) | |
| with open(ROOT / "data" / "injected_breaks.csv") as f: | |
| injected = [(r["break"], r["account_id"], sm[r["icapital_id"]]) for r in csv.DictReader(f)] | |
| return reconcile(data), injected | |
| def test_every_injected_break_is_found(): | |
| res, injected = _result() | |
| found = {(f.check, f.account_id, f.security) for f in res["findings"] if f.status != "Matched"} | |
| for brk, acct, name in injected: | |
| want = EXPECTED_CHECK[brk] | |
| want = want if isinstance(want, tuple) else (want,) | |
| assert any((w, acct, name) in found for w in want), f"missed {brk} on {acct} {name}" | |
| def test_no_false_positives(): | |
| res, injected = _result() | |
| flagged = [f for f in res["findings"] if f.status != "Matched"] | |
| assert len(flagged) == len(injected) | |
| def test_only_reversible_fixes_are_automated(): | |
| res, _ = _result() | |
| auto_checks = {f.check for f in res["findings"] if f.status == "Auto-resolved"} | |
| assert not auto_checks & {"Duplicate transaction", "Commitment", "Security mapping", "Position setup"} | |
| assert {i["action"] for i in res["imports"]} <= {"ADD_TRANSACTION", "RECLASSIFY", "UPDATE_VALUATION"} | |
| if __name__ == "__main__": | |
| for t in (test_every_injected_break_is_found, test_no_false_positives, test_only_reversible_fixes_are_automated): | |
| t() | |
| print("PASS", t.__name__) | |