Exemplo n.º 1
0
def check_complete_reform_dict(reform_name, complete_reform_dict):
    """
    Check specified complete_reform_dict for reform with specified
    reform_name for valid year values and for valid number of replications.
    Raise error if there are any illegal values; otherwise
    return without doing anything or returning anything.
    """
    replications = complete_reform_dict['replications']
    start_year = complete_reform_dict['start_year']
    refspec = complete_reform_dict['specification']
    refdict = Policy.convert_reform_dictionary(refspec)
    if replications < 1 or replications > 1000:
        msg = 'reform {} has replications {} outside [1,1000] range'
        raise ValueError(msg.format(reform_name, replications))
    if start_year < MIN_START_YEAR or start_year > MAX_START_YEAR:
        msg = 'reform {} has start year {} outside [{},{}] range'
        raise ValueError(msg.format(reform_name, start_year,
                                    MIN_START_YEAR, MAX_START_YEAR))
    first_year = min(refdict)
    if first_year < start_year:
        msg = 'reform {} has first reform year {} before start year {}'
        raise ValueError(msg.format(reform_name, first_year, start_year))
    last_year = max(refdict)
    max_year = start_year + NUMBER_OF_YEARS
    if last_year > max_year:
        msg = 'reform {} has last reform year {} after last results year {}'
        raise ValueError(msg.format(reform_name, last_year, max_year))
    return
Exemplo n.º 2
0
def main(reforms_json_filename, tracing):
    """
    Highest-level logic of reforms.py script.
    """
    # pylint: disable=too-many-locals

    # read specified reforms file and convert to a dictionary of reforms
    reforms_dict = read_reforms_json_file(reforms_json_filename)

    # check validity of each reform
    for ref in sorted(reforms_dict, key=int):
        check_complete_reform_dict(ref, reforms_dict[ref])

    # compute taxcalc results for current-law policy
    (itax_taxcalc_clp, ptax_taxcalc_clp) = taxcalc_clp_results()

    # check that selenium package and chromedriver program are available
    check_selenium_and_chromedriver()

    # process each reform in reforms_dict
    for ref in sorted(reforms_dict, key=int):
        syr = reforms_dict[ref]['start_year']
        refspec = reforms_dict[ref]['specification']
        refdict = Policy.convert_reform_dictionary(refspec)
        (itax_taxcalc,
         ptax_taxcalc) = taxcalc_results(syr, refdict,
                                         itax_taxcalc_clp,
                                         ptax_taxcalc_clp)
        for repl in range(reforms_dict[ref]['replications']):
            ref_repl = '{}-{:03d}'.format(ref, repl)
            if tracing:
                sys.stderr.write('==> {}\n'.format(ref_repl))
                sys.stderr.flush()
            (itax_taxbrain,
             ptax_taxbrain,
             taxbrain_output_url) = taxbrain_results(ref_repl, syr, refspec)
            if len(taxbrain_output_url) == 0:
                if tracing:
                    sys.stderr.write('    no TaxBrain output\n')
                    sys.stderr.flush()
                continue  # to top of replication loop
            else:
                if tracing:
                    sys.stderr.write('    got TaxBrain output\n')
                    sys.stderr.flush()
            check_for_differences(ref_repl, 'ITAX', taxbrain_output_url,
                                  itax_taxbrain, itax_taxcalc)
            check_for_differences(ref_repl, 'PTAX', taxbrain_output_url,
                                  ptax_taxbrain, ptax_taxcalc)

    # return no-error exit code
    return 0
Exemplo n.º 3
0
def main(reforms_json_filename):
    """
    Highest-level logic of reforms.py script.
    """
    # read specified reforms file and convert to a dictionary of reforms
    reforms_dict = read_reforms_json_file(reforms_json_filename)

    # check validity of each reform
    for ref in sorted(reforms_dict):
        check_complete_reform_dict(ref, reforms_dict[ref])

    # compute taxcalc results for current-law policy
    (itax_taxcalc_clp, fica_taxcalc_clp) = taxcalc_clp_results()

    # check that selenium package and chromedriver program are available
    check_selenium_and_chromedriver()

    # process each reform in reforms_dict
    for ref in sorted(reforms_dict):
        syr = reforms_dict[ref]['start_year']
        refspec = reforms_dict[ref]['specification']
        refdict = Policy.convert_reform_dictionary(refspec)
        (itax_taxcalc,
         fica_taxcalc) = taxcalc_results(syr, refdict,
                                         itax_taxcalc_clp,
                                         fica_taxcalc_clp)
        for repl in range(reforms_dict[ref]['replications']):
            ref_repl = '{}-{:03d}'.format(ref, repl)
            (itax_taxbrain,
             fica_taxbrain,
             taxbrain_output_url) = taxbrain_results(ref_repl, syr, refspec)
            if len(taxbrain_output_url) == 0:  # no TaxBrain output
                continue  # to top of replication loop
            check_for_differences(ref_repl, 'ITAX', taxbrain_output_url,
                                  itax_taxbrain, itax_taxcalc)
            check_for_differences(ref_repl, 'FICA', taxbrain_output_url,
                                  fica_taxbrain, fica_taxcalc)

    # return no-error exit code
    return 0
Exemplo n.º 4
0
def test_convert_reform_dictionary():
    with pytest.raises(ValueError):
        rdict = Policy.convert_reform_dictionary({2013: {'2013': [40000]}})
    with pytest.raises(ValueError):
        rdict = Policy.convert_reform_dictionary({'_II_em': {2013: [40000]}})
Exemplo n.º 5
0
def test_convert_reform_dictionary():
    with pytest.raises(ValueError):
        rdict = Policy.convert_reform_dictionary({2013: {'2013': [40000]}})
    with pytest.raises(ValueError):
        rdict = Policy.convert_reform_dictionary({'_II_em': {2013: [40000]}})