Skip to content

Commit b537387

Browse files
committed
Add guard against accepted and range definitions.
Minor reformat of error text on accepted value messages
1 parent a834794 commit b537387

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

tools/config/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,15 +1072,20 @@ def validate_config(self):
10721072
accepted = param.accepted_values
10731073
value = param.value
10741074

1075-
if (value < min or (value > max if max is not None else False)):
1076-
err_msg += "\nInvalid config range for %s, is not in the required range: [%s:%s]"\
1077-
% (param,
1078-
min if min is not None else "-inf",
1079-
max if max is not None else "inf")
1080-
1081-
if accepted and value not in accepted:
1082-
err_msg += "\nInvalid config range for %s, is not an accepted value: %s"\
1083-
% (param, accepted)
1075+
if (min is not None or max is not None) and (accepted is not None):
1076+
err_msg += "\n%s has both a range and list of accepted values specified. Please only "\
1077+
"specify either value_min and/or value_max, or accepted_values."\
1078+
% param
1079+
else:
1080+
if (value < min or (value > max if max is not None else False)):
1081+
err_msg += "\nInvalid config range for %s, is not in the required range: [%s:%s]"\
1082+
% (param,
1083+
min if min is not None else "-inf",
1084+
max if max is not None else "inf")
1085+
1086+
if accepted and str(value) not in accepted:
1087+
err_msg += "\nInvalid config range for %s, is not an accepted value: %s"\
1088+
% (param, accepted)
10841089

10851090
if (err_msg):
10861091
raise ConfigException(err_msg)

tools/test/config/range_limits/lib1/mbed_lib.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"config1": {
55
"help": "The default value should pass as it is in the list of accepted values",
66
"value": 5,
7-
"accepted_values": [0, 5, 10]
7+
"accepted_values": "0, 5, 10"
88
},
99
"config2": {
1010
"help": "The default value should pass as it is in the rage of accepted values",
@@ -15,12 +15,7 @@
1515
"config3": {
1616
"help": "The default value should pass as it is in the rage of accepted values",
1717
"value": "foo",
18-
"accepted_values": ["foo", "bar"]
19-
},
20-
"config4": {
21-
"help": "The default value should pass as it is in the rage of accepted values",
22-
"value": false,
23-
"accepted_values": [true, false]
18+
"accepted_values": "foo, bar"
2419
}
2520
}
2621
}

tools/test/config/range_limits/test_data.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"test_target": {
33
"lib1.config1": 5,
44
"lib1.config2": 7,
5-
"lib1.config3": "foo",
6-
"lib1.config4": false
5+
"lib1.config3": "foo"
76
}
87
}

tools/test/config/range_limits_invalid/lib1/mbed_lib.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"config1": {
55
"help": "The default value should fail as it is not in the rage of accepted values",
66
"value": 99,
7-
"accepted_values": [0, 5, 10]
7+
"accepted_values": "0, 5, 10"
88
},
99
"config2": {
1010
"help": "The default value should fail as it is not in the rage of accepted values",
@@ -21,6 +21,12 @@
2121
"help": "The default value should fail as it is not in the rage of accepted values",
2222
"value": 102,
2323
"value_max": 101
24+
},
25+
"config5": {
26+
"help": "The default value should fail as it specified both a range and list of accepted values",
27+
"value": 103,
28+
"value_max": 104,
29+
"accepted_values": "103"
2430
}
2531
}
2632
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"test_target": {
3-
"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]"
3+
"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."
44
}
55
}

0 commit comments

Comments
 (0)