diff --git a/pytest.ini b/pytest.ini index e31fa6c8..0b46accd 100644 --- a/pytest.ini +++ b/pytest.ini @@ -6,3 +6,4 @@ markers = taxexp qbid taxexpdiffs + itax diff --git a/tests/test_misc.py b/tests/test_misc.py index 7e1bda11..9baddf9f 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2,6 +2,10 @@ Miscellaneous tests of tmd.csv variable weighted totals. """ +import pytest +import taxcalc as tc +from tmd.storage import STORAGE_FOLDER + def test_no_negative_weights(tmd_variables): assert tmd_variables.s006.min() >= 0, "Negative weights found" @@ -22,3 +26,32 @@ def test_population(tmd_variables): assert ( abs(population / 1e6 / 334.18 - 1) < 0.01 ), "Population not within 1% of 334.18 million" + + +@pytest.mark.itax +def test_income_tax(): + + def compare(name, act, exp, tol): + assert ( + abs(act / exp - 1) < tol + ), f"{name}:act,exp,tol= {act} {exp} {tol}" + + # use national tmd files to compute various 2021 income tax statistics + rec = tc.Records.tmd_constructor( + data_path=(STORAGE_FOLDER / "output" / "tmd.csv.gz"), + weights_path=(STORAGE_FOLDER / "output" / "tmd_weights.csv.gz"), + growfactors_path=(STORAGE_FOLDER / "output" / "tmd_growfactors.csv"), + exact_calculations=True, + ) + sim = tc.Calculator(policy=tc.Policy(), records=rec) + sim.advance_to_year(2021) + sim.calc_all() + wght = sim.array("s006") + agi = sim.array("c00100") + itax = sim.array("iitax") + # check various income tax statistics + compare("wght_sum", wght.sum(), 184e6, 0.01) + hiagi = agi >= 1e6 + compare("wght_sum_hiagi", (wght * hiagi).sum(), 0.875e6, 0.01) + compare("wght_itax_sum", (wght * itax).sum(), 1591e9, 0.01) + compare("wght_itax_sum_hiagi", ((wght * itax) * hiagi).sum(), 902e9, 0.01) diff --git a/tests/test_tax_revenue.py b/tests/test_tax_revenue.py index b2bbc8b5..ea560d13 100644 --- a/tests/test_tax_revenue.py +++ b/tests/test_tax_revenue.py @@ -6,11 +6,15 @@ import taxcalc as tc -FIRST_CYR = 2023 +FIRST_CYR = 2021 LAST_CYR = 2033 -RELTOL_ITAX = 0.10 -RELTOL_PTAX = 0.02 +DEFAULT_RELTOL_ITAX = 0.10 +RELTOL_ITAX = {} +DEFAULT_RELTOL_PTAX = 0.02 +RELTOL_PTAX = { + 2021: 0.05, +} DUMP = False # True implies test always fails with complete output @@ -60,7 +64,7 @@ def test_tax_revenue( emsg = "" for year in range(FIRST_CYR, LAST_CYR + 1): reldiff = act_itax[year] / exp_itax[year] - 1 - same = abs(reldiff) < RELTOL_ITAX + same = abs(reldiff) < RELTOL_ITAX.get(year, DEFAULT_RELTOL_ITAX) if not same or DUMP: msg = ( f"\nITAX:cyr,act,exp,rdiff= {year} " @@ -68,7 +72,7 @@ def test_tax_revenue( ) emsg += msg reldiff = act_ptax[year] / exp_ptax[year] - 1 - same = abs(reldiff) < RELTOL_PTAX + same = abs(reldiff) < RELTOL_PTAX.get(year, DEFAULT_RELTOL_PTAX) if not same or DUMP: msg = ( f"\nPTAX:cyr,act,exp,rdiff= {year} "