Skip to content

Commit

Permalink
Merge pull request #96 from silx-kit/committed-datatype
Browse files Browse the repository at this point in the history
Support reading metadata of committed datatypes
  • Loading branch information
axelboc authored Aug 29, 2024
2 parents af4597d + 932408b commit 922dc0f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion h5grove/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ def metadata(self, depth: int = 1):
)


class DatatypeContent(ResolvedEntityContent[h5py.Datatype]):
kind = "datatype"

def metadata(self, depth=None):
"""
:returns: {"attributes": AttributeMetadata, "kind": str, "name": str, "type": TypeMetadata}
"""
return sorted_dict(
("type", get_type_metadata(self._h5py_entity.id)),
*super().metadata().items(),
)


def create_content(
h5file: h5py.File,
path: Optional[str],
Expand Down Expand Up @@ -267,7 +280,7 @@ def create_content(
return GroupContent(path, entity, h5file)

if isinstance(entity, h5py.Datatype):
return ResolvedEntityContent(path, entity)
return DatatypeContent(path, entity)

raise TypeError(f"h5py entity {type(entity)} not supported")

Expand Down
17 changes: 17 additions & 0 deletions test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ def test_data_on_opaque(self, server):
retrieved_data = np.void(response.content)
assert np.array_equal(retrieved_data, data)

def test_meta_on_datatype(self, server):
"""Test /meta/ endpoint on a committed datatype"""
filename = "test.h5"

with h5py.File(server.served_directory / filename, mode="w") as h5file:
h5file["committed_type"] = np.dtype("<f8")

response = server.get(f"/meta/?file={filename}&path=/committed_type")
content = decode_response(response)

assert content == {
"attributes": [],
"kind": "datatype",
"name": "committed_type",
"type": {"class": 1, "dtype": "<f8", "size": 8, "order": 0},
}

def test_meta_on_chunked_compressed_dataset(self, server):
"""Test /meta/ endpoint on a chunked and compressed dataset"""
filename = "test.h5"
Expand Down

0 comments on commit 922dc0f

Please sign in to comment.