Skip to content

Commit bd273d2

Browse files
authored
[TC_DGSW] Symplify Validation Assertions (#36997)
1 parent c459b64 commit bd273d2

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

src/python_testing/TC_DGSW_2_1.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ def is_valid_uint32_value(value):
5454
def is_valid_str_value(value):
5555
return isinstance(value, str) and len(value) > 0
5656

57+
def assert_valid_uint64(self, value, field_name):
58+
"""Asserts that the value is a valid uint64."""
59+
asserts.assert_true(self.is_valid_uint64_value(value), f"{field_name} field should be a uint64 type")
60+
61+
def assert_valid_uint32(self, value, field_name):
62+
"""Asserts that the value is a valid uint32."""
63+
asserts.assert_true(self.is_valid_uint32_value(value), f"{field_name} field should be a uint32 type")
64+
65+
def assert_valid_str(self, value, field_name):
66+
"""Asserts that the value is a non-empty string."""
67+
asserts.assert_true(self.is_valid_str_value(value), f"{field_name} field should be a non-empty string")
68+
5769
async def read_dgsw_attribute_expect_success(self, endpoint, attribute):
5870
cluster = Clusters.Objects.SoftwareDiagnostics
5971
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
@@ -94,44 +106,41 @@ async def test_TC_DGSW_2_1(self):
94106
# Validate each element in the thread_metrics_list
95107
for metric in thread_metrics_list:
96108
# The Id field is mandatory
97-
asserts.assert_true(self.is_valid_uint64_value(metric.id), "Id field should be a uint64 type")
109+
self.assert_valid_uint64(metric.id, "Id")
98110

99111
# Validate the optional Name field
100112
if metric.name is not None:
101-
asserts.assert_true(self.is_valid_str_value(metric.name), "Name field should be a string type")
113+
self.assert_valid_str(metric.name, "Name")
102114

103115
# Validate the optional StackFreeCurrent field
104116
if metric.stackFreeCurrent is not None:
105-
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeCurrent),
106-
"StackFreeCurrent field should be a uint32 type")
117+
self.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
107118

108119
# Validate the optional StackFreeMinimum field
109120
if metric.stackFreeMinimum is not None:
110-
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeMinimum),
111-
"StackFreeMinimum field should be a uint32 type")
121+
self.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
112122

113123
# Validate the optional StackSize field
114124
if metric.stackSize is not None:
115-
asserts.assert_true(self.is_valid_uint32_value(metric.stackSize), "StackSize field should be a uint32 type")
125+
self.assert_valid_uint32(metric.stackSize, "StackSize")
116126

117127
# STEP 3: TH reads from the DUT the CurrentHeapFree attribute
118128
self.step(3)
119129
if self.pics_guard(attributes.CurrentHeapFree.attribute_id in attribute_list):
120130
current_heap_free_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapFree)
121-
asserts.assert_true(self.is_valid_uint64_value(current_heap_free_attr), "CurrentHeapFree field should be a uint64 type")
131+
self.assert_valid_uint64(current_heap_free_attr, "CurrentHeapFree")
122132

123133
# STEP 4: TH reads from the DUT the CurrentHeapUsed attribute
124134
self.step(4)
125135
if self.pics_guard(attributes.CurrentHeapUsed.attribute_id in attribute_list):
126136
current_heap_used_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed)
127-
asserts.assert_true(self.is_valid_uint64_value(current_heap_used_attr), "CurrentHeapUsed field should be a uint64 type")
137+
self.assert_valid_uint64(current_heap_used_attr, "CurrentHeapUsed")
128138

129139
# STEP 5: TH reads from the DUT the CurrentHeapHighWatermark attribute
130140
self.step(5)
131141
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
132142
current_heap_high_watermark_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
133-
asserts.assert_true(self.is_valid_uint64_value(current_heap_high_watermark_attr),
134-
"CurrentHeapHighWatermark field should be a uint64 type")
143+
self.assert_valid_uint64(current_heap_high_watermark_attr, "CurrentHeapHighWatermark")
135144

136145

137146
if __name__ == "__main__":

src/python_testing/TC_DGSW_2_3.py

+27-22
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ def is_valid_uint32_value(value):
5656
def is_valid_str_value(value):
5757
return isinstance(value, str) and len(value) > 0
5858

59+
def assert_valid_uint64(self, value, field_name):
60+
"""Asserts that the value is a valid uint64."""
61+
asserts.assert_true(self.is_valid_uint64_value(value), f"{field_name} field should be a uint64 type")
62+
63+
def assert_valid_uint32(self, value, field_name):
64+
"""Asserts that the value is a valid uint32."""
65+
asserts.assert_true(self.is_valid_uint32_value(value), f"{field_name} field should be a uint32 type")
66+
67+
def assert_valid_str(self, value, field_name):
68+
"""Asserts that the value is a non-empty string."""
69+
asserts.assert_true(self.is_valid_str_value(value), f"{field_name} field should be a non-empty string")
70+
5971
async def read_dgsw_attribute_expect_success(self, endpoint, attribute):
6072
cluster = Clusters.Objects.SoftwareDiagnostics
6173
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
@@ -67,7 +79,7 @@ async def send_reset_watermarks_command(self):
6779

6880
def desc_TC_DGSW_2_3(self) -> str:
6981
"""Returns a description of this test"""
70-
return "[TC-DGSW-2.1] Attributes with Server as DUT"
82+
return "[TC-DGSW-2.3] Attributes with Server as DUT"
7183

7284
def pics_TC_DGSW_2_3(self) -> list[str]:
7385
return ["DGSW.S"]
@@ -106,35 +118,32 @@ async def test_TC_DGSW_2_3(self):
106118
# Iterate over all items in the list and validate each one
107119
for metric in thread_metrics_original:
108120
# The Id field is mandatory
109-
asserts.assert_true(self.is_valid_uint64_value(metric.id), "Id field should be a uint64 type")
121+
self.assert_valid_uint64(metric.id, "Id")
110122

111123
if metric.name is not None:
112-
asserts.assert_true(self.is_valid_str_value(metric.name), "Name field should be a string type")
124+
self.assert_valid_str(metric.name, "Name")
113125

114126
if metric.stackFreeCurrent is not None:
115-
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeCurrent),
116-
"StackFreeCurrent field should be a uint32 type")
127+
self.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
117128

118129
if metric.stackFreeMinimum is not None:
119-
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeMinimum),
120-
"StackFreeMinimum field should be a uint32 type")
130+
self.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
121131

122132
if metric.stackSize is not None:
123-
asserts.assert_true(self.is_valid_uint32_value(metric.stackSize), "StackSize field should be a uint32 type")
133+
self.assert_valid_uint32(metric.stackSize, "StackSize")
124134

125135
# STEP 4: TH reads from the DUT the CurrentHeapHighWatermark attribute
126136
self.step(4)
127137
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
128138
high_watermark_original = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
129-
asserts.assert_true(self.is_valid_uint64_value(high_watermark_original),
130-
"CurrentHeapHighWatermark field should be a uint64 type")
139+
self.assert_valid_uint64(high_watermark_original, "CurrentHeapHighWatermark")
131140

132141
# STEP 5: TH reads from the DUT the CurrentHeapUsed attribute
133142
self.step(5)
134143
if self.pics_guard(attributes.CurrentHeapUsed.attribute_id in attribute_list):
135144
current_heap_used_original = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed)
136-
asserts.assert_true(self.is_valid_uint64_value(current_heap_used_original),
137-
"CurrentHeapUsed field should be a uint64 type")
145+
self.assert_valid_uint64(current_heap_used_original, "CurrentHeapUsed")
146+
138147
if high_watermark_original is not None:
139148
asserts.assert_true(current_heap_used_original <= high_watermark_original,
140149
"CurrentHeapUsed should be less than or equal to CurrentHeapHighWatermark")
@@ -148,8 +157,7 @@ async def test_TC_DGSW_2_3(self):
148157
self.step(7)
149158
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
150159
current_heap_high_watermark = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
151-
asserts.assert_true(self.is_valid_uint64_value(current_heap_high_watermark),
152-
"CurrentHeapHighWatermark field should be a uint64 type")
160+
self.assert_valid_uint64(current_heap_high_watermark, "CurrentHeapHighWatermark")
153161

154162
# Verify that the returned value is <= high_watermark_original
155163
asserts.assert_true(current_heap_high_watermark <= high_watermark_original,
@@ -168,22 +176,19 @@ async def test_TC_DGSW_2_3(self):
168176

169177
# Validate all elements in the list
170178
for metric in thread_metrics_reset:
171-
# The Id field is mandatory
172-
asserts.assert_true(self.is_valid_uint64_value(metric.id), "Id field should be a uint64 type")
179+
self.assert_valid_uint64(metric.id, "Id")
173180

174181
if metric.name is not None:
175-
asserts.assert_true(self.is_valid_str_value(metric.name), "Name field should be a string type")
182+
self.assert_valid_str(metric.name, "Name")
176183

177184
if metric.stackFreeCurrent is not None:
178-
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeCurrent),
179-
"StackFreeCurrent field should be a uint32 type")
185+
self.assert_valid_uint32(metric.stackFreeCurrent, "StackFreeCurrent")
180186

181187
if metric.stackFreeMinimum is not None:
182-
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeMinimum),
183-
"StackFreeMinimum field should be a uint32 type")
188+
self.assert_valid_uint32(metric.stackFreeMinimum, "StackFreeMinimum")
184189

185190
if metric.stackSize is not None:
186-
asserts.assert_true(self.is_valid_uint32_value(metric.stackSize), "StackSize field should be a uint32 type")
191+
self.assert_valid_uint32(metric.stackSize, "StackSize")
187192

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

0 commit comments

Comments
 (0)