Skip to content

Commit 1096528

Browse files
vivien-applepull[bot]
authored andcommitted
[matter_yamltests] Add wait keyword supports (#24592)
1 parent 5ebafb1 commit 1096528

File tree

1 file changed

+65
-8
lines changed
  • scripts/py_matter_yamltests/matter_yamltests

1 file changed

+65
-8
lines changed

scripts/py_matter_yamltests/matter_yamltests/parser.py

+65-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
import copy
17-
from enum import Enum
17+
from enum import Enum, auto
1818

1919
import yaml
2020

@@ -50,6 +50,7 @@
5050
'maxInterval',
5151
'timedInteractionTimeoutMs',
5252
'busyWaitMs',
53+
'wait',
5354
]
5455

5556
_TEST_ARGUMENTS_SECTION = [
@@ -91,11 +92,12 @@ class PostProcessCheckStatus(Enum):
9192

9293
class PostProcessCheckType(Enum):
9394
'''Indicates the post processing check step type.'''
94-
IM_STATUS = 'IMStatus',
95-
CLUSTER_STATUS = 'ClusterStatus',
96-
RESPONSE_VALIDATION = 'Response',
97-
CONSTRAINT_VALIDATION = 'Constraints',
98-
SAVE_AS_VARIABLE = 'SaveAs'
95+
IM_STATUS = auto()
96+
CLUSTER_STATUS = auto()
97+
RESPONSE_VALIDATION = auto()
98+
CONSTRAINT_VALIDATION = auto()
99+
SAVE_AS_VARIABLE = auto()
100+
WAIT_VALIDATION = auto()
99101

100102

101103
class PostProcessCheck:
@@ -213,9 +215,10 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
213215
self.timed_interaction_timeout_ms = _value_or_none(
214216
test, 'timedInteractionTimeoutMs')
215217
self.busy_wait_ms = _value_or_none(test, 'busyWaitMs')
218+
self.wait_for = _value_or_none(test, 'wait')
216219

217-
self.is_attribute = self.command in _ATTRIBUTE_COMMANDS
218-
self.is_event = self.command in _EVENT_COMMANDS
220+
self.is_attribute = self.command in _ATTRIBUTE_COMMANDS or self.wait_for in _ATTRIBUTE_COMMANDS
221+
self.is_event = self.command in _EVENT_COMMANDS or self.wait_for in _EVENT_COMMANDS
219222

220223
self.arguments_with_placeholders = _value_or_none(test, 'arguments')
221224
self.response_with_placeholders = _value_or_none(test, 'response')
@@ -472,9 +475,17 @@ def timed_interaction_timeout_ms(self):
472475
def busy_wait_ms(self):
473476
return self._test.busy_wait_ms
474477

478+
@property
479+
def wait_for(self):
480+
return self._test.wait_for
481+
475482
def post_process_response(self, response: dict):
476483
result = PostProcessResponseResult()
477484

485+
if self.wait_for is not None:
486+
self._response_cluster_wait_validation(response, result)
487+
return result
488+
478489
if self._skip_post_processing(response, result):
479490
return result
480491

@@ -487,6 +498,52 @@ def post_process_response(self, response: dict):
487498

488499
return result
489500

501+
def _response_cluster_wait_validation(self, response, result):
502+
"""Check if the response concrete path matches the configuration of the test step
503+
and validate that the response type (e.g readAttribute/writeAttribute/...) matches
504+
the expectation from the test step."""
505+
check_type = PostProcessCheckType.WAIT_VALIDATION
506+
error_success = 'The test expectation "{wait_for}" for "{cluster}.{wait_type}" on endpoint {endpoint} is true'
507+
error_failure = 'The test expectation "{expected} == {received}" is false'
508+
509+
if self.is_attribute:
510+
expected_wait_type = self.attribute
511+
received_wait_type = response.get('attribute')
512+
elif self.is_event:
513+
expected_wait_type = self.event
514+
received_wait_type = response.get('event')
515+
else:
516+
expected_wait_type = self.command
517+
received_wait_type = response.get('command')
518+
519+
expected_values = [
520+
self.wait_for,
521+
self.endpoint,
522+
# TODO The name in tests does not always use spaces
523+
self.cluster.replace(' ', ''),
524+
expected_wait_type
525+
]
526+
527+
received_values = [
528+
response.get('wait_for'),
529+
response.get('endpoint'),
530+
response.get('cluster'),
531+
received_wait_type
532+
]
533+
534+
success = True
535+
for expected_value in expected_values:
536+
received_value = received_values.pop(0)
537+
538+
if expected_value != received_value:
539+
result.error(check_type, error_failure.format(
540+
expected=expected_value, received=received_value))
541+
success = False
542+
543+
if success:
544+
result.success(check_type, error_success.format(
545+
wait_for=self.wait_for, cluster=self.cluster, wait_type=expected_wait_type, endpoint=self.endpoint))
546+
490547
def _skip_post_processing(self, response: dict, result) -> bool:
491548
'''Should we skip perform post processing.
492549

0 commit comments

Comments
 (0)