Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/per_node_endpoint_fixes' into pe…
Browse files Browse the repository at this point in the history
…r_node_endpoint_fixes
  • Loading branch information
cecille committed Sep 3, 2024
2 parents c01bb23 + c7851b6 commit f5b5c09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/python_testing/TC_TIMESYNC_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

import chip.clusters as Clusters
from chip.clusters.Types import NullValue
from matter_testing_support import (MatterBaseTest, default_matter_test_main, has_attribute, has_cluster,
run_if_endpoint_matches, utc_time_in_matter_epoch)
from matter_testing_support import (MatterBaseTest, default_matter_test_main, has_attribute, has_cluster, run_if_endpoint_matches,
utc_time_in_matter_epoch)
from mobly import asserts


Expand Down
2 changes: 1 addition & 1 deletion src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ def matching_runner(self: MatterBaseTest, *args, **kwargs):


def run_if_endpoint_matches(accept_function: EndpointCheckFunction):
""" Test decorator for a test that needs to be run only if the endpoint that meets the accept_function criteria.
""" Test decorator for a test that needs to be run only if the endpoint meets the accept_function criteria.
Place this decorator above the test_ method to have the test framework run this test only if the endpoint matches.
This decorator takes an EndpointCheckFunction to assess whether a test needs to be run on a particular
Expand Down
20 changes: 8 additions & 12 deletions src/python_testing/test_testing/TestDecorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
from chip.clusters import Attribute

try:
from matter_testing_support import (MatterBaseTest, MatterTestConfig, async_test_body, has_attribute,
has_cluster, has_feature, run_if_endpoint_matches, run_on_singleton_matching_endpoint,
should_run_test_on_endpoint)
from matter_testing_support import (MatterBaseTest, MatterTestConfig, async_test_body, has_attribute, has_cluster, has_feature,
run_if_endpoint_matches, run_on_singleton_matching_endpoint, should_run_test_on_endpoint)
except ImportError:
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from matter_testing_support import (MatterBaseTest, MatterTestConfig, async_test_body, has_attribute,
Expand Down Expand Up @@ -107,9 +106,6 @@ def show_prompt(self,


class TestDecorators(MatterBaseTest):
def teardown_test(self):
self.matter_test_config.endpoint = None

def test_checkers(self):
has_onoff = has_cluster(Clusters.OnOff)
has_onoff_onoff = has_attribute(Clusters.OnOff.Attributes.OnOff)
Expand Down Expand Up @@ -278,7 +274,7 @@ def run_check(test_name: str, read_response: Attribute.AsyncReadTransaction.Read
stopped_ok = hooks.stopped == num_endpoints
if not ok or not started_ok or not skipped_ok or not stopped_ok:
failures.append(
f'Expected {expected_runs} run of {test_name}, skips expected: {expect_skip}. Runs: {hooks.started}, skips: {hooks.skipped} stops: {hooks.stopped}')
f'Expected {num_endpoints} run of {test_name}, skips expected: {expect_skip}. Runs: {hooks.started}, skips: {hooks.skipped} stops: {hooks.stopped}')

def check_once_per_endpoint(test_name: str):
run_check(test_name, get_clusters([0, 1]), False)
Expand Down Expand Up @@ -341,22 +337,22 @@ def run_singleton_dynamic(test_name: str, cluster_list: list[int]) -> tuple[bool
return ok, hooks

def expect_success_dynamic(test_name: str, cluster_list: list[int]):
ok, hooks = run_singleton_dynamic(test_name, [0])
ok, hooks = run_singleton_dynamic(test_name, cluster_list)
if not ok:
failures.append(f"Unexpected failure on {test_name} with cluster list {cluster_list}")
if hooks.skipped:
failures.append(f'Unexpected skip call on {test_name} with cluster list {cluster_list}')

def expect_failure_dynamic(test_name: str, cluster_list: list[int]):
ok = run_singleton_dynamic(test_name, [0])
ok, hooks = run_singleton_dynamic(test_name, cluster_list)
if ok:
failures.append(f"Unexpected success on {test_name} with cluster list {cluster_list}")
if hooks.skipped:
# We don't expect a skip call because the test actually failed.
failures.append(f'Skip called for {test_name} with cluster list {cluster_list}')

def expect_skip_dynamic(test_name: str, cluster_list: list[int]):
ok = run_singleton_dynamic(test_name, [0])
ok, hooks = run_singleton_dynamic(test_name, cluster_list)
if not ok:
failures.append(f"Unexpected failure on {test_name} with cluster list {cluster_list}")
if not hooks.skipped:
Expand All @@ -375,10 +371,10 @@ def expect_skip_dynamic(test_name: str, cluster_list: list[int]):
expect_failure_dynamic(test_name, [0, 1])

test_name = 'test_no_run_on_singleton_matching_endpoint'
# no failure, expect skips on single endpoints, expect asserts on multiple matching
# no failure, no matches, expect skips on all endpoints
expect_skip_dynamic(test_name, [0])
expect_skip_dynamic(test_name, [1])
expect_failure_dynamic(test_name, [0, 1])
expect_skip_dynamic(test_name, [0, 1])

test_runner.Shutdown()
print(
Expand Down

0 comments on commit f5b5c09

Please sign in to comment.