コード例 #1
0
def test_graph(reformfile1):
    """
    Test TaxCalcIO with output_graph=True.
    """
    # create graphable input
    nobs = 100
    idict = dict()
    idict['RECID'] = [i for i in range(1, nobs + 1)]
    idict['MARS'] = [2 for i in range(1, nobs + 1)]
    idict['s006'] = [10.0 for i in range(1, nobs + 1)]
    idict['e00300'] = [10000 * i for i in range(1, nobs + 1)]
    idict['_expanded_income'] = idict['e00300']
    idf = pd.DataFrame(idict, columns=list(idict))
    # create TaxCalcIO graph files
    tcio = TaxCalcIO(input_data=idf,
                     tax_year=2020,
                     reform=reformfile1.name,
                     assump=None,
                     growdiff_response=None,
                     aging_input_data=False,
                     exact_calculations=False)
    tcio.static_analysis(writing_output_file=False,
                         output_graph=True)
    # delete graph files
    output_filename = tcio.output_filepath()
    fname = output_filename.replace('.csv', '-atr.html')
    if os.path.isfile(fname):
        os.remove(fname)
    fname = output_filename.replace('.csv', '-mtr.html')
    if os.path.isfile(fname):
        os.remove(fname)
コード例 #2
0
def test_sqldb_option(rawinputfile, reformfile1, assumpfile1):
    """
    Test TaxCalcIO output_sqldb option when not writing_output_file.
    """
    taxyear = 2021
    tcio = TaxCalcIO(input_data=rawinputfile.name,
                     tax_year=taxyear,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=rawinputfile.name,
              tax_year=taxyear,
              baseline=None,
              reform=reformfile1.name,
              assump=assumpfile1.name,
              growdiff_response=None,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    outfilepath = tcio.output_filepath()
    dbfilepath = outfilepath.replace('.csv', '.db')
    # --sqldb output
    try:
        tcio.analyze(writing_output_file=False, output_sqldb=True)
    except:  # pylint: disable=bare-except
        if os.path.isfile(dbfilepath):
            try:
                os.remove(dbfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(sqldb)_ok' == 'no'
    # if try was successful, remove the db file
    if os.path.isfile(dbfilepath):
        os.remove(dbfilepath)
コード例 #3
0
def test_output_options(rawinputfile, reformfile1, assumpfile1):
    """
    Test TaxCalcIO output_ceeu & output_dump options when writing_output_file.
    """
    taxyear = 2021
    tcio = TaxCalcIO(input_data=rawinputfile.name,
                     tax_year=taxyear,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=rawinputfile.name,
              tax_year=taxyear,
              baseline=None,
              reform=reformfile1.name,
              assump=assumpfile1.name,
              growdiff_response=None,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    outfilepath = tcio.output_filepath()
    # --ceeu output and standard output
    try:
        tcio.analyze(writing_output_file=True, output_ceeu=True)
    except:  # pylint: disable=bare-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(ceeu)_ok' == 'no'
    # --dump output with full dump
    try:
        tcio.analyze(writing_output_file=True, output_dump=True)
    except:  # pylint: disable=bare-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(dump)_ok' == 'no'

    # --dump output with partial dump
    try:
        tcio.analyze(writing_output_file=True,
                     dump_varset=set(['combined']),
                     output_dump=True)
    except:  # pylint: disable=bare-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(dump)_ok' == 'no'
    # if tries were successful, remove output file and doc file
    if os.path.isfile(outfilepath):
        os.remove(outfilepath)
    docfilepath = outfilepath.replace('.csv', '-doc.text')
    if os.path.isfile(docfilepath):
        os.remove(docfilepath)
コード例 #4
0
def test_write_doc_file(rawinputfile, reformfile1, assumpfile1):
    """
    Test write_doc_file with compound reform.
    """
    taxyear = 2021
    compound_reform = '{}+{}'.format(reformfile1.name, reformfile1.name)
    tcio = TaxCalcIO(input_data=rawinputfile.name,
                     tax_year=taxyear,
                     baseline=None,
                     reform=compound_reform,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=rawinputfile.name,
              tax_year=taxyear,
              baseline=None,
              reform=compound_reform,
              assump=assumpfile1.name,
              growdiff_response=None,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    tcio.write_doc_file()
    outfilepath = tcio.output_filepath()
    docfilepath = outfilepath.replace('.csv', '-doc.text')
    if os.path.isfile(docfilepath):
        os.remove(docfilepath)
コード例 #5
0
def test_tables(reformfile1):
    """
    Test TaxCalcIO with output_tables=True and with positive weights.
    """
    # create tabable input
    nobs = 100
    idict = dict()
    idict['RECID'] = [i for i in range(1, nobs + 1)]
    idict['MARS'] = [2 for i in range(1, nobs + 1)]
    idict['s006'] = [10.0 for i in range(1, nobs + 1)]
    idict['e00300'] = [10000 * i for i in range(1, nobs + 1)]
    idict['expanded_income'] = idict['e00300']
    idf = pd.DataFrame(idict, columns=list(idict))
    # create and initialize TaxCalcIO object
    tcio = TaxCalcIO(input_data=idf,
                     tax_year=2020,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=None)
    assert not tcio.errmsg
    tcio.init(input_data=idf,
              tax_year=2020,
              baseline=None,
              reform=reformfile1.name,
              assump=None,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    # create TaxCalcIO tables file
    tcio.analyze(writing_output_file=False, output_tables=True)
    # delete tables file
    output_filename = tcio.output_filepath()
    fname = output_filename.replace('.csv', '-tab.text')
    if os.path.isfile(fname):
        os.remove(fname)
コード例 #6
0
def test_tables(reformfile1):
    """
    Test TaxCalcIO with output_tables=True and with positive weights.
    """
    # create tabable input
    nobs = 100
    idict = dict()
    idict['RECID'] = [i for i in range(1, nobs + 1)]
    idict['MARS'] = [2 for i in range(1, nobs + 1)]
    idict['s006'] = [10.0 for i in range(1, nobs + 1)]
    idict['e00300'] = [10000 * i for i in range(1, nobs + 1)]
    idict['expanded_income'] = idict['e00300']
    idf = pd.DataFrame(idict, columns=list(idict))
    # create and initialize TaxCalcIO object
    tcio = TaxCalcIO(input_data=idf,
                     tax_year=2020,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=None)
    assert not tcio.errmsg
    tcio.init(input_data=idf,
              tax_year=2020,
              baseline=None,
              reform=reformfile1.name,
              assump=None,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    # create TaxCalcIO tables file
    tcio.analyze(writing_output_file=False, output_tables=True)
    # delete tables file
    output_filename = tcio.output_filepath()
    fname = output_filename.replace('.csv', '-tab.text')
    if os.path.isfile(fname):
        os.remove(fname)
コード例 #7
0
def test_sqldb_option(reformfile1, assumpfile1):
    """
    Test TaxCalcIO output_sqldb option when not writing_output_file.
    """
    taxyear = 2021
    tcio = TaxCalcIO(input_data=pd.read_csv(StringIO(RAWINPUT)),
                     tax_year=taxyear,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=pd.read_csv(StringIO(RAWINPUT)),
              tax_year=taxyear,
              baseline=None,
              reform=reformfile1.name,
              assump=assumpfile1.name,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    outfilepath = tcio.output_filepath()
    dbfilepath = outfilepath.replace('.csv', '.db')
    # --sqldb output
    try:
        tcio.analyze(writing_output_file=False, output_sqldb=True)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(dbfilepath):
            try:
                os.remove(dbfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(sqldb)_ok' == 'no'
    # if try was successful, remove the db file
    if os.path.isfile(dbfilepath):
        os.remove(dbfilepath)
コード例 #8
0
def test_write_doc_file(reformfile1, assumpfile1):
    """
    Test write_doc_file with compound reform.
    """
    taxyear = 2021
    compound_reform = '{}+{}'.format(reformfile1.name, reformfile1.name)
    tcio = TaxCalcIO(input_data=pd.read_csv(StringIO(RAWINPUT)),
                     tax_year=taxyear,
                     baseline=None,
                     reform=compound_reform,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=pd.read_csv(StringIO(RAWINPUT)),
              tax_year=taxyear,
              baseline=None,
              reform=compound_reform,
              assump=assumpfile1.name,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    tcio.write_doc_file()
    outfilepath = tcio.output_filepath()
    docfilepath = outfilepath.replace('.csv', '-doc.text')
    if os.path.isfile(docfilepath):
        os.remove(docfilepath)
コード例 #9
0
def test_output_options(reformfile1, assumpfile1):
    """
    Test TaxCalcIO output_dump options when writing_output_file.
    """
    taxyear = 2021
    tcio = TaxCalcIO(input_data=pd.read_csv(StringIO(RAWINPUT)),
                     tax_year=taxyear,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=pd.read_csv(StringIO(RAWINPUT)),
              tax_year=taxyear,
              baseline=None,
              reform=reformfile1.name,
              assump=assumpfile1.name,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    outfilepath = tcio.output_filepath()
    # minimal output with no --dump option
    try:
        tcio.analyze(writing_output_file=True, output_dump=False)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(minimal_output)_ok' == 'no'
    # --dump output with full dump
    try:
        tcio.analyze(writing_output_file=True, output_dump=True)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(full_dump_output)_ok' == 'no'
    # --dump output with partial dump
    try:
        tcio.analyze(writing_output_file=True,
                     dump_varset=set(['combined']),
                     output_dump=True)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(partial_dump_output)_ok' == 'no'
    # if tries were successful, remove doc file and output file
    docfilepath = outfilepath.replace('.csv', '-doc.text')
    if os.path.isfile(docfilepath):
        os.remove(docfilepath)
    if os.path.isfile(outfilepath):
        os.remove(outfilepath)
コード例 #10
0
def test_output_options(reformfile1, assumpfile1):
    """
    Test TaxCalcIO output_dump options when writing_output_file.
    """
    taxyear = 2021
    tcio = TaxCalcIO(input_data=pd.read_csv(StringIO(RAWINPUT)),
                     tax_year=taxyear,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=assumpfile1.name)
    assert not tcio.errmsg
    tcio.init(input_data=pd.read_csv(StringIO(RAWINPUT)),
              tax_year=taxyear,
              baseline=None,
              reform=reformfile1.name,
              assump=assumpfile1.name,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    outfilepath = tcio.output_filepath()
    # minimal output with no --dump option
    try:
        tcio.analyze(writing_output_file=True, output_dump=False)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(minimal_output)_ok' == 'no'
    # --dump output with full dump
    try:
        tcio.analyze(writing_output_file=True, output_dump=True)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(full_dump_output)_ok' == 'no'
    # --dump output with partial dump
    try:
        tcio.analyze(writing_output_file=True,
                     dump_varset=set(['combined']),
                     output_dump=True)
    except Exception:  # pylint: disable=broad-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(partial_dump_output)_ok' == 'no'
    # if tries were successful, remove doc file and output file
    docfilepath = outfilepath.replace('.csv', '-doc.text')
    if os.path.isfile(docfilepath):
        os.remove(docfilepath)
    if os.path.isfile(outfilepath):
        os.remove(outfilepath)
コード例 #11
0
def test_no_tables_or_graphs(reformfile1):
    """
    Test TaxCalcIO with output_tables=True and output_graphs=True but
    INPUT has zero weights.
    """
    # create input sample that cannot output tables or graphs
    nobs = 10
    idict = dict()
    idict['RECID'] = [i for i in range(1, nobs + 1)]
    idict['MARS'] = [2 for i in range(1, nobs + 1)]
    idict['s006'] = [0.0 for i in range(1, nobs + 1)]
    idict['e00300'] = [10000 * i for i in range(1, nobs + 1)]
    idict['expanded_income'] = idict['e00300']
    idf = pd.DataFrame(idict, columns=list(idict))
    # create and initialize TaxCalcIO object
    tcio = TaxCalcIO(input_data=idf,
                     tax_year=2020,
                     baseline=None,
                     reform=reformfile1.name,
                     assump=None)
    assert not tcio.errmsg
    tcio.init(input_data=idf,
              tax_year=2020,
              baseline=None,
              reform=reformfile1.name,
              assump=None,
              growdiff_response=None,
              aging_input_data=False,
              exact_calculations=False)
    assert not tcio.errmsg
    # create TaxCalcIO tables file
    tcio.analyze(writing_output_file=False,
                 output_tables=True,
                 output_graphs=True)
    # delete tables and graph files
    output_filename = tcio.output_filepath()
    fname = output_filename.replace('.csv', '-tab.text')
    if os.path.isfile(fname):
        os.remove(fname)
    fname = output_filename.replace('.csv', '-atr.html')
    if os.path.isfile(fname):
        os.remove(fname)
    fname = output_filename.replace('.csv', '-mtr.html')
    if os.path.isfile(fname):
        os.remove(fname)
    fname = output_filename.replace('.csv', '-pch.html')
    if os.path.isfile(fname):
        os.remove(fname)
コード例 #12
0
def test_output_otions(rawinputfile, reformfile1, assumpfile1):
    """
    Test TaxCalcIO output_ceeu & output_dump options when writing_output_file.
    """
    taxyear = 2021
    tcio = TaxCalcIO(input_data=rawinputfile.name,
                     tax_year=taxyear,
                     reform=reformfile1.name,
                     assump=assumpfile1.name)
    assert len(tcio.errmsg) == 0
    tcio.init(input_data=rawinputfile.name,
              tax_year=taxyear,
              reform=reformfile1.name,
              assump=assumpfile1.name,
              growdiff_response=None,
              aging_input_data=False,
              exact_calculations=False)
    assert len(tcio.errmsg) == 0
    outfilepath = tcio.output_filepath()
    # --ceeu output and standard output
    try:
        tcio.analyze(writing_output_file=True, output_ceeu=True)
    except:  # pylint: disable=bare-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(ceeu)_ok' == 'no'
    # --dump output
    try:
        tcio.analyze(writing_output_file=True, output_dump=True)
    except:  # pylint: disable=bare-except
        if os.path.isfile(outfilepath):
            try:
                os.remove(outfilepath)
            except OSError:
                pass  # sometimes we can't remove a generated temporary file
        assert 'TaxCalcIO.analyze(dump)_ok' == 'no'
    # if tries were successful, remove the output file
    if os.path.isfile(outfilepath):
        os.remove(outfilepath)