Skip to content

Commit a4b29b9

Browse files
Fixing issue from code review.
1 parent 13ee1e2 commit a4b29b9

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/python_testing/TC_MOD_1_2.py

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2023 Project CHIP Authors
2+
# Copyright (c) 2025 Project CHIP Authors
33
# All rights reserved.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,17 +38,17 @@
3838
import logging
3939

4040
import chip.clusters as Clusters
41-
from chip.clusters.Types import Nullable
4241
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
4342
from mobly import asserts
43+
from chip.clusters.Types import NullValue
4444

4545
logger = logging.getLogger(__name__)
4646

4747

4848
class MOD_1_2(MatterBaseTest):
4949
"""Proposal test for Mode Select Cluster attributes as a server."""
5050

51-
def TC_MOD_1_2(self) -> str:
51+
def desc_MOD_1_2(self) -> str:
5252
return "80.2.1. [TC-MOD-1.2] Cluster attributes with DUT as Server"
5353

5454
def pics_MOD_1_2(self):
@@ -91,26 +91,25 @@ def _verify_supported_mode(self, supported_mode):
9191
logger.info(
9292
"SupportedMode.semanticTags contains values, verifying attributes for manufacturedcode and value are not longer than 16bits int")
9393
for semantictag in supported_mode.semanticTags:
94-
asserts.assert_true(semantictag >= 0 and semantictag.mfgCode <= self._16bitshex,
94+
asserts.assert_true(semantictag.mfgCode >= 0 and semantictag.mfgCode <= self._16bitshex,
9595
"Element semantictag.Mfgcode is greater than 16 bits")
96-
asserts.assert_true(semantictag >= 0 and semantictag.value <= self._16bitshex,
96+
asserts.assert_true(semantictag.value >= 0 and semantictag.value <= self._16bitshex,
9797
"Element semantictag.Value is greater than 16 bits")
9898

9999
def _log_attribute(self, name, value):
100-
logger.info(f"{name} attribute {value} with type {type(value)}")
100+
logger.info(f"{name} attribute with value: {value} with type: {type(value)}")
101101

102102
@async_test_body
103103
async def test_MOD_1_2(self):
104104
self.cluster = Clusters.ModeSelect
105105
self.endpoint = self.get_endpoint(1)
106106
self._16bitshex = 0xFFFF
107-
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
108107

109-
# commision device
110-
# in the test plan step 1 is defined as a precondition.
108+
# Commision device
109+
# In the test plan step 1 is defined as a precondition.
111110
self.step(1)
112111

113-
# veirfy the Supported modes
112+
# Veirfy the Supported modes
114113
# Verify contains attributes label and mode
115114
# Verify if semantic tags has elements in list , and if there are values assert the values
116115
self.step(2)
@@ -122,9 +121,9 @@ async def test_MOD_1_2(self):
122121
for supported_mode in supported_modes:
123122
logger.info(
124123
f"Label {supported_mode} with type {type(supported_mode)} and {supported_mode.label} and {supported_mode.mode} and {supported_mode.semanticTags}")
125-
# verify the struct values
124+
# Verify the struct values
126125
self._verify_supported_mode(supported_mode=supported_mode)
127-
# after verifying the struct is correct append the mode value.
126+
# After verifying the struct is correct append the mode value.
128127
supported_modes_values.append(supported_mode.mode)
129128
logger.info(f"Supported modes values {supported_modes_values}")
130129

@@ -137,30 +136,31 @@ async def test_MOD_1_2(self):
137136

138137
self.step(4)
139138
on_mode = await self.read_single_attribute_check_success(endpoint=self.endpoint, cluster=self.cluster, attribute=self.cluster.Attributes.OnMode)
140-
# On mode can be null
139+
# On mode can be Nullvalue
141140
self._log_attribute("OnMode", on_mode)
142-
asserts.assert_true((isinstance(on_mode, int) or isinstance(on_mode, Nullable)),
143-
"Onmode is not int or is not clusters.Types.Nullable")
144-
# verify that OnMode is in the list of Supported Modes, but if null, cant be verified.
145-
if not isinstance(on_mode, Nullable):
146-
asserts.assert_in(on_mode, supported_modes_values, f"Onmode {current_mode} is not in {supported_modes_values}")
141+
asserts.assert_true((isinstance(on_mode, int) or on_mode is NullValue),
142+
"Onmode is not int or is not Nullvalue")
143+
# Verify that OnMode is in the list of Supported Modes, but if null, cant be verified.
144+
if on_mode is not NullValue:
145+
asserts.assert_in(on_mode, supported_modes_values, f"Onmode {on_mode} is not in {supported_modes_values}")
147146

148-
# Validate startup mode
147+
# Validate startup mode ( attribute Startup is optional)
149148
self.step(5)
150-
startup_mode = await self.read_single_attribute_check_success(endpoint=self.endpoint, cluster=self.cluster, attribute=self.cluster.Attributes.StartUpMode)
151-
self._log_attribute("StartupMode", startup_mode)
152-
asserts.assert_true(isinstance(startup_mode, int), "Startupmode is not int")
153-
asserts.assert_in(startup_mode, supported_modes_values, f"Startupmode {current_mode} is not in {supported_modes_values}")
154-
155-
# Verify the string for ci is larger that 1 char.
149+
if await self.attribute_guard(endpoint=self.endpoint, attribute=self.cluster.Attributes.StartUpMode):
150+
startup_mode = await self.read_single_attribute_check_success(endpoint=self.endpoint, cluster=self.cluster, attribute=self.cluster.Attributes.StartUpMode)
151+
self._log_attribute("StartupMode", startup_mode)
152+
asserts.assert_true(isinstance(startup_mode, int), "Startupmode is not int")
153+
asserts.assert_in(startup_mode, supported_modes_values,
154+
f"Startupmode {startup_mode} is not in {supported_modes_values}")
155+
156+
# Verify the string is str and larger that 1 char.
156157
# If is non ci ask the user if can read and understand the string.
157158
self.step(6)
158159
description = await self.read_single_attribute_check_success(endpoint=self.endpoint, cluster=self.cluster, attribute=self.cluster.Attributes.Description)
159160
self._log_attribute("Description", description)
160-
if self.is_ci:
161-
asserts.assert_true(isinstance(description, str), "Description attribute is not str")
162-
asserts.assert_true(len(description) >= 1, "Description is lower that 1 char.")
163-
else:
161+
asserts.assert_true(isinstance(description, str), "Description attribute is not str")
162+
asserts.assert_true(len(description) >= 1, "Description is lower that 1 char.")
163+
if not self.is_pics_sdk_ci_only:
164164
user_response = self.wait_for_user_input(prompt_msg=f"Is the value \"{description}\" for attribute Description a readable and understandable string? Enter 'y' or 'n'",
165165
prompt_msg_placeholder="y",
166166
default_value="y")
@@ -170,8 +170,8 @@ async def test_MOD_1_2(self):
170170
self.step(7)
171171
standard_namepace = await self.read_single_attribute_check_success(endpoint=self.endpoint, cluster=self.cluster, attribute=self.cluster.Attributes.StandardNamespace)
172172
self._log_attribute("StandardNamespace", standard_namepace)
173-
asserts.assert_true((isinstance(standard_namepace, Nullable) or (isinstance(standard_namepace, int) and (standard_namepace >= 0 and standard_namepace <= self._16bitshex))),
174-
"Standard namespace is not 16bit enum or not Nullable")
173+
asserts.assert_true((standard_namepace is NullValue or (isinstance(standard_namepace, int) and (standard_namepace >= 0 and standard_namepace <= self._16bitshex))),
174+
"Standard namespace is not 16bit enum or not Nullvalue")
175175

176176

177177
if __name__ == "__main__":

0 commit comments

Comments
 (0)