diff --git a/taxcalc/cli/tc.py b/taxcalc/cli/tc.py index 3577e152e..94a219d29 100644 --- a/taxcalc/cli/tc.py +++ b/taxcalc/cli/tc.py @@ -8,9 +8,14 @@ import sys import argparse +import difflib from taxcalc import TaxCalcIO +TEST_INPUT_FILENAME = 'test.csv' +TEST_TAXYEAR = 2017 + + def main(): """ Contains command-line interface (CLI) to Tax-Calculator TaxCalcIO class. @@ -18,8 +23,8 @@ def main(): # parse command-line arguments: usage_str = 'tc INPUT TAXYEAR {}{}{}'.format( '[--reform REFORM] [--assump ASSUMP]\n', - ' ', - '[--exact] [--tables] [--graphs] [--ceeu] [--dump]') + ' ', + '[--exact] [--tables] [--graphs] [--ceeu] [--dump] [--test]') parser = argparse.ArgumentParser( prog='', usage=usage_str, @@ -84,21 +89,31 @@ def main(): 'output.'), default=False, action="store_true") + parser.add_argument('--test', + help=('optional flag that conducts installation ' + 'test. No screen output implies passed test; ' + 'differences on screen show failed test.'), + default=False, + action="store_true") args = parser.parse_args() - # instantiate TaxCalcIO object and do tax analysis - tcio = TaxCalcIO(input_data=args.INPUT, - tax_year=args.TAXYEAR, - reform=args.reform, - assump=args.assump) + # write test input and expected output files if --test option specified + if args.test: + write_test_input_output_files() + inputfn = TEST_INPUT_FILENAME + taxyear = TEST_TAXYEAR + else: + inputfn = args.INPUT + taxyear = args.TAXYEAR + # instantiate taxcalcio object and do tax analysis + tcio = TaxCalcIO(input_data=inputfn, tax_year=taxyear, + reform=args.reform, assump=args.assump) if len(tcio.errmsg) > 0: sys.stderr.write(tcio.errmsg) sys.stderr.write('USAGE: tc --help\n') return 1 - aging = args.INPUT.endswith('puf.csv') or args.INPUT.endswith('cps.csv') - tcio.init(input_data=args.INPUT, - tax_year=args.TAXYEAR, - reform=args.reform, - assump=args.assump, + aging = inputfn.endswith('puf.csv') or inputfn.endswith('cps.csv') + tcio.init(input_data=inputfn, tax_year=taxyear, + reform=args.reform, assump=args.assump, growdiff_response=None, aging_input_data=aging, exact_calculations=args.exact) @@ -111,10 +126,49 @@ def main(): output_graphs=args.graphs, output_ceeu=args.ceeu, output_dump=args.dump) + # compare test output with expected test output if --test option specified + if args.test: + compare_test_output_files() # return no-error exit code return 0 # end of main function code +EXPECTED_TEST_OUTPUT_FILENAME = 'test-{}-out.csv'.format(str(TEST_TAXYEAR)[2:]) +ACTUAL_TEST_OUTPUT_FILENAME = 'test-{}-#-#.csv'.format(str(TEST_TAXYEAR)[2:]) + + +def write_test_input_output_files(): + """ + Write test input and expected output files. + """ + input_data = ( + 'RECID,MARS,XTOT,EIC,e00200,e00200p,e00200s,p23250,e18400,e19800\n' + '1, 2, 3, 1, 40000, 40000, 0, 0, 3000, 4000\n' + '2, 2, 3, 1,200000, 200000, 0, 0, 15000, 20000\n' + ) + with open(TEST_INPUT_FILENAME, 'w') as ifile: + ifile.write(input_data) + expected_output_data = ( + 'RECID,YEAR,WEIGHT,INCTAX,LSTAX,PAYTAX\n' + '1,2017,0.00,682.99,0.00,6120.00\n' + '2,2017,0.00,29690.00,0.00,21572.80\n' + ) + with open(EXPECTED_TEST_OUTPUT_FILENAME, 'w') as ofile: + ofile.write(expected_output_data) + + +def compare_test_output_files(): + """ + Compare expected and actual test output files. + """ + explines = open(EXPECTED_TEST_OUTPUT_FILENAME, 'U').readlines() + actlines = open(ACTUAL_TEST_OUTPUT_FILENAME, 'U').readlines() + diff = difflib.unified_diff(explines, actlines, + fromfile=EXPECTED_TEST_OUTPUT_FILENAME, + tofile=ACTUAL_TEST_OUTPUT_FILENAME, n=0) + sys.stdout.writelines(diff) + + if __name__ == '__main__': sys.exit(main()) diff --git a/taxcalc/records_variables.json b/taxcalc/records_variables.json index 853fb68e5..3cab5460e 100644 --- a/taxcalc/records_variables.json +++ b/taxcalc/records_variables.json @@ -424,12 +424,12 @@ }, "p22250": { "type": "float", - "desc": "Sch D: Net short-term gain/loss", + "desc": "Sch D: Net short-term capital gains/losses", "form": {"2013-2016": "1040 Sch D, line 7"} }, "p23250": { "type": "float", - "desc": "Sch D: Net long-term gain/loss", + "desc": "Sch D: Net long-term capital gains/losses", "form": {"2013-2016": "1040 Sch D, line 15"} }, "p25470": {