diff --git a/h5grove/content.py b/h5grove/content.py index 72c2206..b193855 100644 --- a/h5grove/content.py +++ b/h5grove/content.py @@ -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], @@ -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") diff --git a/test/base_test.py b/test/base_test.py index 154d161..df6d60d 100644 --- a/test/base_test.py +++ b/test/base_test.py @@ -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("