Skip to content

Commit

Permalink
Rewrite TestWriteBasicAttributes to drop ZCLRead/WriteAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed May 7, 2024
1 parent 61c21d5 commit a4c38a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
37 changes: 17 additions & 20 deletions src/controller/python/test/test_scripts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,45 +1201,42 @@ def TestReadBasicAttributes(self, nodeid: int, endpoint: int, group: int):
return False
return True

def TestWriteBasicAttributes(self, nodeid: int, endpoint: int, group: int):
def TestWriteBasicAttributes(self, nodeid: int, endpoint: int):
@ dataclass
class AttributeWriteRequest:
cluster: str
attribute: str
cluster: Clusters.ClusterObjects.Cluster
attribute: Clusters.ClusterObjects.ClusterAttributeDescriptor
value: Any
expected_status: IM.Status = IM.Status.Success

requests = [
AttributeWriteRequest("BasicInformation", "NodeLabel", "Test"),
AttributeWriteRequest("BasicInformation", "Location",
AttributeWriteRequest(Clusters.BasicInformation, Clusters.BasicInformation.Attributes.NodeLabel, "Test"),
AttributeWriteRequest(Clusters.BasicInformation, Clusters.BasicInformation.Attributes.Location,
"a pretty loooooooooooooog string", IM.Status.ConstraintError),
]
failed_zcl = []
failed_attribute_write = []
for req in requests:
try:
try:
self.devCtrl.ZCLWriteAttribute(cluster=req.cluster,
attribute=req.attribute,
nodeid=nodeid,
endpoint=endpoint,
groupid=group,
value=req.value)
await self.WriteAttribute(nodeid, [(endpoint, req.attribute, 0)])
if req.expected_status != IM.Status.Success:
raise AssertionError(
f"Write attribute {req.cluster}.{req.attribute} expects failure but got success response")
f"Write attribute {req.attribute.__qualname__} expects failure but got success response")
except Exception as ex:
if req.expected_status != IM.Status.Success:
continue
else:
raise ex
res = self.devCtrl.ZCLReadAttribute(
cluster=req.cluster, attribute=req.attribute, nodeid=nodeid, endpoint=endpoint, groupid=group)
TestResult(f"Read attribute {req.cluster}.{req.attribute}", res).assertValueEqual(
req.value)

res = await self.ReadAttribute(nodeid, [(endpoint, req.attribute)])
val = res[endpoint][req.cluster][req.attribute]
if val != req.value:
raise Exception(
f"Read attribute {req.attribute.__qualname__}: expected value {req.value}, got {val}")
except Exception as ex:
failed_zcl.append(str(ex))
if failed_zcl:
self.logger.exception(f"Following attributes failed: {failed_zcl}")
failed_attribute_write.append(str(ex))
if failed_attribute_write:
self.logger.exception(f"Following attributes failed: {failed_attribute_write}")
return False
return True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def TestDatamodel(test: BaseTestHelper, device_nodeid: int):

logger.info("Testing attribute writing")
FailIfNot(test.TestWriteBasicAttributes(nodeid=device_nodeid,
endpoint=ENDPOINT_ID,
group=GROUP_ID),
endpoint=ENDPOINT_ID),
"Failed to test Write Basic Attributes")

logger.info("Testing attribute reading basic again")
Expand Down

0 comments on commit a4c38a9

Please sign in to comment.