|
33 | 33 |
|
34 | 34 | try:
|
35 | 35 | from matter_testing_support import (MatterBaseTest, MatterTestConfig, async_test_body, has_attribute,
|
36 |
| - has_cluster, has_feature, run_if_endpoint_matches, should_run_test_on_endpoint) |
| 36 | + has_cluster, has_feature, run_if_endpoint_matches, run_on_singleton_matching_endpoint, |
| 37 | + should_run_test_on_endpoint) |
37 | 38 | except ImportError:
|
38 | 39 | sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
39 | 40 | from matter_testing_support import (MatterBaseTest, MatterTestConfig, async_test_body, has_attribute,
|
40 |
| - has_cluster, has_feature, run_if_endpoint_matches, should_run_test_on_endpoint) |
| 41 | + has_cluster, has_feature, run_if_endpoint_matches, run_on_singleton_matching_endpoint, |
| 42 | + should_run_test_on_endpoint) |
41 | 43 |
|
42 | 44 | from typing import Optional
|
43 | 45 |
|
@@ -222,6 +224,18 @@ async def test_fail_on_ep1(self):
|
222 | 224 | if self.matter_test_config.endpoint == 1:
|
223 | 225 | asserts.fail("Expected failure")
|
224 | 226 |
|
| 227 | + @run_on_singleton_matching_endpoint(has_cluster(Clusters.OnOff)) |
| 228 | + async def test_run_on_singleton_matching_endpoint(self): |
| 229 | + pass |
| 230 | + |
| 231 | + @run_on_singleton_matching_endpoint(has_cluster(Clusters.OnOff)) |
| 232 | + async def test_run_on_singleton_matching_endpoint_failure(self): |
| 233 | + asserts.fail("Expected failure") |
| 234 | + |
| 235 | + @run_on_singleton_matching_endpoint(has_attribute(Clusters.OnOff.Attributes.OffWaitTime)) |
| 236 | + async def test_no_run_on_singleton_matching_endpoint(self): |
| 237 | + pass |
| 238 | + |
225 | 239 |
|
226 | 240 | def main():
|
227 | 241 | failures = []
|
@@ -308,6 +322,64 @@ def check_all_skipped(test_name: str):
|
308 | 322 | if ok:
|
309 | 323 | failures.append(f"Did not get expected test assertion on {test_name}")
|
310 | 324 |
|
| 325 | + def run_singleton_dynamic(test_name: str, cluster_list: list[int]) -> tuple[bool, DecoratorTestRunnerHooks]: |
| 326 | + nonlocal failures |
| 327 | + read_resp = get_clusters(cluster_list) |
| 328 | + test_runner.set_test('TestDecorators.py', 'TestDecorators', test_name) |
| 329 | + test_runner.set_test_config(MatterTestConfig(endpoint=2)) |
| 330 | + hooks = DecoratorTestRunnerHooks() |
| 331 | + ok = test_runner.run_test_with_mock_read(read_resp, hooks) |
| 332 | + # for all tests, we need to ensure the endpoint was set back to the prior values |
| 333 | + if test_runner.config.endpoint != 2: |
| 334 | + failures.append(f"Dynamic tests {test_name} with clusters {cluster_list} did not set endpoint back to prior") |
| 335 | + # All tests should have a start and a stop |
| 336 | + started_ok = len(hooks.started) == 1 |
| 337 | + stopped_ok = hooks.stopped == 1 |
| 338 | + if not started_ok or not stopped_ok: |
| 339 | + failures.append( |
| 340 | + f'Hooks failure on {test_name}, Runs: {hooks.started}, skips: {hooks.skipped} stops: {hooks.stopped}') |
| 341 | + return ok, hooks |
| 342 | + |
| 343 | + def expect_success_dynamic(test_name: str, cluster_list: list[int]): |
| 344 | + ok, hooks = run_singleton_dynamic(test_name, [0]) |
| 345 | + if not ok: |
| 346 | + failures.append(f"Unexpected failure on {test_name} with cluster list {cluster_list}") |
| 347 | + if hooks.skipped: |
| 348 | + failures.append(f'Unexpected skip call on {test_name} with cluster list {cluster_list}') |
| 349 | + |
| 350 | + def expect_failure_dynamic(test_name: str, cluster_list: list[int]): |
| 351 | + ok = run_singleton_dynamic(test_name, [0]) |
| 352 | + if ok: |
| 353 | + failures.append(f"Unexpected success on {test_name} with cluster list {cluster_list}") |
| 354 | + if hooks.skipped: |
| 355 | + # We don't expect a skip call because the test actually failed. |
| 356 | + failures.append(f'Skip called for {test_name} with cluster list {cluster_list}') |
| 357 | + |
| 358 | + def expect_skip_dynamic(test_name: str, cluster_list: list[int]): |
| 359 | + ok = run_singleton_dynamic(test_name, [0]) |
| 360 | + if not ok: |
| 361 | + failures.append(f"Unexpected failure on {test_name} with cluster list {cluster_list}") |
| 362 | + if not hooks.skipped: |
| 363 | + # We don't expect a skip call because the test actually failed. |
| 364 | + failures.append(f'Skip not called for {test_name} with cluster list {cluster_list}') |
| 365 | + |
| 366 | + test_name = 'test_run_on_singleton_matching_endpoint' |
| 367 | + expect_success_dynamic(test_name, [0]) |
| 368 | + expect_success_dynamic(test_name, [1]) |
| 369 | + # expect failure because there is more than 1 endpoint |
| 370 | + expect_failure_dynamic(test_name, [0, 1]) |
| 371 | + |
| 372 | + test_name = 'test_run_on_singleton_matching_endpoint_failure' |
| 373 | + expect_failure_dynamic(test_name, [0]) |
| 374 | + expect_failure_dynamic(test_name, [1]) |
| 375 | + expect_failure_dynamic(test_name, [0, 1]) |
| 376 | + |
| 377 | + test_name = 'test_no_run_on_singleton_matching_endpoint' |
| 378 | + # no failure, expect skips on single endpoints, expect asserts on multiple matching |
| 379 | + expect_skip_dynamic(test_name, [0]) |
| 380 | + expect_skip_dynamic(test_name, [1]) |
| 381 | + expect_failure_dynamic(test_name, [0, 1]) |
| 382 | + |
311 | 383 | test_runner.Shutdown()
|
312 | 384 | print(
|
313 | 385 | f"Test of Decorators: test response incorrect: {len(failures)}")
|
|
0 commit comments