Skip to content

Commit 881530c

Browse files
committed
address review comments
1 parent f0b46ca commit 881530c

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.github/workflows/tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ jobs:
588588
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestConformanceSupport.py'
589589
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_IDM_10_4.py'
590590
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_SC_7_1.py'
591+
scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/TestDecorators.py'
592+
591593
592594
- name: Uploading core files
593595
uses: actions/upload-artifact@v4

src/python_testing/matter_testing_support.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,7 @@ def per_endpoint_runner(self: MatterBaseTest, *args, **kwargs):
17621762
# Ditto for teardown - we want to tear down after each iteration, and we want to notify the hook that
17631763
# the test iteration is stopped. test_stop is called by on_pass or on_fail during the last iteration or
17641764
# on failure.
1765+
original_ep = self.matter_test_config.endpoint
17651766
for e in endpoints:
17661767
logging.info(f'Running test on endpoint {e}')
17671768
if e != endpoints[0]:
@@ -1772,7 +1773,7 @@ def per_endpoint_runner(self: MatterBaseTest, *args, **kwargs):
17721773
self.teardown_test()
17731774
test_duration = (datetime.now(timezone.utc) - self.test_start_time) / timedelta(microseconds=1)
17741775
self.runner_hook.test_stop(exception=None, duration=test_duration)
1775-
1776+
self.matter_test_config.endpoint = original_ep
17761777
return per_endpoint_runner
17771778
return per_endpoint_test_internal
17781779

src/python_testing/test_testing/TestDecorators.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ async def test_endpoints(self):
159159
async def test_whole_node_with_pics(self):
160160
pass
161161

162+
# This method returns the top level pics for test_whole_node_with_pics
163+
# It is used to test that test_whole_node_with_pics will fail since you can't have a whole node test gated on a PICS.
162164
def pics_whole_node_with_pics(self):
163165
return ['EXAMPLE.S']
164166

@@ -167,6 +169,8 @@ def pics_whole_node_with_pics(self):
167169
async def test_per_endpoint_with_pics(self):
168170
pass
169171

172+
# This method returns the top level pics for test_per_endpoint_with_pics
173+
# It is used to test that test_per_endpoint_with_pics will fail since you can't have a per endpoint test gated on a PICS.
170174
def pics_per_endpoint_with_pics(self):
171175
return ['EXAMPLE.S']
172176

@@ -210,7 +214,19 @@ async def test_endpoint_boolean_yes(self):
210214
async def test_endpoint_boolean_no(self):
211215
pass
212216

213-
# TODO: add test for assertions on whole node, and on each endpoint of an endpoint test
217+
@per_endpoint_test(has_cluster(Clusters.OnOff))
218+
async def test_fail_on_ep0(self):
219+
if self.matter_test_config.endpoint == 0:
220+
asserts.fail("Expected failure")
221+
222+
@per_endpoint_test(has_cluster(Clusters.OnOff))
223+
async def test_fail_on_ep1(self):
224+
if self.matter_test_config.endpoint == 1:
225+
asserts.fail("Expected failure")
226+
227+
@per_node_test
228+
async def test_fail_on_whole_node(self):
229+
asserts.fail("Expected failure")
214230

215231

216232
def main():
@@ -279,6 +295,34 @@ def check_skipped(test_name: str):
279295
check_once_per_endpoint('test_endpoint_boolean_yes')
280296
check_skipped('test_endpoint_boolean_no')
281297

298+
test_name = 'test_fail_on_ep0'
299+
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
300+
read_resp = get_clusters([0, 1])
301+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
302+
if ok:
303+
failures.append(f"Did not get expected test assertion on {test_name}")
304+
305+
test_name = 'test_fail_on_ep1'
306+
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
307+
read_resp = get_clusters([0, 1])
308+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
309+
if ok:
310+
failures.append(f"Did not get expected test assertion on {test_name}")
311+
312+
test_name = 'test_fail_on_ep1'
313+
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
314+
read_resp = get_clusters([0])
315+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
316+
if not ok:
317+
failures.append(f"Unexpected failure on {test_name}")
318+
319+
test_name = 'test_fail_on_whole_node'
320+
test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name)
321+
read_resp = get_clusters([0, 1])
322+
ok = test_runner.run_test_with_mock_read(read_resp, hooks)
323+
if ok:
324+
failures.append(f"Did not get expected test assertion on {test_name}")
325+
282326
test_runner.Shutdown()
283327
print(
284328
f"Test of Decorators: test response incorrect: {len(failures)}")

0 commit comments

Comments
 (0)