def test_2(input_file, reform_file): """ Test SimpleTaxIO instantiation with a policy reform from JSON file. """ simtax = SimpleTaxIO(input_filename=input_file.name, reform=reform_file.name, exact_calculations=False, emulate_taxsim_2441_logic=False, output_records=False) assert simtax.number_input_lines() == NUM_INPUT_LINES # check that reform was implemented as specified above in REFORM_CONTENTS syr = simtax.start_year() # pylint: disable=no-member,protected-access amt_brk1 = simtax.policy._AMT_brk1 assert amt_brk1[2015 - syr] == 200000 assert amt_brk1[2016 - syr] > 200000 assert amt_brk1[2017 - syr] == 300000 assert amt_brk1[2018 - syr] > 300000 ii_em = simtax.policy._II_em assert ii_em[2016 - syr] == 6000 assert ii_em[2017 - syr] == 6000 assert ii_em[2018 - syr] == 7500 assert ii_em[2019 - syr] > 7500 assert ii_em[2020 - syr] == 9000 assert ii_em[2021 - syr] > 9000 amt_em = simtax.policy._AMT_em assert amt_em[2016 - syr, 0] > amt_em[2015 - syr, 0] assert amt_em[2017 - syr, 0] > amt_em[2016 - syr, 0] assert amt_em[2018 - syr, 0] == amt_em[2017 - syr, 0] assert amt_em[2019 - syr, 0] == amt_em[2017 - syr, 0] assert amt_em[2020 - syr, 0] == amt_em[2017 - syr, 0] assert amt_em[2021 - syr, 0] > amt_em[2020 - syr, 0] assert amt_em[2022 - syr, 0] > amt_em[2021 - syr, 0]
def test_3(input_file): """ Test SimpleTaxIO calculate method with a policy reform from dictionary. """ policy_reform = { 2016: {'_SS_Earnings_c': [300000]}, 2018: {'_SS_Earnings_c': [500000]}, 2020: {'_SS_Earnings_c': [700000]} } simtax = SimpleTaxIO(input_filename=input_file.name, reform=policy_reform, exact_calculations=False, emulate_taxsim_2441_logic=True, output_records=False) simtax.calculate() assert simtax.number_input_lines() == NUM_INPUT_LINES
def test_incorrect_creation(filename, exact): """ Test incorrect SimpleTaxIO instantiation. """ with pytest.raises(ValueError): SimpleTaxIO(input_filename=filename, reform=None, exact_calculations=exact, emulate_taxsim_2441_logic=False, output_records=False)
def test_invalid_creation_w_file(input_file, reform): """ Test incorrect SimpleTaxIO instantiation with input_file """ with pytest.raises(ValueError): SimpleTaxIO(input_filename=input_file.name, reform=reform, exact_calculations=False, emulate_taxsim_2441_logic=False, output_records=False)
def test_bad_input_file(contents): """ Ensure the provided file contents force a ValueError when used as input """ ifile = tempfile.NamedTemporaryFile(mode='a', delete=False) ifile.write(contents) ifile.close() with pytest.raises(ValueError): SimpleTaxIO(input_filename=ifile.name, reform=None, exact_calculations=False, emulate_taxsim_2441_logic=False, output_records=False) if os.path.isfile(ifile.name): try: os.remove(ifile.name) except OSError: pass # sometimes we can't remove a generated temporary file
def test_1(input_file): """ Test SimpleTaxIO instantiation with no policy reform. """ SimpleTaxIO.show_iovar_definitions() simtax = SimpleTaxIO(input_filename=input_file.name, reform=None, exact_calculations=False, emulate_taxsim_2441_logic=False, output_records=False) assert simtax.number_input_lines() == NUM_INPUT_LINES # test extracting of weight and debugging variables SimpleTaxIO.DVAR_NAMES = ['f2441'] ovar = SimpleTaxIO.extract_output(simtax.calc, 0, exact=True, extract_weight=True) assert ovar SimpleTaxIO.DVAR_NAMES = ['badvar'] with pytest.raises(AttributeError): ovar = SimpleTaxIO.extract_output(simtax.calc, 0) SimpleTaxIO.DVAR_NAMES = []
def test_1(input_file): # pylint: disable=redefined-outer-name """ Test SimpleTaxIO instantiation with no policy reform. """ SimpleTaxIO.show_iovar_definitions() simtax = SimpleTaxIO(input_filename=input_file.name, reform=None, exact_calculations=False, emulate_taxsim_2441_logic=False, output_records=False) assert simtax.number_input_lines() == NUM_INPUT_LINES # test extracting of weight and debugging variables crecs = simtax._calc.records # pylint: disable=protected-access SimpleTaxIO.DVAR_NAMES = ['f2441'] # pylint: disable=unused-variable ovar = SimpleTaxIO.extract_output(crecs, 0, exact=True, extract_weight=True) SimpleTaxIO.DVAR_NAMES = ['badvar'] with pytest.raises(ValueError): ovar = SimpleTaxIO.extract_output(crecs, 0) SimpleTaxIO.DVAR_NAMES = []
def main(): """ Contains command-line interface to the Tax-Calculator SimpleTaxIO class. """ # parse command-line arguments: parser = argparse.ArgumentParser( prog='python simtax.py', description=('Writes to a file the federal tax OUTPUT for the tax ' 'filing units specified in the INPUT file with the ' 'OUTPUT computed from the INPUT using the Tax-Calculator.' ' Both the INPUT and OUTPUT files use Internet-TAXSIM ' 'format. The OUTPUT filename is the INPUT filename ' 'with the ".out-simtax" string appended if no --reform ' 'option is specified; otherwise the OUTPUT filename is ' 'the INPUT filename with the ".out-simtax-REFORM" string ' 'appended (excluding any ".json" ending to the REFORM ' 'filename). The OUTPUT file contains the first 28 ' 'Internet-TAXSIM output variables. Use --iohelp flag ' 'for more information. For details on Internet-TAXSIM ' 'version 9.3 INPUT and OUTPUT formats, go to ' 'http://users.nber.org/~taxsim/taxsim-calc9/')) parser.add_argument('--iohelp', help=('optional flag to show INPUT and OUTPUT ' 'variable definitions and exit'), default=False, action="store_true") parser.add_argument('--reform', help=('REFORM is name of optional file that contains ' 'tax reform "policy" parameters (any "behavior" ' 'or "growth" or "consumption" parameters are ' 'ignored); the REFORM file is specified using ' 'JSON that may include //-comments. No --reform ' 'implies use of current-law policy.'), default=None) parser.add_argument('--exact', help=('optional flag to suppress smoothing in income ' 'tax calculations that eliminate marginal-tax-' 'rate-complicating "stair-steps". The default ' 'is to smooth, and therefore, not to do the ' ' exact calculations called for in the tax ' 'law.'), default=False, action="store_true") parser.add_argument('--taxsim2441', help=('optional flag to emulate the Internet-TAXSIM ' 'practice of approximating the number of ' 'children eligible for the child care expense ' 'credit on Form 2441 by the total number of ' 'dependents of any age. The default practice ' 'is to approximate with the number of ' 'dependents under age 17.'), default=False, action="store_true") parser.add_argument('--records', help=('optional flag that causes the output file to ' 'be a CSV-formatted file containing for each ' 'INPUT filing unit the TAXYEAR values of each ' 'variable in the Records.USABLE_READ_VARS set. ' 'If the --records option is specified, the ' 'output file name will be the same as if the ' 'option was not specified, except that the ' '"out-simtax" part is replaced by "records"'), default=False, action="store_true") parser.add_argument('INPUT', nargs='?', default='', help=('INPUT is name of required file that contains ' 'tax-filing-unit information in Internet-TAXSIM ' 'format.')) args = parser.parse_args() # optionally show INPUT and OUTPUT variable definitions and exit if args.iohelp: SimpleTaxIO.show_iovar_definitions() return 0 # check INPUT filename if args.INPUT == '': sys.stderr.write('ERROR: must specify INPUT file name;\n') sys.stderr.write('USAGE: python simtax.py --help\n') return 1 # instantiate SimpleTaxIO object and do tax calculations simtax = SimpleTaxIO(input_filename=args.INPUT, reform=args.reform, exact_calculations=args.exact, emulate_taxsim_2441_logic=args.taxsim2441, output_records=args.records) simtax.calculate(writing_output_file=True, exact_output=args.exact) # return no-error exit code return 0