Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TC-WASHERCTRL-2.1 Python migration #36720

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions src/python_testing/TC_WASHERCTRL_2_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#
# Copyright (c) 2024 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments
# for details about the block below.
#
# === BEGIN CI TEST ARGUMENTS ===
# test-runner-runs:
# run1:
# app: ${ALL_CLUSTERS_APP}
# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
# script-args: >
# --storage-path admin_storage.json
# --commissioning-method on-network
# --discriminator 1234
# --passcode 20202021
# --PICS src/app/tests/suites/certification/ci-pics-values
# --trace-to json:${TRACE_TEST_JSON}.json
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# factory-reset: true
# quiet: true
# === END CI TEST ARGUMENTS ===

import logging
import random

import chip.clusters as Clusters
from chip.interaction_model import Status
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
from mobly import asserts

logger = logging.getLogger(__name__)


MAX_SPIN_SPEEDS = 16


class TC_WASHERCTRL_2_1(MatterBaseTest):

def desc_TC_WASHERCTRL_2_1(self) -> str:
"""Returns a description of this test"""
return "[TC-WASHERCTRL-2.1] Optional Spin attributes with DUT as Server"

def pics_TC_WASHERCTRL_2_1(self) -> list[str]:
pics = [
"WASHERCTRL.S.F00",
]
return pics

def steps_TC_WASHERCTRL_2_1(self) -> list[TestStep]:
steps = [
TestStep(1, "Commissioning, already done",
is_commissioning=True),
TestStep(2, "TH reads from the DUT the SpinSpeeds attribute"),
TestStep(3, "TH reads from the DUT the SpinSpeedCurrent attribute"),
TestStep(4, "TH writes a supported SpinSpeedCurrent attribute that is a valid index into the list"
+ "of spin speeds (0 to numSpinSpeeds - 1)"),
TestStep(5, "After a few seconds, TH reads from the DUT the SpinSpeedCurrent attribute"),
TestStep(6, "TH writes an unsupported SpinSpeedCurrent attribute that is other than 0 to DUT")
]

return steps

@async_test_body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment here - would want to do the same thing in this PR, assuming the lined PR lands before this gets undrafted. #36703 (comment)

async def test_TC_WASHERCTRL_2_1(self):

endpoint = self.get_endpoint(default=1)

self.step(1)

# Read the SpinSpeeds attributes
self.step(2)
list_speed_speeds = await self.read_single_attribute_check_success(endpoint=endpoint,
cluster=Clusters.Objects.LaundryWasherControls,
attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeeds)

asserts.assert_true(isinstance(list_speed_speeds, list), "Returned value was not a list")
numSpinSpeeds = len(list_speed_speeds)
asserts.assert_less_equal(numSpinSpeeds, MAX_SPIN_SPEEDS, "List of SpinSpeeds larger than maximum allowed")

# Read the SpinSpeedCurrent attribute
self.step(3)
spin_speed_current = await self.read_single_attribute_check_success(endpoint=endpoint,
cluster=Clusters.Objects.LaundryWasherControls,
attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent)
asserts.assert_true(isinstance(spin_speed_current, int), "SpinSpeedCurrent has an invalid value")
asserts.assert_true(0 <= spin_speed_current <= (numSpinSpeeds - 1), "SpinSpeedCurrent outside valid range")

# Write a valid SpinSpeedCurrent value
self.step(4)
requested_speed = random.randint(0, numSpinSpeeds - 1)
result = await self.default_controller.WriteAttribute(self.dut_node_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest using write_single_attribute function - it checks the return status for you and has some nice defaults for node and controller.

https://github.com/project-chip/connectedhomeip/blob/master/src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py#L1244

and below

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I was aware of the read_single_attribute function but didn't knew about this one.

I changed both uses of the WriteAttribute function with the new one.

[(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(requested_speed))])
asserts.assert_equal(result[0].Status, Status.Success, "Failed to write SpinSpeed value")

# Read SpinSpeedCurrent value and verify that was changed.
self.step(5)
current_value = await self.read_single_attribute_check_success(endpoint=endpoint,
cluster=Clusters.Objects.LaundryWasherControls,
attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent)
asserts.assert_equal(current_value, requested_speed, "Value obtained different than the previously written one")

# Try to write an invalid value (outside supported range)
self.step(6)
result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(numSpinSpeeds))])
asserts.assert_equal(result[0].Status, Status.ConstraintError,
"Trying to write an invalid value should return ConstraintError")


if __name__ == "__main__":
default_matter_test_main()
Loading