コード例 #1
0
def test_2(input_file,  # pylint: disable=redefined-outer-name
           reform_file):  # pylint: disable=redefined-outer-name
    """
    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()
    amt_brk1 = simtax._policy._AMT_brk1  # pylint: disable=protected-access
    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  # pylint: disable=protected-access
    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  # pylint: disable=protected-access
    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]
コード例 #2
0
def test_2(input_file,  # pylint: disable=redefined-outer-name
           reform_file):  # pylint: disable=redefined-outer-name
    """
    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()
    amt_tthd = simtax._policy._AMT_tthd  # pylint: disable=protected-access
    assert amt_tthd[2015 - syr] == 200000
    assert amt_tthd[2016 - syr] > 200000
    assert amt_tthd[2017 - syr] == 300000
    assert amt_tthd[2018 - syr] > 300000
    ii_em = simtax._policy._II_em  # pylint: disable=protected-access
    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  # pylint: disable=protected-access
    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]
コード例 #3
0
def test_1(input_file):  # pylint: disable=redefined-outer-name
    """
    Test SimpleTaxIO constructor with no policy reform.
    """
    SimpleTaxIO.show_iovar_definitions()
    simtax = SimpleTaxIO(input_filename=input_file.name,
                         reform=None,
                         emulate_taxsim_2441_logic=False)
    assert simtax.number_input_lines() == NUM_INPUT_LINES
コード例 #4
0
ファイル: simtax.py プロジェクト: MattHJensen/taxcalc
def main():
    """
    Contains command-line interface to the Tax-Calculator SimpleTaxIO class.
    """
    # parse command-line arguments:
    parser = argparse.ArgumentParser(
        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.  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 without trying '
                              'to read the INPUT file, so INPUT can be any '
                              'meaningless character (e.g., x or ?'),
                        default=False,
                        action="store_true")
    parser.add_argument('--reform',
                        help=('REFORM is name of optional file that contains '
                              'tax reform provisions; the provisions are '
                              'specified using JSON that may include '
                              '//-comments. No REFORM filename implies use '
                              'of current-law policy.'),
                        default=None)
    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('INPUT',
                        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
    # instantiate SimpleTaxIO object and do tax calculations
    simtax = SimpleTaxIO(input_filename=args.INPUT,
                         reform_filename=args.reform,
                         emulate_taxsim_2441_logic=args.taxsim2441)
    simtax.calculate()
    # return no-error exit code
    return 0
コード例 #5
0
def test_1(input_file):  # pylint: disable=redefined-outer-name
    """
    Test SimpleTaxIO constructor with no policy reform.
    """
    SimpleTaxIO.show_iovar_definitions()
    simtax = SimpleTaxIO(input_filename=input_file.name,
                         reform=None,
                         emulate_taxsim_2441_logic=False)
    assert simtax.number_input_lines() == NUM_INPUT_LINES
コード例 #6
0
def test_3(input_file):  # pylint: disable=redefined-outer-name
    """
    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,
                         emulate_taxsim_2441_logic=False)
    simtax.calculate()
    assert simtax.number_input_lines() == NUM_INPUT_LINES
コード例 #7
0
def test_3(input_file):  # pylint: disable=redefined-outer-name
    """
    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,
                         emulate_taxsim_2441_logic=False,
                         output_records=False)
    simtax.calculate()
    assert simtax.number_input_lines() == NUM_INPUT_LINES
コード例 #8
0
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)
コード例 #9
0
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)
コード例 #10
0
def main(infilename, outfilename):
    """
    Contains high-level logic of the script.
    """
    # read INPUT file into a Pandas DataFrame
    inputdf = pd.read_csv(infilename)

    # translate INPUT variables into OUTPUT lines
    olines = ''
    for idx in range(0, inputdf.shape[0]):
        rec = inputdf.xs(idx)
        odict = extract_output(rec)
        olines += SimpleTaxIO.construct_output_line(odict)

    # write OUTPUT lines to OUTPUT file
    with open(outfilename, 'w') as outfile:
        outfile.write(olines)

    # return no-error exit code
    return 0
コード例 #11
0
def main(infilename, outfilename):
    """
    Contains high-level logic of the script.
    """
    # read INPUT file into a Pandas DataFrame
    inputdf = pd.read_csv(infilename)

    # translate INPUT variables into OUTPUT lines
    olines = ''
    for idx in range(0, inputdf.shape[0]):
        rec = inputdf.xs(idx)
        odict = extract_output(rec)
        olines += SimpleTaxIO.construct_output_line(odict)

    # write OUTPUT lines to OUTPUT file
    with open(outfilename, 'w') as outfile:
        outfile.write(olines)

    # return no-error exit code
    return 0
コード例 #12
0
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
コード例 #13
0
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 = []
コード例 #14
0
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 = []
コード例 #15
0
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 = []
コード例 #16
0
ファイル: simtax.py プロジェクト: intownllc/Tax-Calculator
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 without trying "
            "to read the INPUT file, so INPUT can be any "
            "meaningless character (e.g., x or ?"
        ),
        default=False,
        action="store_true",
    )
    parser.add_argument(
        "--reform",
        help=(
            "REFORM is name of optional file that contains "
            "tax reform provisions; the provisions are "
            "specified using JSON that may include "
            "//-comments. No REFORM filename implies use "
            "of current-law policy."
        ),
        default=None,
    )
    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(
        "INPUT",
        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
    # instantiate SimpleTaxIO object and do tax calculations
    simtax = SimpleTaxIO(
        input_filename=args.INPUT, reform_filename=args.reform, emulate_taxsim_2441_logic=args.taxsim2441
    )
    simtax.calculate()
    # return no-error exit code
    return 0
コード例 #17
0
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 without trying '
                              'to read the INPUT file, so INPUT can be any '
                              'meaningless character (e.g., x or ?'),
                        default=False,
                        action="store_true")
    parser.add_argument('--reform',
                        help=('REFORM is name of optional file that contains '
                              'tax reform provisions; the provisions are '
                              'specified using JSON that may include '
                              '//-comments. No REFORM filename implies use '
                              'of current-law policy.'),
                        default=None)
    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.VALID_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',
                        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
    # instantiate SimpleTaxIO object and do tax calculations
    simtax = SimpleTaxIO(input_filename=args.INPUT,
                         reform=args.reform,
                         emulate_taxsim_2441_logic=args.taxsim2441,
                         output_records=args.records)
    simtax.calculate(writing_output_file=True)
    # return no-error exit code
    return 0
コード例 #18
0
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