Skip to content

Commit db21ff8

Browse files
committed
Add a force option for per endpoint tests
1 parent 76939b0 commit db21ff8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/python_testing/matter_testing_support.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,13 @@ async def get_accepted_endpoints_for_test(self: MatterBaseTest, accept_function:
18641864
Returns a list of endpoints on which the test should be run given the accept_function for the test.
18651865
"""
18661866
wildcard = await self.default_controller.Read(self.dut_node_id, [()])
1867-
return [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
1867+
matching = [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
1868+
forced_endpoint = self.user_params.get('force_endpoint', None)
1869+
if forced_endpoint is None:
1870+
return matching
1871+
1872+
asserts.assert_in(forced_endpoint, matching, "Force endpoint does not match test requirements")
1873+
return [forced_endpoint]
18681874

18691875

18701876
def run_for_each_matching_endpoint(accept_function: EndpointCheckFunction):

src/python_testing/test_testing/TestDecorators.py

+40
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def show_prompt(self,
105105

106106

107107
class TestDecorators(MatterBaseTest):
108+
def teardown_test(self):
109+
if 'force_endpoint' in self.user_params.keys():
110+
del self.user_params['force_endpoint']
111+
108112
def test_checkers(self):
109113
has_onoff = has_cluster(Clusters.OnOff)
110114
has_onoff_onoff = has_attribute(Clusters.OnOff.Attributes.OnOff)
@@ -153,7 +157,31 @@ async def test_endpoints(self):
153157
endpoints = await get_accepted_endpoints_for_test(self, has_timesync_utc)
154158
asserts.assert_equal(endpoints, [], msg)
155159

160+
@async_test_body
161+
async def test_force_endpoint_good(self):
162+
has_onoff = has_cluster(Clusters.OnOff)
163+
164+
all_endpoints = await self.default_controller.Read(self.dut_node_id, [()])
165+
all_endpoints = list(all_endpoints.attributes.keys())
166+
167+
msg = "Unexpected endpoint list returned"
168+
169+
for e in all_endpoints:
170+
self.user_params['force_endpoint'] = e
171+
endpoints = await get_accepted_endpoints_for_test(self, has_onoff)
172+
asserts.assert_equal(endpoints, [e], msg)
173+
174+
@async_test_body
175+
async def test_force_endpoint_bad(self):
176+
''' This test should cause an assertion because the forced endpoint does not match the requirements.'''
177+
has_onoff = has_cluster(Clusters.OnOff)
178+
all_endpoints = list(all_endpoints.attributes.keys())
179+
forced = max(all_endpoints + 1)
180+
self.user_params['force_endpoint'] = e
181+
endpoints = await get_accepted_endpoints_for_test(self, has_onoff)
182+
156183
# This test should cause an assertion because it has pics_ method
184+
157185
@run_once_for_node
158186
async def test_whole_node_with_pics(self):
159187
pass
@@ -258,6 +286,18 @@ def main():
258286
if not ok:
259287
failures.append("Test case failure: test_endpoints")
260288

289+
test_runner.set_test('TestDecorators.py', 'TestDecorators', 'test_force_endpoint_good')
290+
read_resp = get_clusters([0, 1])
291+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
292+
if not ok:
293+
failures.append("Test case failure: test_force_endpoint_good")
294+
295+
test_runner.set_test('TestDecorators.py', 'TestDecorators', 'test_force_endpoint_bad')
296+
read_resp = get_clusters([0, 1])
297+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
298+
if ok:
299+
failures.append("Test case failure: test_force_endpoint_bad")
300+
261301
test_name = 'test_whole_node_with_pics'
262302
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
263303
ok = test_runner.run_test_with_mock_read(read_resp, hooks)

0 commit comments

Comments
 (0)