Source document

pipeline_philly/verify/test_compare_cells.py

Served verbatim from the project repository. Internal working document conventions apply: documents may reference file paths, branch names, and findings-ledger anchors from the repo.

"""Acceptance tests for compare_cells (fourth external audit, 2026-09-08):
student counts must be compared independently of rate suppression.
Run: python -m pytest pipeline_philly/verify/test_compare_cells.py -q
"""
import pathlib
import sys

sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
from pipeline_philly.verify.absenteeism_full_qa import compare_cells  # noqa: E402


def _run(src_n, srv_n, src_v=75.0, srv_v=75.0):
    key = ("1234", "2024-25", "ALL")
    src = {key: {"value": src_v, "n": src_n, "suppressed": src_v is None}}
    srv = {key: {"value": srv_v, "n": srv_n, "suppressed": srv_v is None}}
    return compare_cells("t", src, srv, None, 0.005, True)


def test_both_rates_suppressed_counts_differ_fails():
    r = _run(10, 999, src_v=None, srv_v=None)
    assert r["denominator_mismatches"] == 1 and r["status"] == "FAIL"


def test_served_count_missing_fails():
    r = _run(100, None)
    assert r["denominator_mismatches"] == 1 and r["status"] == "FAIL"


def test_numeric_count_differs_fails():
    r = _run(100, 999)
    assert r["denominator_mismatches"] == 1 and r["status"] == "FAIL"


def test_matching_passes_and_is_counted():
    r = _run(100, 100)
    assert r["denominator_mismatches"] == 0 and r["denominator_comparisons"] == 1 and r["status"] == "PASS"