Skip to content

Commit a2725b9

Browse files
committed
Add documentation to decorators and helpers
1 parent 2d5d300 commit a2725b9

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

src/python_testing/matter_testing_support.py

+76-3
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,6 @@ def async_runner(self: MatterBaseTest, *args, **kwargs):
15661566
return async_runner
15671567

15681568
def per_node_test(body):
1569-
15701569
""" Decorator to be used for PICS-free tests that apply to the entire node.
15711570
15721571
Use this decorator when your script needs to be run once to validate the whole node.
@@ -1587,6 +1586,26 @@ def _has_cluster(wildcard, endpoint, cluster: ClusterObjects.Cluster) -> bool:
15871586
return False
15881587

15891588
def has_cluster(cluster: ClusterObjects.ClusterObjectDescriptor) -> EndpointCheckFunction:
1589+
""" EndpointCheckFunction that can be passed as a parameter to the per_endpoint_test decorator.
1590+
1591+
Use this function with the per_endpoint_test decorator to run this test on all endpoints with
1592+
the specified cluster. For example, given a device with the following conformance
1593+
1594+
EP0: cluster A, B, C
1595+
EP1: cluster D, E
1596+
EP2, cluster D
1597+
EP3, cluster E
1598+
1599+
And the following test specification:
1600+
@per_endpoint_test(has_cluster(Clusters.D))
1601+
test_mytest(self):
1602+
...
1603+
1604+
The test would be run on endpoint 1 and on endpoint 2.
1605+
1606+
If the cluster is not found on any endpoint the decorator will call the on_skip function to
1607+
notify the test harness that the test is not applicable to this node and the test will not be run.
1608+
"""
15901609
return partial(_has_cluster, cluster=cluster)
15911610

15921611
def _has_attribute(wildcard, endpoint, attribute: ClusterObjects.ClusterAttributeDescriptor) -> bool:
@@ -1598,13 +1617,67 @@ def _has_attribute(wildcard, endpoint, attribute: ClusterObjects.ClusterAttribut
15981617
return False
15991618

16001619
def has_attribute(attribute: ClusterObjects.ClusterAttributeDescriptor) -> EndpointCheckFunction:
1620+
""" EndpointCheckFunction that can be passed as a parameter to the per_endpoint_test decorator.
1621+
1622+
Use this function with the per_endpoint_test decorator to run this test on all endpoints with
1623+
the specified attribute. For example, given a device with the following conformance
1624+
1625+
EP0: cluster A, B, C
1626+
EP1: cluster D with attribute d, E
1627+
EP2, cluster D with attribute d
1628+
EP3, cluster D without attribute d
1629+
1630+
And the following test specification:
1631+
@per_endpoint_test(has_attribute(Clusters.D.Attributes.d))
1632+
test_mytest(self):
1633+
...
1634+
1635+
The test would be run on endpoint 1 and on endpoint 2.
1636+
1637+
If the cluster is not found on any endpoint the decorator will call the on_skip function to
1638+
notify the test harness that the test is not applicable to this node and the test will not be run.
1639+
"""
16011640
return partial(_has_attribute, attribute=attribute)
16021641

1603-
async def get_accepted_endpoints_for_test(self:MatterBaseTest, accept_function: EndpointCheckFunction):
1642+
async def get_accepted_endpoints_for_test(self:MatterBaseTest, accept_function: EndpointCheckFunction) -> list[uint]:
1643+
""" Helper function for the per_endpoint_test decorator.
1644+
1645+
Returns a list of endpoints on which the test should be run given the accept_function for the test.
1646+
"""
16041647
wildcard = await self.default_controller.Read(self.dut_node_id, [()])
16051648
return [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
16061649

1607-
def per_endpoint_test(accept_function):
1650+
def per_endpoint_test(accept_function: EndpointCheckFunction):
1651+
""" Test decorator for a test that needs to be run once per endpoint that meets the accept_function criteria.
1652+
1653+
Place this decorator above the test_ method to have the test framework run this test once per endpoint.
1654+
This decorator takes an EndpointCheckFunction to assess whether a test needs to be run on a particular
1655+
endpoint.
1656+
1657+
For example, given the following device conformance:
1658+
1659+
EP0: cluster A, B, C
1660+
EP1: cluster D, E
1661+
EP2, cluster D
1662+
EP3, cluster E
1663+
1664+
And the following test specification:
1665+
@per_endpoint_test(has_cluster(Clusters.D))
1666+
test_mytest(self):
1667+
...
1668+
1669+
The test would be run on endpoint 1 and on endpoint 2.
1670+
1671+
If the cluster is not found on any endpoint the decorator will call the on_skip function to
1672+
notify the test harness that the test is not applicable to this node and the test will not be run.
1673+
1674+
The decorator works by setting the self.matter_test_config.endpoint value and running the test function.
1675+
Therefore, tests that make use of this decorator should call controller functions against that endpoint.
1676+
Support functions in this file default to this endpoint.
1677+
1678+
Tests that use this decorator cannot use a pics_ method for test selection and should not reference any
1679+
PICS values internally.
1680+
"""
16081681
def per_endpoint_test_internal(body):
16091682
def per_endpoint_runner(self: MatterBaseTest, *args, **kwargs):
16101683
asserts.assert_false(self.get_test_pics(self.current_test_info.name), "pics_ method supplied for per_endpoint_test.")

0 commit comments

Comments
 (0)