Skip to content

Commit

Permalink
Add a force option for per endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Aug 6, 2024
1 parent 76939b0 commit db21ff8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,13 @@ async def get_accepted_endpoints_for_test(self: MatterBaseTest, accept_function:
Returns a list of endpoints on which the test should be run given the accept_function for the test.
"""
wildcard = await self.default_controller.Read(self.dut_node_id, [()])
return [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
matching = [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
forced_endpoint = self.user_params.get('force_endpoint', None)
if forced_endpoint is None:
return matching

asserts.assert_in(forced_endpoint, matching, "Force endpoint does not match test requirements")
return [forced_endpoint]


def run_for_each_matching_endpoint(accept_function: EndpointCheckFunction):
Expand Down
40 changes: 40 additions & 0 deletions src/python_testing/test_testing/TestDecorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def show_prompt(self,


class TestDecorators(MatterBaseTest):
def teardown_test(self):
if 'force_endpoint' in self.user_params.keys():
del self.user_params['force_endpoint']

def test_checkers(self):
has_onoff = has_cluster(Clusters.OnOff)
has_onoff_onoff = has_attribute(Clusters.OnOff.Attributes.OnOff)
Expand Down Expand Up @@ -153,7 +157,31 @@ async def test_endpoints(self):
endpoints = await get_accepted_endpoints_for_test(self, has_timesync_utc)
asserts.assert_equal(endpoints, [], msg)

@async_test_body
async def test_force_endpoint_good(self):
has_onoff = has_cluster(Clusters.OnOff)

all_endpoints = await self.default_controller.Read(self.dut_node_id, [()])
all_endpoints = list(all_endpoints.attributes.keys())

msg = "Unexpected endpoint list returned"

for e in all_endpoints:
self.user_params['force_endpoint'] = e
endpoints = await get_accepted_endpoints_for_test(self, has_onoff)
asserts.assert_equal(endpoints, [e], msg)

@async_test_body
async def test_force_endpoint_bad(self):
''' This test should cause an assertion because the forced endpoint does not match the requirements.'''
has_onoff = has_cluster(Clusters.OnOff)
all_endpoints = list(all_endpoints.attributes.keys())
forced = max(all_endpoints + 1)
self.user_params['force_endpoint'] = e
endpoints = await get_accepted_endpoints_for_test(self, has_onoff)

# This test should cause an assertion because it has pics_ method

@run_once_for_node
async def test_whole_node_with_pics(self):
pass
Expand Down Expand Up @@ -258,6 +286,18 @@ def main():
if not ok:
failures.append("Test case failure: test_endpoints")

test_runner.set_test('TestDecorators.py', 'TestDecorators', 'test_force_endpoint_good')
read_resp = get_clusters([0, 1])
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
if not ok:
failures.append("Test case failure: test_force_endpoint_good")

test_runner.set_test('TestDecorators.py', 'TestDecorators', 'test_force_endpoint_bad')
read_resp = get_clusters([0, 1])
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
if ok:
failures.append("Test case failure: test_force_endpoint_bad")

test_name = 'test_whole_node_with_pics'
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
Expand Down

0 comments on commit db21ff8

Please sign in to comment.