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