Skip to content

Commit

Permalink
rearrange, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Sep 5, 2023
1 parent b5b917e commit a94ebb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/dataspaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Base.close(obj::Dataspace)
end

# null dataspace constructor
Dataspace(nothing) = Dataspace(API.h5s_create(API.H5S_NULL))
Dataspace(::Nothing) = Dataspace(API.h5s_create(API.H5S_NULL))

# reverese dims order, convert to hsize_t
_to_h5_dims(dims::Dims{N}) where {N} = API.hsize_t[dims[i] for i in N:-1:1]
Expand Down
23 changes: 23 additions & 0 deletions test/dataspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ using Test
@test dataspace(HDF5.EmptyArray{Bool}()) == ds_null

@test repr(ds_null) == "HDF5.Dataspace(nothing): null dataspace"

close(ds_null)
@test repr(ds_null) == "HDF5.Dataspace: (invalid)"
end

@testset "scalar dataspace" begin
Expand Down Expand Up @@ -216,3 +219,23 @@ end
@test HDF5.get_extent_dims(dspace_maxd)[1] == (3, 1)
@test HDF5.get_extent_dims(dspace_maxd)[2] == (-1, -1)
end


@testset "hyperslab" begin

dspace_slab = HDF5.hyperslab(Dataspace((100, 4)), 1:20:100, 1:4)
@test repr(dspace_slab) == """
HDF5.Dataspace((100, 4)): 2-dimensional dataspace
hyperslab selection: (1:20:81, 1:4)"""


if HDF5.libversion v"1.10.7"
dspace_irrg =
HDF5.select_hyperslab!(
copy(dspace_slab),
:or,
(2, 2),
)
@test repr(dspace_irrg) == "HDF5.Dataspace((100, 4)): 2-dimensional dataspace [irregular selection]"
end
end
24 changes: 1 addition & 23 deletions test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end
dtype = HDF5.Datatype(HDF5.API.h5t_copy(HDF5.API.H5T_C_S1))
HDF5.API.h5t_set_size(dtype, HDF5.API.H5T_VARIABLE)
HDF5.API.h5t_set_cset(dtype, HDF5.cset(typeof(salut)))
dspace = Dataspace(salut)
dspace = dataspace(salut)
dset = create_dataset(f, "salut-vlen", dtype, dspace)
GC.@preserve salut begin
HDF5.API.h5d_write(
Expand Down Expand Up @@ -906,31 +906,9 @@ end # generic read of native types
dtypeattrs = attributes(dtype)
@test sprint(show, dtypeattrs) == "Attributes of HDF5.Datatype: /type H5T_IEEE_F64LE"

dspace_null = HDF5.Dataspace(HDF5.API.h5s_create(HDF5.API.H5S_NULL))
dspace_scal = HDF5.Dataspace(HDF5.API.h5s_create(HDF5.API.H5S_SCALAR))
dspace_norm = Dataspace((100, 4))
dspace_maxd = Dataspace((100, 4); max_dims=(256, 4))
dspace_slab = HDF5.hyperslab(Dataspace((100, 4)), 1:20:100, 1:4)
if HDF5.libversion v"1.10.7"
dspace_irrg = HDF5.Dataspace(
HDF5.API.h5s_combine_select(
HDF5.API.h5s_copy(dspace_slab),
HDF5.API.H5S_SELECT_OR,
HDF5.hyperslab(Dataspace((100, 4)), 2, 2)
)
)
@test sprint(show, dspace_irrg) == "HDF5.Dataspace: (100, 4) [irregular selection]"
end
@test sprint(show, dspace_null) == "HDF5.Dataspace: H5S_NULL"
@test sprint(show, dspace_scal) == "HDF5.Dataspace: H5S_SCALAR"
@test sprint(show, dspace_norm) == "HDF5.Dataspace: (100, 4)"
@test sprint(show, dspace_maxd) == "HDF5.Dataspace: (100, 4) / (256, 4)"
@test sprint(show, dspace_slab) == "HDF5.Dataspace: (1:20:81, 1:4) / (1:100, 1:4)"

# Now test printing after closing each object

close(dspace_null)
@test sprint(show, dspace_null) == "HDF5.Dataspace: (invalid)"

close(dtype)
@test sprint(show, dtype) == "HDF5.Datatype: (invalid)"
Expand Down

0 comments on commit a94ebb8

Please sign in to comment.