Skip to content

Commit

Permalink
Python testing hello example: Fix for TH expectations (#31688)
Browse files Browse the repository at this point in the history
The TH expects tests to appear in a certain way to be properly
picked up and parsed. Add instructions in the hello test and
change the example names to match the expectations.
  • Loading branch information
cecille authored and pull[bot] committed Feb 16, 2024
1 parent 2bcc1c7 commit b96ef14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/python_testing/hello_external_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def main():
app_process = subprocess.Popen([app_cmd], stdout=sys.stdout, stderr=sys.stderr, bufsize=0)

commission()
one_test('test_failure_on_wrong_endpoint')
one_test('test_names_as_expected')
one_test('test_pics')
one_test('test_TC_NAMES_2_1')
one_test('test_TC_ENDPOINT_2_1')
one_test('test_TC_PICSTEST_2_1')

app_process.send_signal(signal.SIGINT.value)
app_process.wait()
Expand Down
18 changes: 11 additions & 7 deletions src/python_testing/hello_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class HelloTest(MatterBaseTest):
# This example test does not include the step_ and desc_ markers
# The MatterBaseTest will assume a single step and create a description
# based on the test name
# To work in the Test harness, all tests should be named as
# TC_PICSCODE_#_#, (substituting the appropriate pics codes and numbers for the test)
@async_test_body
async def test_names_as_expected(self):
async def test_TC_NAMES_2_1(self):
dev_ctrl = self.default_controller
vendor_name = await self.read_single_attribute(
dev_ctrl,
Expand All @@ -44,17 +46,19 @@ async def test_names_as_expected(self):
# for the test, then use self.step(#) to indicate how the test proceeds through the test plan.
# Support for keeping the TH up to date is built into MatterBaseTest when you use the step()
# function.
def steps_failure_on_wrong_endpoint(self) -> list[TestStep]:
# If the device needs to be commissioned before running the test, ensure the first step in
# this function is marked is_commissioning=True.
def steps_TC_ENDPOINT_2_1(self) -> list[TestStep]:
steps = [TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(2, "Read ProductName on endpoint 9999"),
]
return steps

def desc_failure_on_wrong_endpoint(self) -> str:
def desc_TC_ENDPOINT_2_1(self) -> str:
return '#.#.#. [TC-HELLO-x.x] Test Failure On Wrong Endpoint'

@async_test_body
async def test_failure_on_wrong_endpoint(self):
async def test_TC_ENDPOINT_2_1(self):
self.step(1) # Commissioning

self.step(2)
Expand All @@ -68,19 +72,19 @@ async def test_failure_on_wrong_endpoint(self):
asserts.assert_true(isinstance(result, Clusters.Attribute.ValueDecodeFailure), "Should fail to read on endpoint 9999")
asserts.assert_equal(result.Reason.status, Status.UnsupportedEndpoint, "Failure reason should be UnsupportedEndpoint")

def steps_pics(self) -> list[TestStep]:
def steps_TC_PICSTEST_2_1(self) -> list[TestStep]:
steps = [TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(2, "Skip this step based on pics"),
TestStep(3, "Run this step"),
TestStep(4, "Always skip this step")
]
return steps

def desc_pics(self) -> str:
def desc_TC_PICSTEST_2_1(self) -> str:
return "#.#.#. [TC-HELLO-x.x] Test pics"

@async_test_body
async def test_pics(self):
async def test_TC_PICSTEST_2_1(self):
self.step(1) # commissioning
print('This should be run')

Expand Down

0 comments on commit b96ef14

Please sign in to comment.