# Path: openfisca_survey_manager/utils.py
# def inflate_parameters(parameters, inflator, base_year, last_year = None, ignore_missing_units = False):
# 
#     if (last_year is not None) and (last_year > base_year + 1):
#         for year in range(base_year + 1, last_year + 1):
#             inflate_parameters(parameters, inflator, year - 1, last_year = year, ignore_missing_units = ignore_missing_units)
# 
#     else:
#         if last_year is None:
#             last_year = base_year + 1
# 
#         assert last_year == base_year + 1
# 
#         for sub_parameter in parameters.children.values():
#             if isinstance(sub_parameter, ParameterNode):
#                 inflate_parameters(sub_parameter, inflator, base_year, last_year, ignore_missing_units = ignore_missing_units)
#             else:
#                 acceptable_units = [
#                     'rate_unit',
#                     'threshold_unit',
#                     'unit',
#                     ]
#                 if ignore_missing_units:
#                     if not hasattr(sub_parameter, 'metadata'):
#                         continue
#                     # Empty intersection: not unit present in metadata
#                     if not bool(set(sub_parameter.metadata.keys()) & set(acceptable_units)):
#                         continue
# 
#                 assert hasattr(sub_parameter, 'metadata'), "{} doesn't have metadata".format(sub_parameter.name)
#                 unit_types = set(sub_parameter.metadata.keys()).intersection(set(acceptable_units))
#                 assert unit_types, "No admissible unit in metadata for parameter {}. You may consider using the option 'ignore_missing_units' from the inflate_paramaters() function.".format(
#                     sub_parameter.name)
#                 if len(unit_types) > 1:
#                     assert unit_types == set(['threshold_unit', 'rate_unit']), \
#                         "Too much admissible units in metadata for parameter {}".format(
#                             sub_parameter.name)
#                 unit_by_type = dict([
#                     (unit_type, sub_parameter.metadata[unit_type]) for unit_type in unit_types
#                     ])
# 
#                 for unit_type in unit_by_type.keys():
#                     if sub_parameter.metadata[unit_type].startswith("currency"):
#                         inflate_parameter_leaf(sub_parameter, base_year, inflator, unit_type = unit_type)
# 
# def parameters_asof(parameters, instant):
#     if isinstance(instant, str):
#         instant = periods.instant(instant)
#     assert isinstance(instant, periods.Instant)
# 
#     for sub_parameter in parameters.children.values():
#         if isinstance(sub_parameter, ParameterNode):
#             parameters_asof(sub_parameter, instant)
#         else:
#             if isinstance(sub_parameter, Scale):
#                 for bracket in sub_parameter.brackets:
#                     threshold = bracket.children['threshold']
#                     rate = bracket.children.get('rate')
#                     amount = bracket.children.get('amount')
#                     leaf_asof(threshold, instant)
#                     if rate:
#                         leaf_asof(rate, instant)
#                     if amount:
#                         leaf_asof(amount, instant)
#             else:
#                 leaf_asof(sub_parameter, instant)


from openfisca_core import periods
from openfisca_country_template import CountryTaxBenefitSystem
from openfisca_survey_manager.utils import inflate_parameters, parameters_asof
    parameters = tax_benefit_system.parameters
    social_security_contribution_2016 = parameters.taxes.social_security_contribution(2016).thresholds[1]
    social_security_contribution_2017 = parameters.taxes.social_security_contribution(2017).thresholds[1]
    assert social_security_contribution_2016 != social_security_contribution_2017
    parameters_asof(parameters, instant = "2016")
    assert parameters.taxes.social_security_contribution(2016).thresholds[1] == social_security_contribution_2016
    assert parameters.taxes.social_security_contribution(2017).thresholds[1] == social_security_contribution_2016


def test_inflate_simple_parameter():
    """
        Test parameters inflator on a simple parameter as the basic income
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    basic_income_2016 = parameters.benefits.basic_income(2016)
    basic_income_2017 = parameters.benefits.basic_income(2017)
    assert basic_income_2017 == basic_income_2016
    inflate_parameters(parameters, inflator = .1, base_year = 2016, last_year = 2017)

    assert basic_income_2016 == parameters.benefits.basic_income(2016)
    assert 1.1 * basic_income_2016 == parameters.benefits.basic_income(2017)


def test_inflate_scale():
    """
        Test parameters inflator on a scale parameter as the social security contributions tax_scale
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters

# Path: openfisca_survey_manager/utils.py
# def inflate_parameters(parameters, inflator, base_year, last_year = None, ignore_missing_units = False):
# 
#     if (last_year is not None) and (last_year > base_year + 1):
#         for year in range(base_year + 1, last_year + 1):
#             inflate_parameters(parameters, inflator, year - 1, last_year = year, ignore_missing_units = ignore_missing_units)
# 
#     else:
#         if last_year is None:
#             last_year = base_year + 1
# 
#         assert last_year == base_year + 1
# 
#         for sub_parameter in parameters.children.values():
#             if isinstance(sub_parameter, ParameterNode):
#                 inflate_parameters(sub_parameter, inflator, base_year, last_year, ignore_missing_units = ignore_missing_units)
#             else:
#                 acceptable_units = [
#                     'rate_unit',
#                     'threshold_unit',
#                     'unit',
#                     ]
#                 if ignore_missing_units:
#                     if not hasattr(sub_parameter, 'metadata'):
#                         continue
#                     # Empty intersection: not unit present in metadata
#                     if not bool(set(sub_parameter.metadata.keys()) & set(acceptable_units)):
#                         continue
# 
#                 assert hasattr(sub_parameter, 'metadata'), "{} doesn't have metadata".format(sub_parameter.name)
#                 unit_types = set(sub_parameter.metadata.keys()).intersection(set(acceptable_units))
#                 assert unit_types, "No admissible unit in metadata for parameter {}. You may consider using the option 'ignore_missing_units' from the inflate_paramaters() function.".format(
#                     sub_parameter.name)
#                 if len(unit_types) > 1:
#                     assert unit_types == set(['threshold_unit', 'rate_unit']), \
#                         "Too much admissible units in metadata for parameter {}".format(
#                             sub_parameter.name)
#                 unit_by_type = dict([
#                     (unit_type, sub_parameter.metadata[unit_type]) for unit_type in unit_types
#                     ])
# 
#                 for unit_type in unit_by_type.keys():
#                     if sub_parameter.metadata[unit_type].startswith("currency"):
#                         inflate_parameter_leaf(sub_parameter, base_year, inflator, unit_type = unit_type)
# 
# def parameters_asof(parameters, instant):
#     if isinstance(instant, str):
#         instant = periods.instant(instant)
#     assert isinstance(instant, periods.Instant)
# 
#     for sub_parameter in parameters.children.values():
#         if isinstance(sub_parameter, ParameterNode):
#             parameters_asof(sub_parameter, instant)
#         else:
#             if isinstance(sub_parameter, Scale):
#                 for bracket in sub_parameter.brackets:
#                     threshold = bracket.children['threshold']
#                     rate = bracket.children.get('rate')
#                     amount = bracket.children.get('amount')
#                     leaf_asof(threshold, instant)
#                     if rate:
#                         leaf_asof(rate, instant)
#                     if amount:
#                         leaf_asof(amount, instant)
#             else:
#                 leaf_asof(sub_parameter, instant)


# Path: openfisca_survey_manager/tests/test_legislation_inflator.py
from openfisca_core import periods
from openfisca_country_template import CountryTaxBenefitSystem
from openfisca_survey_manager.utils import inflate_parameters, parameters_asof

    parameters = tax_benefit_system.parameters
    social_security_contribution_2016 = parameters.taxes.social_security_contribution(2016).thresholds[1]
    social_security_contribution_2017 = parameters.taxes.social_security_contribution(2017).thresholds[1]
    assert social_security_contribution_2016 != social_security_contribution_2017
    parameters_asof(parameters, instant = "2016")
    assert parameters.taxes.social_security_contribution(2016).thresholds[1] == social_security_contribution_2016
    assert parameters.taxes.social_security_contribution(2017).thresholds[1] == social_security_contribution_2016


def test_inflate_simple_parameter():
    """
        Test parameters inflator on a simple parameter as the basic income
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters
    basic_income_2016 = parameters.benefits.basic_income(2016)
    basic_income_2017 = parameters.benefits.basic_income(2017)
    assert basic_income_2017 == basic_income_2016
    inflate_parameters(parameters, inflator = .1, base_year = 2016, last_year = 2017)

    assert basic_income_2016 == parameters.benefits.basic_income(2016)
    assert 1.1 * basic_income_2016 == parameters.benefits.basic_income(2017)


def test_inflate_scale():
    """
        Test parameters inflator on a scale parameter as the social security contributions tax_scale
    """
    tax_benefit_system = CountryTaxBenefitSystem()
    parameters = tax_benefit_system.parameters

    inflate_parameters(parameters, inflator = .3, base_year = 2015, last_year = 2016)