Exemplo n.º 1
0
def xml_to_julia(tax_benefit_system, tree):
    xml_json = check(decompositionsxml.xml_decomposition_to_json)(
        tree.getroot())
    xml_json = check(
        decompositionsxml.make_validate_node_xml_json(tax_benefit_system))(
            xml_json)
    julia_list_tree = transform_node_xml_json_to_julia_list_tree(xml_json)
    julia_source_code = transform_julia_list_tree_to_julia_source_code(
        julia_list_tree)
    return julia_source_code
Exemplo n.º 2
0
def test_jsons():
    for json_file_name in os.listdir(json_dir_path):
        with open(os.path.join(json_dir_path, json_file_name)) as json_file:
            content = json.load(json_file)
        scenario_json = content['scenario']
        scenario = check(
            tax_benefit_system.Scenario.make_json_to_instance(
                tax_benefit_system=tax_benefit_system))(scenario_json)
        if 'year' in scenario_json:
            year = scenario_json['year']
        else:
            date = datetime.datetime.strptime(scenario_json['date'],
                                              "%Y-%m-%d")
            year = date.year
        totpac = scenario.test_case['foyers_fiscaux'].values()[0].get(
            'personnes_a_charge')
        for code, field in content['resultat_officiel'].iteritems():
            yield check_variable, {
                'code': code,
                'field': field,
                'json_file_name': json_file_name,
                'scenario': scenario,
                'totpac': totpac,
                'year': year,
            }
def json_with_test_case_to_input_variables(scenario_or_simulation_json):
    country_package = importlib.import_module(args.country_package_name)
    TaxBenefitSystem = country_package.init_country()
    tax_benefit_system = TaxBenefitSystem()
    new_scenario_or_simulation_json = copy.deepcopy(scenario_or_simulation_json)
    new_scenarios_json = new_scenario_or_simulation_json['scenarios'] \
        if 'scenarios' in new_scenario_or_simulation_json \
        else [new_scenario_or_simulation_json]
    assert all('test_case' in scenario_json for scenario_json in new_scenarios_json), \
        'All the scenarios must have a test case.'
    for new_scenario_json in new_scenarios_json:
        scenario = check(tax_benefit_system.Scenario.make_json_to_instance(
            repair = True,
            tax_benefit_system = tax_benefit_system,
            ))(new_scenario_json)
        scenario.suggest()
        simulation = scenario.new_simulation(use_set_input_hooks = False)
        input_variables_json = simulation.to_input_variables_json()
        del new_scenario_json['test_case']
        new_scenario_json['input_variables'] = input_variables_json
    return new_scenario_or_simulation_json
def test_jsons():
    for json_file_name in os.listdir(json_dir_path):
        with open(os.path.join(json_dir_path, json_file_name)) as json_file:
            content = json.load(json_file)
        scenario_json = content['scenario']
        scenario = check(tax_benefit_system.Scenario.make_json_to_instance(tax_benefit_system = tax_benefit_system))(
            scenario_json)
        if 'year' in scenario_json:
            year = scenario_json['year']
        else:
            date = datetime.datetime.strptime(scenario_json['date'], "%Y-%m-%d")
            year = date.year
        totpac = scenario.test_case['foyers_fiscaux'].values()[0].get('personnes_a_charge')
        for code, field in content['resultat_officiel'].iteritems():
            yield check_variable, {
                'code': code,
                'field': field,
                'json_file_name': json_file_name,
                'scenario': scenario,
                'totpac': totpac,
                'year': year,
                }
def json_with_test_case_to_input_variables(scenario_or_simulation_json):
    country_package = importlib.import_module(args.country_package_name)
    tax_benefit_system = country_package.init_tax_benefit_system()
    new_scenario_or_simulation_json = copy.deepcopy(
        scenario_or_simulation_json)
    new_scenarios_json = new_scenario_or_simulation_json['scenarios'] \
        if 'scenarios' in new_scenario_or_simulation_json \
        else [new_scenario_or_simulation_json]
    assert all('test_case' in scenario_json for scenario_json in new_scenarios_json), \
        'All the scenarios must have a test case.'
    for new_scenario_json in new_scenarios_json:
        scenario = check(
            tax_benefit_system.Scenario.make_json_to_instance(
                repair=True,
                tax_benefit_system=tax_benefit_system,
            ))(new_scenario_json)
        scenario.suggest()
        simulation = scenario.new_simulation(use_set_input_hooks=False)
        input_variables_json = simulation.to_input_variables_json()
        del new_scenario_json['test_case']
        new_scenario_json['input_variables'] = input_variables_json
    return new_scenario_or_simulation_json
def xml_to_julia(tax_benefit_system, tree):
    xml_json = check(decompositionsxml.xml_decomposition_to_json)(tree.getroot())
    xml_json = check(decompositionsxml.make_validate_node_xml_json(tax_benefit_system))(xml_json)
    julia_list_tree = transform_node_xml_json_to_julia_list_tree(xml_json)
    julia_source_code = transform_julia_list_tree_to_julia_source_code(julia_list_tree)
    return julia_source_code