@@ -1439,6 +1439,59 @@ def testPutPointsRegionReference(self):
14391439 self .assertEqual (rsp_value ["select_type" ], "H5S_SEL_POINTS" )
14401440 self .assertEqual (rsp_value ["selection" ], [[0 , 0 ], [2 , 2 ], [4 , 4 ]])
14411441
1442+ def testPutOpaqueAttribute (self ):
1443+ print ("testPutOpaqueAttribute" , self .base_domain )
1444+ headers = helper .getRequestHeaders (domain = self .base_domain )
1445+ req = self .endpoint + "/"
1446+
1447+ rsp = self .session .get (req , headers = headers )
1448+ self .assertEqual (rsp .status_code , 200 )
1449+ rspJson = json .loads (rsp .text )
1450+ root_id = rspJson ["root" ]
1451+
1452+ opaque_type = {"class" : "H5T_OPAQUE" , "size" : 7 }
1453+
1454+ # scalar opaque attribute
1455+ attr_name = "opaque_scalar"
1456+ value = base64 .b64encode (b"OPAQUE0" ).decode ("ascii" )
1457+ data = {"type" : opaque_type , "value" : value }
1458+ req = self .endpoint + "/groups/" + root_id + "/attributes/" + attr_name
1459+ rsp = self .session .put (req , data = json .dumps (data ), headers = headers )
1460+ self .assertEqual (rsp .status_code , 201 )
1461+
1462+ rsp = self .session .get (req , headers = headers )
1463+ self .assertEqual (rsp .status_code , 200 )
1464+ rspJson = json .loads (rsp .text )
1465+ self .assertTrue ("type" in rspJson )
1466+ rsp_type = rspJson ["type" ]
1467+ self .assertEqual (rsp_type ["class" ], "H5T_OPAQUE" )
1468+ self .assertEqual (rsp_type ["size" ], 7 )
1469+ self .assertTrue ("shape" in rspJson )
1470+ self .assertEqual (rspJson ["shape" ]["class" ], "H5S_SCALAR" )
1471+ self .assertTrue ("value" in rspJson )
1472+ self .assertEqual (rspJson ["value" ], value )
1473+
1474+ # 1-D array of opaque values, including an empty (all-zero) element
1475+ attr_name = "opaque_array"
1476+ values = [
1477+ base64 .b64encode (b"OPAQUE0" ).decode ("ascii" ),
1478+ base64 .b64encode (b"OPAQUE1" ).decode ("ascii" ),
1479+ "" ,
1480+ ]
1481+ data = {"type" : opaque_type , "shape" : 3 , "value" : values }
1482+ req = self .endpoint + "/groups/" + root_id + "/attributes/" + attr_name
1483+ rsp = self .session .put (req , data = json .dumps (data ), headers = headers )
1484+ self .assertEqual (rsp .status_code , 201 )
1485+
1486+ rsp = self .session .get (req , headers = headers )
1487+ self .assertEqual (rsp .status_code , 200 )
1488+ rspJson = json .loads (rsp .text )
1489+ rsp_type = rspJson ["type" ]
1490+ self .assertEqual (rsp_type ["class" ], "H5T_OPAQUE" )
1491+ self .assertEqual (rsp_type ["size" ], 7 )
1492+ self .assertEqual (rspJson ["shape" ]["dims" ], [3 , ])
1493+ self .assertEqual (rspJson ["value" ], values )
1494+
14421495 def testPutNoData (self ):
14431496 # Test PUT value for 1d attribute without any data provided
14441497 print ("testPutNoData" , self .base_domain )
0 commit comments