Skip to content

Commit

Permalink
Allow groupId to be a variable in YAML tests. (#29641)
Browse files Browse the repository at this point in the history
This allows targeting group messages at a group id that's a config define.

Fixes #29637
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Apr 2, 2024
1 parent 332a97e commit 4346404
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ def __init__(self, test: _TestStepWithPlaceholders, step_index: int, runtime_con
self._test.event)
self._test.endpoint = self._config_variable_substitution(
self._test.endpoint)
self._test.group_id = self._config_variable_substitution(
self._test.group_id)
test.update_arguments(self.arguments)
test.update_responses(self.responses)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __check_test_step(self, config: dict, content):
'identity': str,
'nodeId': int,
'runIf': str, # Should be a variable.
'groupId': int,
'groupId': (int, str), # Can be a variable.
'endpoint': (int, str), # Can be a variable
'cluster': str,
'attribute': str,
Expand Down
18 changes: 17 additions & 1 deletion scripts/py_matter_yamltests/test_yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def test_key_tests_step_int_keys(self):
' - {key}: {value}')
keys = [
'nodeId',
'groupId',
'minInterval',
'maxInterval',
'timedInteractionTimeoutMs',
Expand Down Expand Up @@ -324,6 +323,23 @@ def test_key_tests_step_endpoint_number_key(self):
x = content.format(value=value)
self.assertRaises(TestStepInvalidTypeError, load, x)

def test_key_tests_step_group_id_key(self):
load = YamlLoader().load

content = ('tests:\n'
' - groupId: {value}')

_, _, _, _, tests = load(content.format(value=1))
self.assertEqual(tests, [{'groupId': 1}])

_, _, _, _, tests = load(content.format(value='TestKey'))
self.assertEqual(tests, [{'groupId': 'TestKey'}])

wrong_values = self._get_wrong_values([str, int], spaces=6)
for value in wrong_values:
x = content.format(value=value)
self.assertRaises(TestStepInvalidTypeError, load, x)

def test_key_tests_step_event_number_key(self):
load = YamlLoader().load

Expand Down
6 changes: 5 additions & 1 deletion src/app/tests/suites/TestGroupMessaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ config:
nodeId: 0x12344321
cluster: "Basic Information"
endpoint: 0
# Test that a group id can be a variable.
groupIdVariable:
type: int16u
defaultValue: 0x0101
nodeId2:
type: node_id
defaultValue: 0x43211234
Expand Down Expand Up @@ -215,7 +219,7 @@ tests:
- label: "Turn On the light to see attribute change"
cluster: "On/Off"
command: "On"
groupId: 0x0101
groupId: groupIdVariable # 0x0101

# Give the group invoke time to actually happen; unicast delivery can outrace
# multicast if the unicast packet is sent immediately after the multicast one.
Expand Down

0 comments on commit 4346404

Please sign in to comment.