Skip to content

Commit ae4128f

Browse files
committed
[matter_yamltests] Allow response field to be configured from the config section
1 parent f5c4621 commit ae4128f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

scripts/py_matter_yamltests/matter_yamltests/parser.py

+5
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
222222
# a success with any associatied value(s). So the empty response is effectively
223223
# replace by an array that contains an empty object to represent that.
224224
responses = [{}]
225+
elif isinstance(responses, str):
226+
if config.get(responses):
227+
responses = config.get(responses)
228+
else:
229+
raise ValueError(responses)
225230
elif not isinstance(responses, list):
226231
# If a single response is specified, it is converted to a list of responses.
227232
responses = [responses]

scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __check_test_step(self, content):
101101
'verification': str,
102102
'PICS': str,
103103
'arguments': dict,
104-
'response': (dict, list),
104+
'response': (dict, list, str), # Can be a variable
105105
'minInterval': int,
106106
'maxInterval': int,
107107
'timedInteractionTimeoutMs': int,
@@ -124,7 +124,7 @@ def __check_test_step(self, content):
124124
response = content.get('response')
125125
if isinstance(response, list):
126126
[self.__check_test_step_response(x) for x in response]
127-
else:
127+
elif isinstance(response, dict):
128128
self.__check_test_step_response(response)
129129

130130
def __check_test_step_arguments(self, content):

scripts/py_matter_yamltests/test_yaml_loader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def test_key_tests_step_response_key(self):
301301
_, _, _, _, tests = load(content.format(value=value))
302302
self.assertEqual(tests, [{'response': [{'value': True}]}])
303303

304-
wrong_values = self._get_wrong_values([dict, list], spaces=6)
304+
wrong_values = self._get_wrong_values([dict, list, str], spaces=6)
305305
for value in wrong_values:
306306
x = content.format(value=value)
307307
self.assertRaises(TestStepInvalidTypeError, load, x)

0 commit comments

Comments
 (0)