Add guard against accepted and range definitions.

Minor reformat of error text on accepted value messages
pull/8673/head
kegilbert 2018-11-08 19:00:39 -06:00
parent a834794b53
commit b53738750f
5 changed files with 24 additions and 19 deletions

View File

@ -1072,15 +1072,20 @@ class Config(object):
accepted = param.accepted_values
value = param.value
if (value < min or (value > max if max is not None else False)):
err_msg += "\nInvalid config range for %s, is not in the required range: [%s:%s]"\
% (param,
min if min is not None else "-inf",
max if max is not None else "inf")
if (min is not None or max is not None) and (accepted is not None):
err_msg += "\n%s has both a range and list of accepted values specified. Please only "\
"specify either value_min and/or value_max, or accepted_values."\
% param
else:
if (value < min or (value > max if max is not None else False)):
err_msg += "\nInvalid config range for %s, is not in the required range: [%s:%s]"\
% (param,
min if min is not None else "-inf",
max if max is not None else "inf")
if accepted and value not in accepted:
err_msg += "\nInvalid config range for %s, is not an accepted value: %s"\
% (param, accepted)
if accepted and str(value) not in accepted:
err_msg += "\nInvalid config range for %s, is not an accepted value: %s"\
% (param, accepted)
if (err_msg):
raise ConfigException(err_msg)

View File

@ -4,7 +4,7 @@
"config1": {
"help": "The default value should pass as it is in the list of accepted values",
"value": 5,
"accepted_values": [0, 5, 10]
"accepted_values": "0, 5, 10"
},
"config2": {
"help": "The default value should pass as it is in the rage of accepted values",
@ -15,12 +15,7 @@
"config3": {
"help": "The default value should pass as it is in the rage of accepted values",
"value": "foo",
"accepted_values": ["foo", "bar"]
},
"config4": {
"help": "The default value should pass as it is in the rage of accepted values",
"value": false,
"accepted_values": [true, false]
"accepted_values": "foo, bar"
}
}
}

View File

@ -2,7 +2,6 @@
"test_target": {
"lib1.config1": 5,
"lib1.config2": 7,
"lib1.config3": "foo",
"lib1.config4": false
"lib1.config3": "foo"
}
}

View File

@ -4,7 +4,7 @@
"config1": {
"help": "The default value should fail as it is not in the rage of accepted values",
"value": 99,
"accepted_values": [0, 5, 10]
"accepted_values": "0, 5, 10"
},
"config2": {
"help": "The default value should fail as it is not in the rage of accepted values",
@ -21,6 +21,12 @@
"help": "The default value should fail as it is not in the rage of accepted values",
"value": 102,
"value_max": 101
},
"config5": {
"help": "The default value should fail as it specified both a range and list of accepted values",
"value": 103,
"value_max": 104,
"accepted_values": "103"
}
}
}

View File

@ -1,5 +1,5 @@
{
"test_target": {
"exception_msg": "\nInvalid config range for lib1.config1 = 99 (macro name: \"MBED_CONF_LIB1_CONFIG1\"), is not an accepted value: [0, 5, 10]\nInvalid config range for lib1.config2 = 100 (macro name: \"MBED_CONF_LIB1_CONFIG2\"), is not in the required range: [0:10]\nInvalid config range for lib1.config3 = 101 (macro name: \"MBED_CONF_LIB1_CONFIG3\"), is not in the required range: [102:inf]\nInvalid config range for lib1.config4 = 102 (macro name: \"MBED_CONF_LIB1_CONFIG4\"), is not in the required range: [-inf:101]"
"exception_msg": "\nInvalid config range for lib1.config1 = 99 (macro name: \"MBED_CONF_LIB1_CONFIG1\"), is not an accepted value: 0, 5, 10\nInvalid config range for lib1.config2 = 100 (macro name: \"MBED_CONF_LIB1_CONFIG2\"), is not in the required range: [0:10]\nInvalid config range for lib1.config3 = 101 (macro name: \"MBED_CONF_LIB1_CONFIG3\"), is not in the required range: [102:inf]\nInvalid config range for lib1.config4 = 102 (macro name: \"MBED_CONF_LIB1_CONFIG4\"), is not in the required range: [-inf:101]\nlib1.config5 = 103 (macro name: \"MBED_CONF_LIB1_CONFIG5\") has both a range and list of accepted values specified. Please only specify either value_min and/or value_max, or accepted_values."
}
}