Skip to content

Commit

Permalink
extend fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Dec 12, 2024
1 parent a4f0aca commit b95087f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
2 changes: 0 additions & 2 deletions hsds/dset_dn.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ async def PUT_DatasetShape(request):
selection += f"{lb}:{ub}"
dims[i] = ub
else:
if dims[i] == 0:
dims[i] = 1 # each dimension must be non-zero
selection += ":"
if i < len(dims) - 1:
selection += ","
Expand Down
84 changes: 84 additions & 0 deletions tests/integ/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,90 @@ def testExtend2DDataset(self):
self.assertEqual(shape["dims"][0], 15) # increased to 15
self.assertEqual(shape["dims"][1], 30) # increased to 30

def testExtend3DDataset(self):
# test extending dataset with three dimension
domain = self.base_domain + "/testExtend3DDataset.h5"
helper.setupDomain(domain)
print("testExtend3DDataset", domain)
headers = helper.getRequestHeaders(domain=domain)

# get domain
req = helper.getEndpoint() + "/"
rsp = self.session.get(req, headers=headers)
rspJson = json.loads(rsp.text)
self.assertTrue("root" in rspJson)
root_uuid = rspJson["root"]

# create the dataset
req = self.endpoint + "/datasets"
payload = {"type": "H5T_STD_I32LE", "shape": [0, 3, 0], "maxdims": [0, 3, 0]}
req = self.endpoint + "/datasets"
rsp = self.session.post(req, data=json.dumps(payload), headers=headers)
self.assertEqual(rsp.status_code, 201) # create dataset
rspJson = json.loads(rsp.text)
dset_uuid = rspJson["id"]
self.assertTrue(helper.validateId(dset_uuid))

# link new dataset as 'extendable'
name = "extendable"
req = self.endpoint + "/groups/" + root_uuid + "/links/" + name
payload = {"id": dset_uuid}
rsp = self.session.put(req, data=json.dumps(payload), headers=headers)
self.assertEqual(rsp.status_code, 201)

# verify type and shape
req = helper.getEndpoint() + "/datasets/" + dset_uuid
rsp = self.session.get(req, headers=headers)
self.assertEqual(rsp.status_code, 200)
rspJson = json.loads(rsp.text)
type_json = rspJson["type"]
self.assertEqual(type_json["class"], "H5T_INTEGER")
self.assertEqual(type_json["base"], "H5T_STD_I32LE")
shape = rspJson["shape"]
self.assertEqual(shape["class"], "H5S_SIMPLE")

self.assertEqual(len(shape["dims"]), 3)
self.assertEqual(shape["dims"], [0, 3, 0])
self.assertTrue("maxdims" in shape)
self.assertEqual(shape["maxdims"], [0, 3, 0])

# verify shape using the GET shape request
req = req + "/shape"
rsp = self.session.get(req, headers=headers)
self.assertEqual(rsp.status_code, 200)
rspJson = json.loads(rsp.text)
self.assertTrue("type" not in rspJson)
self.assertTrue("shape" in rspJson)
shape = rspJson["shape"]
self.assertEqual(shape["class"], "H5S_SIMPLE")
self.assertEqual(len(shape["dims"]), 3)
self.assertEqual(shape["dims"], [0, 3, 0])
self.assertTrue("maxdims" in shape)
self.assertEqual(shape["maxdims"], [0, 3, 0])

# extend the dataset by 5 elements in first dimension
payload = {"extend": 5, "extend_dim": 0}
rsp = self.session.put(req, data=json.dumps(payload), headers=headers)
self.assertEqual(rsp.status_code, 201)
rspJson = json.loads(rsp.text)
self.assertTrue("selection" in rspJson)
self.assertEqual(rspJson["selection"], "[0:5,:,:]")

# verify updated-shape using the GET shape request
rsp = self.session.get(req, headers=headers)
self.assertEqual(rsp.status_code, 200)
rspJson = json.loads(rsp.text)
self.assertTrue("shape" in rspJson)
shape = rspJson["shape"]
self.assertEqual(shape["class"], "H5S_SIMPLE")
self.assertEqual(len(shape["dims"]), 3)
self.assertEqual(shape["dims"], [5, 3, 0])

# extend the dataset by 10 elements in second dimension
payload = {"extend": 10, "extend_dim": 1}
rsp = self.session.put(req, data=json.dumps(payload), headers=headers)
self.assertEqual(rsp.status_code, 409) # tried to extend a non-extensible dimension

def testCreationPropertiesLayoutDataset(self):
# test Dataset with creation property list
domain = self.base_domain + "/testCreationPropertiesLayoutDataset.h5"
Expand Down

0 comments on commit b95087f

Please sign in to comment.