当前位置: 首页>>代码示例>>Python>>正文


Python Policy._validate_values方法代码示例

本文整理汇总了Python中taxcalc.Policy._validate_values方法的典型用法代码示例。如果您正苦于以下问题:Python Policy._validate_values方法的具体用法?Python Policy._validate_values怎么用?Python Policy._validate_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在taxcalc.Policy的用法示例。


在下文中一共展示了Policy._validate_values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_valid_value_infomation

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import _validate_values [as 别名]
def test_valid_value_infomation():
    """
    Check consistency of valid_values info in policy_current_law.json file.
    """
    # pylint: disable=too-many-statements,too-many-locals
    # pylint: disable=too-many-branches,too-many-nested-blocks
    # construct set of parameter names with a "valid_values" field
    policy = Policy()
    min_max_list = ['min', 'max']
    warn_stop_list = ['warn', 'stop']
    json_range_params = set()
    parameters = set(policy._vals.keys())
    for pname, param in policy._vals.items():
        assert isinstance(param, dict)
        if param['value_type'] == 'string':
            continue  # because string parameters have no invalid_* keys
        prange = param.get('valid_values', None)
        if prange:
            json_range_params.add(pname)
            oor_action = param['invalid_action']
            assert oor_action in warn_stop_list
            range_items = prange.items()
            assert len(range_items) == 2
            for vop, vval in range_items:
                assert vop in min_max_list
                if isinstance(vval, str):
                    if vval == 'default':
                        if vop != 'min' or oor_action != 'warn':
                            msg = 'USES DEFAULT FOR min OR FOR error'
                            assert pname == msg
                        continue
                    else:
                        vval_ = '_' + vval
                        if vval_ in parameters:
                            if vop == 'min':
                                extra_msg = param['invalid_minmsg']
                            if vop == 'max':
                                extra_msg = param['invalid_maxmsg']
                            assert vval in extra_msg
                        else:
                            assert vval == 'ILLEGAL RANGE STRING VALUE'
                else:  # if vval is not a str
                    if isinstance(vval, int):
                        continue
                    elif isinstance(vval, float):
                        continue
                    elif isinstance(vval, bool):
                        continue
                    else:
                        assert vval == 'ILLEGAL RANGE NUMERIC VALUE'
    # compare contents of c_l_p.json parameters and json_range_params
    unmatched = parameters ^ json_range_params
    if unmatched:
        assert unmatched == 'UNMATCHED RANGE PARAMETERS'
    # check all current-law-policy parameters for range validity
    clp = Policy()
    clp._validate_values(parameters)
    # eventually activate: assert not clp.parameter_warnings
    ctc_c_warning = 'CTC_c was redefined in release 1.0.0\n'
    assert clp.parameter_warnings == ctc_c_warning
    assert not clp.parameter_errors
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:63,代码来源:test_policy.py


注:本文中的taxcalc.Policy._validate_values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。