Skip to content

Commit

Permalink
Merge pull request #2756 from martinholmer/add-tmd-test
Browse files Browse the repository at this point in the history
Add test_tmdcsv.py pytest file
  • Loading branch information
martinholmer authored Jun 6, 2024
2 parents d9b56c7 + 2504d6d commit b75b24f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help:
@echo "clean : remove .pyc files and local taxcalc package"
@echo "package : build and install local package"
@echo "pytest-cps : generate report for and cleanup after"
@echo " pytest -m 'not requires_pufcsv and not pre_release'"
@echo " pytest -m 'not requires_pufcsv and not requires_tmdcsv and not pre_release'"
@echo "pytest : generate report for and cleanup after"
@echo " pytest -m 'not pre_release'"
@echo "pytest-all : generate report for and cleanup after"
Expand Down
10 changes: 10 additions & 0 deletions taxcalc/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def puf_subsample(puf_fullsample):
return puf_fullsample.sample(frac=0.05, random_state=2222)


@pytest.fixture(scope='session')
def tmd_path(tests_path):
return os.path.join(tests_path, '..', '..', 'tmd.csv')


@pytest.fixture(scope='session')
def tmd_fullsample(tmd_path):
return pandas.read_csv(tmd_path)


@pytest.fixture(scope='session', name='test_reforms_init')
def fixture_test_reforms(tests_path):
"""
Expand Down
38 changes: 38 additions & 0 deletions taxcalc/tests/test_tmdcsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Tests of Tax-Calculator using tmd.csv input.
Note that the tmd.csv file that is required to run this program has
been constructed in the PSLmodels tax-microdata repository using the
2015 IRS SOI PUF file and recent Census CPS data. If you have
acquired from IRS the 2015 SOI PUF file and want to execute this program,
contact the Tax-Calculator development team to discuss your options.
Read Tax-Calculator/TESTING.md for details.
"""
# CODING-STYLE CHECKS:
# pycodestyle test_tmdcsv.py
# pylint --disable=locally-disabled test_tmdcsv.py

import pytest
# pylint: disable=import-error
from taxcalc import Policy, Records, Calculator


@pytest.mark.requires_tmdcsv
def test_tmd_input(tmd_fullsample):
"""
Test Tax-Calculator using full-sample tmd.csv file.
"""
taxyear = 2022
# create a Policy object with current-law policy parameters
pol = Policy()
# create a Records object containing all tmd.csv input records
recs = Records.tmd_constructor(data=tmd_fullsample)
# create a Calculator object using current-law policy and tmd records
calc = Calculator(policy=pol, records=recs)
calc.advance_to_year(taxyear)
calc.calc_all()
assert calc.data_year == Records.TMDCSV_YEAR
assert calc.current_year == taxyear
inctax = calc.weighted_total('iitax')
assert inctax > 0

0 comments on commit b75b24f

Please sign in to comment.