Skip to content

Commit 9469436

Browse files
vivien-applebzbarsky-apple
authored andcommitted
[matter_yamltests] Add an implicit rule that the key 'value' in argum… (#28068)
* [matter_yamltests] Add an implicit rule that the key 'value' in arguments can not be used if the command is not a 'writeAttribute' * Update scripts/py_matter_yamltests/matter_yamltests/errors.py --------- Co-authored-by: Boris Zbarsky <[email protected]>
1 parent 3e39324 commit 9469436

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

scripts/py_matter_yamltests/matter_yamltests/errors.py

+12
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,15 @@ def __init__(self, content):
198198
super().__init__(message)
199199

200200
self.tag_key_with_error(content, 'response')
201+
202+
203+
class TestStepArgumentsValueError(TestStepError):
204+
"""Raise when a test step arguments use the 'value' keyword but the command is not trying to write to an attribute"""
205+
206+
def __init__(self, content):
207+
message = 'The "value" key can not be used in conjuction with a command that is not "writeAttribute"'
208+
super().__init__(message)
209+
210+
self.tag_key_with_error(content, 'command')
211+
arguments = content.get('arguments')
212+
self.tag_key_with_error(arguments, 'value')

scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
from typing import Tuple, Union
1717

18-
from .errors import (TestStepError, TestStepGroupEndPointError, TestStepGroupResponseError, TestStepInvalidTypeError,
19-
TestStepKeyError, TestStepNodeIdAndGroupIdError, TestStepResponseVariableError, TestStepValueAndValuesError,
20-
TestStepVerificationStandaloneError, TestStepWaitResponseError)
18+
from .errors import (TestStepArgumentsValueError, TestStepError, TestStepGroupEndPointError, TestStepGroupResponseError,
19+
TestStepInvalidTypeError, TestStepKeyError, TestStepNodeIdAndGroupIdError, TestStepResponseVariableError,
20+
TestStepValueAndValuesError, TestStepVerificationStandaloneError, TestStepWaitResponseError)
2121
from .fixes import add_yaml_support_for_scientific_notation_without_dot
2222

2323
try:
@@ -120,6 +120,7 @@ def __check_test_step(self, config: dict, content):
120120
content)
121121
self.__rule_wait_should_not_expect_a_response(content)
122122
self.__rule_response_variable_should_exist_in_config(config, content)
123+
self.__rule_argument_value_is_only_when_writing_attributes(content)
123124

124125
if 'arguments' in content:
125126
arguments = content.get('arguments')
@@ -260,3 +261,10 @@ def __rule_response_variable_should_exist_in_config(self, config, content):
260261
response = content.get('response')
261262
if isinstance(response, str) and response not in config:
262263
raise TestStepResponseVariableError(content)
264+
265+
def __rule_argument_value_is_only_when_writing_attributes(self, content):
266+
if 'arguments' in content:
267+
command = content.get('command')
268+
arguments = content.get('arguments')
269+
if 'value' in arguments and command != 'writeAttribute':
270+
raise TestStepArgumentsValueError(content)

scripts/py_matter_yamltests/test_yaml_loader.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ def test_key_tests_step_dict_keys(self):
267267
load = YamlLoader().load
268268

269269
content = ('tests:\n'
270-
' - {key}: {value}')
270+
' - command: writeAttribute\n'
271+
' {key}: {value}')
271272
keys = [
272273
'arguments',
273274
]
@@ -278,7 +279,8 @@ def test_key_tests_step_dict_keys(self):
278279
for key in keys:
279280
_, _, _, _, tests = load(
280281
content.format(key=key, value=valid_value))
281-
self.assertEqual(tests, [{key: {'value': True}}])
282+
self.assertEqual(
283+
tests, [{'command': 'writeAttribute', key: {'value': True}}])
282284

283285
for value in wrong_values:
284286
x = content.format(key=key, value=value)

0 commit comments

Comments
 (0)