From f5f04d184547519b42add16f1228d8c0f660fe24 Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Fri, 1 Dec 2023 11:43:17 +0100 Subject: [PATCH] improve test coverage --- src/ZGroup.jl | 9 ++------- test/runtests.jl | 13 +++++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ZGroup.jl b/src/ZGroup.jl index 1f5b92c..5c93a54 100644 --- a/src/ZGroup.jl +++ b/src/ZGroup.jl @@ -19,7 +19,7 @@ export attributes ZGroup(storage, path::AbstractString, arrays, groups, attrs, writeable) = ZGroup(storage, String(path), arrays, groups, attrs, writeable) -zname(g::ZGroup) = zname(g.path) +zname(g::ZGroup) = zname(path(g)) #Open an existing ZGroup function ZGroup(s::T,mode="r",path="";fill_as_missing=false) where T <: AbstractStore @@ -71,12 +71,7 @@ function Base.show(io::IO, g::ZGroup) !isempty(groups(g)) && print(io, "\nGroups: ", map(i -> string(zname(i), " "), values(groups(g)))...) nothing end -Base.haskey(g::ZGroup,k)= haskey(groups(g),k) || haskey(arrays(g),k) - - -const SymbolOrString = Union{Symbol,AbstractString} -Base.haskey(x::Dict{String,ZGroup}, key::Symbol) = haskey(x, "$key") -Base.haskey(x::Dict{String,ZArray}, key::Symbol) = haskey(x, "$key") +Base.haskey(g::ZGroup,k)= haskey(groups(g),string(k)) || haskey(arrays(g),string(k)) function Base.getindex(g::ZGroup, k::AbstractString) if haskey(groups(g), k) diff --git a/test/runtests.jl b/test/runtests.jl index 40c1335..62309cb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -102,14 +102,23 @@ end zzeros(Float64,a,"a",3,3) zzeros(Int,a,"b",5,4,2) + zgroup(a,"subgroup") @test a["a"] isa ZArray @test a[:a] isa ZArray @test a.b isa ZArray - @test issetequal(propertynames(a),(:a,:b)) - @test issetequal(propertynames(a,true),(:a,:b,:attrs)) + @test a.subgroup isa ZGroup + @test haskey(a,"a") + @test haskey(a,:a) + @test !haskey(a,"something") + @test !haskey(a,:something) + @test issetequal(propertynames(a),(:a,:b,:subgroup)) + @test issetequal(propertynames(a,true),(:a,:b,:subgroup,:attrs)) @test @test_warn "Accessing attributes" a.attrs["a"]==5 @test attributes(a) == Dict("a"=>5) + buf=IOBuffer() + show(buf,a) + @test startswith(String(take!(buf)),"ZarrGroup at Dictionary Storage and path \nVariables:") end @testset "Metadata" begin