Skip to content

Commit c77a534

Browse files
committed
Changed assertion types, remodified logs, rename variables
1 parent c48efc3 commit c77a534

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/python_testing/TC_LCFG_2_1.py

+26-22
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,8 +38,10 @@
3838

3939
import chip.clusters as Clusters
4040
import langcodes
41+
import random
4142
from chip.interaction_model import Status
4243
from chip.testing.matter_testing import MatterBaseTest, TestStep, default_matter_test_main, has_cluster, run_if_endpoint_matches
44+
from chip.testing.matter_asserts import assert_non_empty_string
4345
from mobly import asserts
4446

4547

@@ -50,11 +52,8 @@ def pics_TC_LCFG_2_1(self) -> list[str]:
5052
def has_repeated_values(self, list):
5153
return len(list) != len(set(list))
5254

53-
def list_has_maximum_length_of_35_bytes(self, list):
54-
return all(self.has_maximum_lenght_of_35_bytes(elem) for elem in list)
55-
56-
def has_maximum_lenght_of_35_bytes(self, str):
57-
return len(str.encode('utf-8')) <= 35
55+
def values_have_maximum_length(self, list, max_lenght):
56+
return all((len(elem.encode('utf-8')) <= max_lenght) for elem in list)
5857

5958
def supported_locales_has_active_locale(self, list, str):
6059
return str in list
@@ -74,30 +73,32 @@ async def test_TC_LCFG_2_1(self):
7473

7574
endpoint = self.get_endpoint(default=0)
7675
value_not_present_in_supported_locales = "fw-GB"
77-
es_ES = "es-ES"
76+
max_lenght_string = 35
77+
max_length_list = 32
7878

7979
# Step 0: Commissioning DUT (already done)
8080
self.step(0)
8181

8282
# Step 1: TH reads SupportedLocales attribute from DUT
8383
self.step(1)
8484

85-
initial_values_supported_locales = await self.read_single_attribute_check_success(
85+
initial_supported_locales = await self.read_single_attribute_check_success(
8686
cluster=Clusters.LocalizationConfiguration,
8787
attribute=Clusters.LocalizationConfiguration.Attributes.SupportedLocales,
8888
endpoint=endpoint
8989
)
9090

9191
# Verify values in SupportedLocales attribute are not repeated
92-
asserts.assert_false(self.has_repeated_values(initial_values_supported_locales),
93-
"SupportedLocales attribute has no repeated values")
92+
asserts.assert_false(self.has_repeated_values(initial_supported_locales),
93+
"SupportedLocales attribute should not have repeated values")
9494

9595
# Verify maximun number of elements in the SupportedLocales list is 32
96-
asserts.assert_true(len(initial_values_supported_locales) <= 32, "SupportedLocales attribute has less than 32 elements")
96+
asserts.assert_less_equal(len(initial_supported_locales), max_length_list,
97+
"SupportedLocales attribute should have less than " + str(max_length_list) + " elements")
9798

98-
# Verify values of SupportedLocales attribute has a maximum lenght of 35 bytes
99-
asserts.assert_true(self.list_has_maximum_length_of_35_bytes(initial_values_supported_locales),
100-
"SupportedLocales attribute has a maximum lenght of 35 bytes")
99+
# Verify values of SupportedLocales attribute have a maximum lenght of 35 bytes
100+
asserts.assert_true(self.values_have_maximum_length(initial_supported_locales, max_lenght_string),
101+
"Values of SupportedLocales attribute should have a maximum lenght of " + str(max_lenght_string) + " bytes")
101102

102103
# Step 2: TH reads ActiveLocale attribute from the DUT
103104
self.step(2)
@@ -109,19 +110,18 @@ async def test_TC_LCFG_2_1(self):
109110
)
110111

111112
# Verify that the ActiveLocale attribute is not empty
112-
asserts.assert_true(bool(initial_active_locale), "ActiveLocale attribute is not empty")
113+
assert_non_empty_string(initial_active_locale, "ActiveLocale attribute should not be empty")
113114

114115
# Verify that the ActiveLocale attribute is Language Tag as defined by BCP47
115-
asserts.assert_true(langcodes.tag_is_valid(initial_active_locale),
116-
"ActiveLocale attribute is Language Tag as defined by BCP47")
116+
assert langcodes.tag_is_valid(initial_active_locale), "ActiveLocale attribute should be Language Tag as defined by BCP47"
117117

118118
# Verify that the value of ActiveLocale attribute has maximum lenght of 35 bytes
119-
asserts.assert_true(self.has_maximum_lenght_of_35_bytes(initial_active_locale),
120-
"ActiveLocale attribute has less than 35 bytes")
119+
asserts.assert_less_equal(len(initial_active_locale), max_lenght_string,
120+
"ActiveLocale attribute should have less than " + str(max_lenght_string) + " bytes")
121121

122122
# Verify that the ActiveLocale attribute value is present in the SupportedLocales attribute list
123-
asserts.assert_true(self.supported_locales_has_active_locale(initial_values_supported_locales,
124-
initial_active_locale), "ActiveLocale attribute value is present in the SupportedLocales attribute list")
123+
asserts.assert_true(self.supported_locales_has_active_locale(initial_supported_locales,
124+
initial_active_locale), "ActiveLocale attribute value should be present in the SupportedLocales attribute list")
125125

126126
# Step 3: TH writes new string not present in SupportedLocales attribute to ActiveLocale attribute
127127
self.step(3)
@@ -134,7 +134,11 @@ async def test_TC_LCFG_2_1(self):
134134
# Step 4: TH writes new string present in SupportedLocales attribute to ActiveALocale attribute
135135
self.step(4)
136136

137-
value_present_in_supported_locales = initial_values_supported_locales[initial_values_supported_locales.index(es_ES)]
137+
filtered_supported_locales = [elem for elem in initial_supported_locales if elem != initial_active_locale]
138+
if filtered_supported_locales:
139+
value_present_in_supported_locales = random.choice(filtered_supported_locales)
140+
else:
141+
asserts.fail("SupportedLocales attribute has only one element and is the same value as ActiveLocale")
138142

139143
result = await self.write_single_attribute(attribute_value=Clusters.LocalizationConfiguration.Attributes.ActiveLocale(value_present_in_supported_locales), endpoint_id=endpoint, expect_success=True)
140144

0 commit comments

Comments
 (0)