def test_calc_table(): b = mcr.Batch(path="tests/example_test_input.csv") table = b.create_table() assert isinstance(table, pd.DataFrame) # table.to_csv("expected_multi_table.csv") expected_table = pd.read_csv(os.path.join(CURR_PATH, "expected_multi_table.csv"), index_col=0) for col in table.columns: assert np.allclose(table[col], expected_table[col])
def test_qbid_params(): """ Adpots a test from Tax-Calculator that checks QBID calculations against results from a TPC paper. """ tpc_path = os.path.join(CURRENT_PATH, "tpc_qbid_input.csv") b = mcr.Batch(tpc_path) table = b.create_table() # QBID from TPC paper expect_qbid = [15000, 1612.5, 0, 15000, 10750, 10000] assert np.allclose(table["Qualified Business Income Deduction"], expect_qbid)
def test_a18_validation(): taxcrunch_in = os.path.join(CURRENT_PATH, "taxsim_validation/taxcrunch_in_a18.csv") crunch = mcr.Batch(taxcrunch_in) table_a18 = crunch.create_table() taxsim_out = os.path.join(CURRENT_PATH, "taxsim_validation/taxsim_out_a18.csv") taxsim_df = pd.read_csv(taxsim_out) taxcrunch_frate = table_a18["Income Tax MTR"] * 100 assert np.allclose(table_a18["Individual Income Tax"], taxsim_df["fiitax"], atol=0.01) assert np.allclose(table_a18["Payroll Tax"], taxsim_df["fica"], atol=0.01) assert np.allclose(taxcrunch_frate, taxsim_df["frate"], atol=0.01)
def test_get_pol_link(): b = mcr.Batch(path="tests/example_test_input.csv") reform_preset = "Trump2016.json" m = b.get_pol(reform_file=reform_preset) assert m._II_rt1[2017 - 2013] == 0.12
def test_get_pol_dict(): b = mcr.Batch(path="tests/example_test_input.csv") m = b.get_pol(reform_file=reform_dict) assert m._CTC_c[2018 - 2013] == 1800
def test_get_pol_directory_file(): b = mcr.Batch(path="tests/example_test_input.csv") # use the full file pathname for testing purposes local_reform = "tests/test_reform.json" n = b.get_pol(reform_file=local_reform) assert n._CTC_c[2018 - 2013] == 1000
def test_get_pol_no_reform(): b = mcr.Batch(path="tests/example_test_input.csv") assert isinstance(b, mcr.Batch) m = b.get_pol(reform_file=None) assert isinstance(m, tc.Policy)
import pytest import json import os import numpy as np import pandas as pd import taxcalc as tc import taxcrunch.cruncher as cr import taxcrunch.multi_cruncher as mcr CURRENT_PATH = os.path.abspath(os.path.dirname(__file__)) input_path = os.path.join(CURRENT_PATH, "example_test_input.csv") reform_path = os.path.join(CURRENT_PATH, "test_reform.json") b = mcr.Batch(input_path) reform_dict = {"CTC_c": {2013: 1300, 2018: 1800}} def test_read_input(crunch=b): invar, invar_marg, rows = b.read_input() assert isinstance(invar, pd.DataFrame) assert isinstance(rows, int) # check that number of input rows matches output rows assert rows == len(b.create_table().index) def test_get_pol_directory_file(crunch=b): n = b.get_pol(reform_file=reform_path)