Exemplo n.º 1
0
def test_legislation_xml_file():
    legislation_tree = xml.etree.ElementTree.parse(model.PARAM_FILE)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(legislation_tree.getroot(),
        state = conv.default_state)

    legislation_xml_json, errors = legislationsxml.validate_node_xml_json(legislation_xml_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_xml_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_xml_json, ensure_ascii = False,
                indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_xml_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    _, legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)

    legislation_json, errors = legislations.validate_node_json(legislation_json, state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    dated_legislation_json = legislations.generate_dated_legislation_json(legislation_json, datetime.date(2006, 1, 1))
#    raise ValueError(unicode(json.dumps(dated_legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))
    compact_legislation = legislations.compact_dated_node_json(dated_legislation_json)
Exemplo n.º 2
0
def check_legislation_xml_file(year):
    legislation_tree = conv.check(legislationsxml.make_xml_legislation_info_list_to_xml_element(False))(
        TaxBenefitSystem.legislation_xml_info_list, state = conv.default_state)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(
        legislation_tree,
        state = conv.default_state,
        )

    legislation_xml_json, errors = legislationsxml.validate_legislation_xml_json(legislation_xml_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_xml_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_xml_json, ensure_ascii = False,
                indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_xml_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    _, legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)

    legislation_json, errors = legislations.validate_legislation_json(legislation_json, state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    # Create tax_benefit system only now, to be able to debug XML validation errors in above code.
    tax_benefit_system = TaxBenefitSystem()
    if tax_benefit_system.preprocess_legislation is not None:
        legislation_json = tax_benefit_system.preprocess_legislation(legislation_json)

    legislation_json = legislations.generate_dated_legislation_json(legislation_json, year)
    legislation_json, errors = legislations.validate_dated_legislation_json(legislation_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode(
                'utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    compact_legislation = legislations.compact_dated_node_json(legislation_json)
    assert compact_legislation is not None
Exemplo n.º 3
0
def check_legislation_xml_file(year):
    legislation_tree = xml.etree.ElementTree.parse(base.TaxBenefitSystem.legislation_xml_file_path)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(legislation_tree.getroot(),
        state = conv.default_state)

    legislation_xml_json, errors = legislationsxml.validate_legislation_xml_json(legislation_xml_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_xml_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_xml_json, ensure_ascii = False,
                indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_xml_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    _, legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)

    legislation_json, errors = legislations.validate_legislation_json(legislation_json, state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    legislation_json = legislations.generate_dated_legislation_json(legislation_json, year)
    legislation_json, errors = legislations.validate_dated_legislation_json(legislation_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode(
                'utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    compact_legislation = legislations.compact_dated_node_json(legislation_json)
    # Create tax_benefit system only now, to be able to debug XML validation errors in above code.
    if base.tax_benefit_system.preprocess_compact_legislation is not None:
        base.tax_benefit_system.preprocess_compact_legislation(compact_legislation)
def test_legislation_xml_file():
    legislation_tree = xml.etree.ElementTree.parse(model.PARAM_FILE)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(legislation_tree.getroot(),
        state = conv.default_state)

    legislation_xml_json, errors = legislationsxml.validate_legislation_xml_json(legislation_xml_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_xml_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_xml_json, ensure_ascii = False,
                indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_xml_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    _, legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)

    legislation_json, errors = legislations.validate_legislation_json(legislation_json, state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    dated_legislation_json = legislations.generate_dated_legislation_json(legislation_json, datetime.date(2006, 1, 1))
    dated_legislation_json, errors = legislations.validate_dated_legislation_json(dated_legislation_json,
        state = conv.default_state)
    if errors is not None:
        errors = conv.embed_error(dated_legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(unicode(json.dumps(dated_legislation_json, ensure_ascii = False, indent = 2)).encode(
                'utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
            unicode(json.dumps(dated_legislation_json, ensure_ascii = False, indent = 2)),
            ).encode('utf-8'))

    compact_legislation = legislations.compact_dated_node_json(dated_legislation_json)
Exemplo n.º 5
0
def check_legislation_xml_file(year):
    legislation_tree = conv.check(
        legislationsxml.make_xml_legislation_info_list_to_xml_element(False))(
            TaxBenefitSystem.legislation_xml_info_list,
            state=conv.default_state)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(
        legislation_tree,
        state=conv.default_state,
    )

    legislation_xml_json, errors = legislationsxml.validate_legislation_xml_json(
        legislation_xml_json, state=conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_xml_json, 'errors', errors)
        if errors is None:
            raise ValueError(
                unicode(
                    json.dumps(legislation_xml_json,
                               ensure_ascii=False,
                               indent=2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(
                json.dumps(errors,
                           ensure_ascii=False,
                           indent=2,
                           sort_keys=True)),
            unicode(
                json.dumps(legislation_xml_json, ensure_ascii=False,
                           indent=2)),
        ).encode('utf-8'))

    _, legislation_json = legislationsxml.transform_node_xml_json_to_json(
        legislation_xml_json)

    legislation_json, errors = legislations.validate_legislation_json(
        legislation_json, state=conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(
                unicode(
                    json.dumps(legislation_json, ensure_ascii=False,
                               indent=2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(
                json.dumps(errors,
                           ensure_ascii=False,
                           indent=2,
                           sort_keys=True)),
            unicode(json.dumps(legislation_json, ensure_ascii=False,
                               indent=2)),
        ).encode('utf-8'))

    # Create tax_benefit system only now, to be able to debug XML validation errors in above code.
    tax_benefit_system = TaxBenefitSystem()
    if tax_benefit_system.preprocess_legislation is not None:
        legislation_json = tax_benefit_system.preprocess_legislation(
            legislation_json)

    legislation_json = legislations.generate_dated_legislation_json(
        legislation_json, year)
    legislation_json, errors = legislations.validate_dated_legislation_json(
        legislation_json, state=conv.default_state)
    if errors is not None:
        errors = conv.embed_error(legislation_json, 'errors', errors)
        if errors is None:
            raise ValueError(
                unicode(
                    json.dumps(legislation_json, ensure_ascii=False,
                               indent=2)).encode('utf-8'))
        raise ValueError(u'{0} for: {1}'.format(
            unicode(
                json.dumps(errors,
                           ensure_ascii=False,
                           indent=2,
                           sort_keys=True)),
            unicode(json.dumps(legislation_json, ensure_ascii=False,
                               indent=2)),
        ).encode('utf-8'))

    compact_legislation = legislations.compact_dated_node_json(
        legislation_json)
    assert compact_legislation is not None
Exemplo n.º 6
0
def test_parametric_reform(year):
    legislation_tree = xml.etree.ElementTree.parse(TaxBenefitSystem.PARAM_FILE)
    legislation_xml_json = conv.check(legislationsxml.xml_legislation_to_json)(
        legislation_tree.getroot(),
        state = conv.default_state
        )
    _, legislation_json = legislationsxml.transform_node_xml_json_to_json(legislation_xml_json)

    legislation_json_src = legislation_json
#    import json
#    with open("/tmp/src.json", "w") as f:
#        f.write(
#            json.dumps(legislation_json_src, ensure_ascii = False, encoding = "utf8", indent = 2).encode("utf8"))
#    print str((legislation_json_src['children']['ir']['children']['bareme']['slices'][0]['rate'],))
#    print str((legislation_json_src['children']['ir']['children']['bareme']['slices'][1]['rate'],))
    legislation_json_reform = copy.deepcopy(legislation_json_src)
    legislation_json_reform['children']['ir']['children']['bareme']['slices'][0]['rate'][-1]['value'] = 1

    # import json_delta
    # json_delta: bug with ordered dicts
    #difference = json_delta.diff(p, p_copy)

#    from dictdiffer import diff, patch, swap, revert
#    difference = diff(p, p_copy)
#    print difference (ugly)

    legislation_json_patch = jsonpatch.make_patch(legislation_json_src, legislation_json_reform)
    print legislation_json_patch

    reform = Reform(name = u"Imposition à 100% dès le premier euro et jusqu'à la fin de la 1ère tranche",
                    legislation_json_patch = legislation_json_patch)

    simulation = tax_benefit_system.new_scenario().init_single_entity(
        axes = [
            dict(
                count = 3,
                name = 'sali',
                max = 100000,
                min = 0,
                ),
            ],
        parent1 = dict(birth = datetime.date(year - 40, 1, 1)),
        year = year,
        ).new_simulation(debug = True)
    assert max(abs(simulation.calculate('impo') - [0, -7889.20019531, -23435.52929688])) < .0001
    tax_benefit_system.apply_reform(reform = reform)
#    with open("/tmp/reform.json", "w") as f:
#        f.write(
#            json.dumps(
#                tax_benefit_system.legislation_json,
#                ensure_ascii = False,
#                encoding = "utf8",
#                indent = 2,
#                ).encode("utf8"))
    simulation2 = tax_benefit_system.new_scenario().init_single_entity(
        axes = [
            dict(
                count = 3,
                name = 'sali',
                max = 100000,
                min = 0,
                ),
            ],
        parent1 = dict(birth = datetime.date(year - 40, 1, 1)),
        year = year,
        ).new_simulation(debug = True)
    assert max(abs(simulation2.calculate('impo') - [0., -13900.20019531, -29446.52929688])) < .0001