Skip to content

Commit b2b6275

Browse files
authored
Consolidate basic assert tests (project-chip#37168)
1 parent 575a440 commit b2b6275

File tree

7 files changed

+271
-109
lines changed

7 files changed

+271
-109
lines changed

src/python_testing/TC_DGSW_2_1.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#
3737

3838
import chip.clusters as Clusters
39+
from chip.testing import matter_asserts
3940
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
4041

4142

@@ -81,41 +82,41 @@ async def test_TC_DGSW_2_1(self):
8182
# Validate each element in the thread_metrics_list
8283
for metric in thread_metrics_list:
8384
# The Id field is mandatory
84-
self.assert_valid_uint64(metric.id, "Id")
85+
matter_asserts.assert_valid_uint64(metric.id, "Id")
8586

8687
# Validate the optional Name field
8788
if metric.name is not None:
88-
self.assert_valid_str(metric.name, "Name")
89+
matter_asserts.assert_is_string(metric.name, "Name")
8990

9091
# Validate the optional StackFreeCurrent field
9192
if metric.stackFreeCurrent is not None:
92-
self.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
93+
matter_asserts.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
9394

9495
# Validate the optional StackFreeMinimum field
9596
if metric.stackFreeMinimum is not None:
96-
self.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
97+
matter_asserts.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
9798

9899
# Validate the optional StackSize field
99100
if metric.stackSize is not None:
100-
self.assert_valid_uint32(metric.stackSize, "StackSize")
101+
matter_asserts.assert_valid_uint32(metric.stackSize, "StackSize")
101102

102103
# STEP 3: TH reads from the DUT the CurrentHeapFree attribute
103104
self.step(3)
104105
if self.pics_guard(attributes.CurrentHeapFree.attribute_id in attribute_list):
105106
current_heap_free_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapFree)
106-
self.assert_valid_uint64(current_heap_free_attr, "CurrentHeapFree")
107+
matter_asserts.assert_valid_uint64(current_heap_free_attr, "CurrentHeapFree")
107108

108109
# STEP 4: TH reads from the DUT the CurrentHeapUsed attribute
109110
self.step(4)
110111
if self.pics_guard(attributes.CurrentHeapUsed.attribute_id in attribute_list):
111112
current_heap_used_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed)
112-
self.assert_valid_uint64(current_heap_used_attr, "CurrentHeapUsed")
113+
matter_asserts.assert_valid_uint64(current_heap_used_attr, "CurrentHeapUsed")
113114

114115
# STEP 5: TH reads from the DUT the CurrentHeapHighWatermark attribute
115116
self.step(5)
116117
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
117118
current_heap_high_watermark_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
118-
self.assert_valid_uint64(current_heap_high_watermark_attr, "CurrentHeapHighWatermark")
119+
matter_asserts.assert_valid_uint64(current_heap_high_watermark_attr, "CurrentHeapHighWatermark")
119120

120121

121122
if __name__ == "__main__":

src/python_testing/TC_DGSW_2_2.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#
4343

4444
import chip.clusters as Clusters
45+
from chip.testing import matter_asserts
4546
from chip.testing.matter_testing import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main
46-
from mobly import asserts
4747

4848

4949
class TC_DGSW_2_2(MatterBaseTest):
@@ -66,22 +66,13 @@ def validate_soft_fault_event_data(self, event_data):
6666
"""
6767

6868
# Validate 'Id' field: Ensure it is a uint64 type
69-
asserts.assert_true(
70-
self.is_valid_uint_value(event_data.id, bit_count=64),
71-
"The 'Id' field must be a uint64 type"
72-
)
69+
matter_asserts.assert_valid_uint64(event_data.id, "Id")
7370

7471
# Validate 'Name' field: Ensure it is a string
75-
asserts.assert_true(
76-
isinstance(event_data.name, str),
77-
"The 'Name' field must be a string type"
78-
)
72+
matter_asserts.assert_is_string(event_data.name, "Name")
7973

8074
# Validate 'FaultRecording' field: Ensure it is an octet string (bytes or bytearray)
81-
asserts.assert_true(
82-
self.is_valid_octet_string(event_data.faultRecording),
83-
"The 'FaultRecording' field must be an octet string (bytes or bytearray)"
84-
)
75+
matter_asserts.assert_is_octstr(event_data.faultRecording, "FaultRecording")
8576

8677
def desc_TC_DGSW_2_2(self) -> str:
8778
"""Returns a description of this test"""

src/python_testing/TC_DGSW_2_3.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import logging
3939

4040
import chip.clusters as Clusters
41+
from chip.testing import matter_asserts
4142
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
4243
from mobly import asserts
4344

@@ -94,31 +95,31 @@ async def test_TC_DGSW_2_3(self):
9495
# Iterate over all items in the list and validate each one
9596
for metric in thread_metrics_original:
9697
# The Id field is mandatory
97-
self.assert_valid_uint64(metric.id, "Id")
98+
matter_asserts.assert_valid_uint64(metric.id, "Id")
9899

99100
if metric.name is not None:
100-
self.assert_valid_str(metric.name, "Name")
101+
matter_asserts.assert_is_string(metric.name, "Name")
101102

102103
if metric.stackFreeCurrent is not None:
103-
self.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
104+
matter_asserts.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
104105

105106
if metric.stackFreeMinimum is not None:
106-
self.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
107+
matter_asserts.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
107108

108109
if metric.stackSize is not None:
109-
self.assert_valid_uint32(metric.stackSize, "StackSize")
110+
matter_asserts.assert_valid_uint32(metric.stackSize, "StackSize")
110111

111112
# STEP 4: TH reads from the DUT the CurrentHeapHighWatermark attribute
112113
self.step(4)
113114
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
114115
high_watermark_original = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
115-
self.assert_valid_uint64(high_watermark_original, "CurrentHeapHighWatermark")
116+
matter_asserts.assert_valid_uint64(high_watermark_original, "CurrentHeapHighWatermark")
116117

117118
# STEP 5: TH reads from the DUT the CurrentHeapUsed attribute
118119
self.step(5)
119120
if self.pics_guard(attributes.CurrentHeapUsed.attribute_id in attribute_list):
120121
current_heap_used_original = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed)
121-
self.assert_valid_uint64(current_heap_used_original, "CurrentHeapUsed")
122+
matter_asserts.assert_valid_uint64(current_heap_used_original, "CurrentHeapUsed")
122123

123124
if high_watermark_original is not None:
124125
asserts.assert_true(current_heap_used_original <= high_watermark_original,
@@ -133,7 +134,7 @@ async def test_TC_DGSW_2_3(self):
133134
self.step(7)
134135
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
135136
current_heap_high_watermark = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
136-
self.assert_valid_uint64(current_heap_high_watermark, "CurrentHeapHighWatermark")
137+
matter_asserts.assert_valid_uint64(current_heap_high_watermark, "CurrentHeapHighWatermark")
137138

138139
# Verify that the returned value is <= high_watermark_original
139140
asserts.assert_true(current_heap_high_watermark <= high_watermark_original,
@@ -152,19 +153,19 @@ async def test_TC_DGSW_2_3(self):
152153

153154
# Validate all elements in the list
154155
for metric in thread_metrics_reset:
155-
self.assert_valid_uint64(metric.id, "Id")
156+
matter_asserts.assert_valid_uint64(metric.id, "Id")
156157

157158
if metric.name is not None:
158-
self.assert_valid_str(metric.name, "Name")
159+
matter_asserts.assert_is_string(metric.name, "Name")
159160

160161
if metric.stackFreeCurrent is not None:
161-
self.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
162+
matter_asserts.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
162163

163164
if metric.stackFreeMinimum is not None:
164-
self.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
165+
matter_asserts.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
165166

166167
if metric.stackSize is not None:
167-
self.assert_valid_uint32(metric.stackSize, "StackSize")
168+
matter_asserts.assert_valid_uint32(metric.stackSize, "StackSize")
168169

169170
# Ensure the list length matches thread_metrics_original to simplify matching
170171
asserts.assert_equal(len(thread_metrics_reset), len(thread_metrics_original),

src/python_testing/TC_DGWIFI_2_1.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import chip.clusters as Clusters
3636
from chip.clusters.Types import Nullable, NullValue
37+
from chip.testing import matter_asserts
3738
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
3839
from mobly import asserts
3940

@@ -131,7 +132,7 @@ async def test_TC_DGWIFI_2_1(self):
131132
# Just do a minimal check here; you can refine or extend based on the spec.
132133
if security_type is not NullValue:
133134
security_type_value = security_type.Value
134-
self.assert_valid_uint8(security_type_value, "SecurityType")
135+
matter_asserts.assert_valid_uint8(security_type_value, "SecurityType")
135136

136137
# Check if the security_type is a valid SecurityTypeEnum member
137138
self.assert_true(
@@ -154,7 +155,7 @@ async def test_TC_DGWIFI_2_1(self):
154155
# WiFiVersion is an enum. If not configured or operational, might be NULL.
155156
if wifi_version is not NullValue:
156157
wifi_version_value = wifi_version.Value
157-
self.assert_valid_uint8(wifi_version_value, "WiFiVersion")
158+
matter_asserts.assert_valid_uint8(wifi_version_value, "WiFiVersion")
158159

159160
# Check if the wifi_version is a valid WiFiVersionEnum member
160161
self.assert_true(wifi_version_value in [item.value for item in Clusters.Objects.WiFiNetworkDiagnostics.Enums.WiFiVersionEnum],
@@ -171,7 +172,7 @@ async def test_TC_DGWIFI_2_1(self):
171172
channel_number = await self.read_dgwifi_attribute_expect_success(endpoint=endpoint, attribute=attributes.ChannelNumber)
172173
# If not operational, might be NULL. Else we expect an unsigned integer channel.
173174
if channel_number is not NullValue:
174-
self.assert_valid_uint16(channel_number.Value, "ChannelNumber")
175+
matter_asserts.assert_valid_uint16(channel_number.Value, "ChannelNumber")
175176

176177
#
177178
# STEP 6: TH reads RSSI attribute
@@ -195,7 +196,7 @@ async def test_TC_DGWIFI_2_1(self):
195196
"BeaconLostCount must be of type 'Nullable' when not None.")
196197

197198
if beacon_lost_count is not NullValue:
198-
self.assert_valid_uint32(beacon_lost_count.Value, "BeaconLostCount")
199+
matter_asserts.assert_valid_uint32(beacon_lost_count.Value, "BeaconLostCount")
199200

200201
#
201202
# STEP 8: TH reads BeaconRxCount attribute
@@ -207,7 +208,7 @@ async def test_TC_DGWIFI_2_1(self):
207208
"BeaconRxCount must be of type 'Nullable' when not None.")
208209

209210
if beacon_rx_count is not NullValue:
210-
self.assert_valid_uint32(beacon_rx_count.Value, "BeaconRxCount")
211+
matter_asserts.assert_valid_uint32(beacon_rx_count.Value, "BeaconRxCount")
211212

212213
#
213214
# STEP 9: TH reads PacketMulticastRxCount attribute
@@ -219,7 +220,7 @@ async def test_TC_DGWIFI_2_1(self):
219220
"PacketMulticastRxCount must be of type 'Nullable' when not None.")
220221

221222
if pkt_multi_rx is not NullValue:
222-
self.assert_valid_uint32(pkt_multi_rx.Value, "PacketMulticastRxCount")
223+
matter_asserts.assert_valid_uint32(pkt_multi_rx.Value, "PacketMulticastRxCount")
223224

224225
#
225226
# STEP 10: TH reads PacketMulticastTxCount attribute
@@ -231,7 +232,7 @@ async def test_TC_DGWIFI_2_1(self):
231232
"PacketMulticastTxCount must be of type 'Nullable' when not None.")
232233

233234
if pkt_multi_tx is not NullValue:
234-
self.assert_valid_uint32(pkt_multi_tx.Value, "PacketMulticastTxCount")
235+
matter_asserts.assert_valid_uint32(pkt_multi_tx.Value, "PacketMulticastTxCount")
235236

236237
#
237238
# STEP 11: TH reads PacketUnicastRxCount attribute
@@ -243,7 +244,7 @@ async def test_TC_DGWIFI_2_1(self):
243244
"PacketUnicastRxCount must be of type 'Nullable' when not None.")
244245

245246
if pkt_uni_rx is not NullValue:
246-
self.assert_valid_uint32(pkt_uni_rx.Value, "PacketUnicastRxCount")
247+
matter_asserts.assert_valid_uint32(pkt_uni_rx.Value, "PacketUnicastRxCount")
247248

248249
#
249250
# STEP 12: TH reads PacketUnicastTxCount attribute
@@ -255,7 +256,7 @@ async def test_TC_DGWIFI_2_1(self):
255256
"PacketUnicastTxCount must be of type 'Nullable' when not None.")
256257

257258
if pkt_uni_tx is not NullValue:
258-
self.assert_valid_uint32(pkt_uni_tx.Value, "PacketUnicastTxCount")
259+
matter_asserts.assert_valid_uint32(pkt_uni_tx.Value, "PacketUnicastTxCount")
259260

260261
#
261262
# STEP 13: TH reads CurrentMaxRate attribute
@@ -268,7 +269,7 @@ async def test_TC_DGWIFI_2_1(self):
268269
"CurrentMaxRate must be of type 'Nullable' when not None.")
269270

270271
if current_max_rate is not NullValue:
271-
self.assert_valid_uint64(current_max_rate.Value, "CurrentMaxRate")
272+
matter_asserts.assert_valid_uint64(current_max_rate.Value, "CurrentMaxRate")
272273

273274
#
274275
# STEP 14: TH reads OverrunCount attribute
@@ -281,7 +282,7 @@ async def test_TC_DGWIFI_2_1(self):
281282
"OverrunCount must be of type 'Nullable' when not None.")
282283

283284
if overrun_count is not NullValue:
284-
self.assert_valid_uint64(overrun_count.Value, "OverrunCount")
285+
matter_asserts.assert_valid_uint64(overrun_count.Value, "OverrunCount")
285286

286287

287288
if __name__ == "__main__":

0 commit comments

Comments
 (0)