Skip to content

Commit 855b179

Browse files
committed
Rewrite TestWriteBasicAttributes to drop ZCLRead/WriteAttribute
1 parent 61c21d5 commit 855b179

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/controller/python/test/test_scripts/base.py

+17-20
Original file line numberDiff line numberDiff line change
@@ -1201,45 +1201,42 @@ def TestReadBasicAttributes(self, nodeid: int, endpoint: int, group: int):
12011201
return False
12021202
return True
12031203

1204-
def TestWriteBasicAttributes(self, nodeid: int, endpoint: int, group: int):
1204+
async def TestWriteBasicAttributes(self, nodeid: int, endpoint: int):
12051205
@ dataclass
12061206
class AttributeWriteRequest:
1207-
cluster: str
1208-
attribute: str
1207+
cluster: Clusters.ClusterObjects.Cluster
1208+
attribute: Clusters.ClusterObjects.ClusterAttributeDescriptor
12091209
value: Any
12101210
expected_status: IM.Status = IM.Status.Success
12111211

12121212
requests = [
1213-
AttributeWriteRequest("BasicInformation", "NodeLabel", "Test"),
1214-
AttributeWriteRequest("BasicInformation", "Location",
1213+
AttributeWriteRequest(Clusters.BasicInformation, Clusters.BasicInformation.Attributes.NodeLabel, "Test"),
1214+
AttributeWriteRequest(Clusters.BasicInformation, Clusters.BasicInformation.Attributes.Location,
12151215
"a pretty loooooooooooooog string", IM.Status.ConstraintError),
12161216
]
1217-
failed_zcl = []
1217+
failed_attribute_write = []
12181218
for req in requests:
12191219
try:
12201220
try:
1221-
self.devCtrl.ZCLWriteAttribute(cluster=req.cluster,
1222-
attribute=req.attribute,
1223-
nodeid=nodeid,
1224-
endpoint=endpoint,
1225-
groupid=group,
1226-
value=req.value)
1221+
await self.WriteAttribute(nodeid, [(endpoint, req.attribute, 0)])
12271222
if req.expected_status != IM.Status.Success:
12281223
raise AssertionError(
1229-
f"Write attribute {req.cluster}.{req.attribute} expects failure but got success response")
1224+
f"Write attribute {req.attribute.__qualname__} expects failure but got success response")
12301225
except Exception as ex:
12311226
if req.expected_status != IM.Status.Success:
12321227
continue
12331228
else:
12341229
raise ex
1235-
res = self.devCtrl.ZCLReadAttribute(
1236-
cluster=req.cluster, attribute=req.attribute, nodeid=nodeid, endpoint=endpoint, groupid=group)
1237-
TestResult(f"Read attribute {req.cluster}.{req.attribute}", res).assertValueEqual(
1238-
req.value)
1230+
1231+
res = await self.ReadAttribute(nodeid, [(endpoint, req.attribute)])
1232+
val = res[endpoint][req.cluster][req.attribute]
1233+
if val != req.value:
1234+
raise Exception(
1235+
f"Read attribute {req.attribute.__qualname__}: expected value {req.value}, got {val}")
12391236
except Exception as ex:
1240-
failed_zcl.append(str(ex))
1241-
if failed_zcl:
1242-
self.logger.exception(f"Following attributes failed: {failed_zcl}")
1237+
failed_attribute_write.append(str(ex))
1238+
if failed_attribute_write:
1239+
self.logger.exception(f"Following attributes failed: {failed_attribute_write}")
12431240
return False
12441241
return True
12451242

src/controller/python/test/test_scripts/mobile-device-test.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ def TestDatamodel(test: BaseTestHelper, device_nodeid: int):
129129
"Failed to test Read Basic Attributes")
130130

131131
logger.info("Testing attribute writing")
132-
FailIfNot(test.TestWriteBasicAttributes(nodeid=device_nodeid,
133-
endpoint=ENDPOINT_ID,
134-
group=GROUP_ID),
132+
FailIfNot(asyncio.run(test.TestWriteBasicAttributes(nodeid=device_nodeid,
133+
endpoint=ENDPOINT_ID)),
135134
"Failed to test Write Basic Attributes")
136135

137136
logger.info("Testing attribute reading basic again")

0 commit comments

Comments
 (0)