Skip to content

Commit

Permalink
Allow attributes on types (#832)
Browse files Browse the repository at this point in the history
* Allow attributes on types

* Test attributes on types
  • Loading branch information
eschnett authored May 14, 2021
1 parent b4d3434 commit 3bf0012
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ end
Base.cconvert(::Type{hid_t}, attr::Attribute) = attr.id

struct Attributes
parent::Union{File,Group,Dataset}
parent::Union{File,Object}
end
attributes(p::Union{File,Group,Dataset}) = Attributes(p)
attributes(p::Union{File,Object}) = Attributes(p)

# Methods for reference types
function Reference(parent::Union{File,Group,Dataset}, name::AbstractString)
Expand Down
9 changes: 9 additions & 0 deletions test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@ dtype = HDF5.Datatype(HDF5.h5t_copy(HDF5.H5T_IEEE_F64LE))
commit_datatype(hfile, "type", dtype)
@test sprint(show, dtype) == "HDF5.Datatype: /type H5T_IEEE_F64LE"

dtypemeta = create_attribute(dtype, "dtypemeta", datatype(Bool), dataspace((1,)))
@test sprint(show, dtypemeta) == "HDF5.Attribute: dtypemeta"

dtypeattrs = attributes(dtype)
@test sprint(show, dtypeattrs) == "Attributes of HDF5.Datatype: /type H5T_IEEE_F64LE"

dspace_null = HDF5.Dataspace(HDF5.h5s_create(HDF5.H5S_NULL))
dspace_scal = HDF5.Dataspace(HDF5.h5s_create(HDF5.H5S_SCALAR))
dspace_norm = dataspace((100, 4))
Expand Down Expand Up @@ -735,6 +741,9 @@ close(prop)
close(meta)
@test sprint(show, meta) == "HDF5.Attribute: (invalid)"

close(dtypemeta)
@test sprint(show, dtypemeta) == "HDF5.Attribute: (invalid)"

close(dset)
@test sprint(show, dset) == "HDF5.Dataset: (invalid)"
@test sprint(show, dsetattrs) == "Attributes of HDF5.Dataset: (invalid)"
Expand Down

0 comments on commit 3bf0012

Please sign in to comment.