From 1dd0da53f0fc9331d488bb1ab91868935d9dd6c5 Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Thu, 21 Nov 2024 12:51:00 +0100 Subject: [PATCH] Fix unit tests (#170) * fix unit tests * Fix s3 example --- docs/src/s3examples.md | 20 +++++++++++++------- src/Storage/consolidated.jl | 2 +- test/storage.jl | 16 ++++++++-------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/src/s3examples.md b/docs/src/s3examples.md index d1f952b..0f16a1f 100644 --- a/docs/src/s3examples.md +++ b/docs/src/s3examples.md @@ -12,25 +12,31 @@ account, you can access the dataset without credentials as follows: ````@example aws using Zarr, AWS -AWS.global_aws_config(AWSConfig(creds=nothing, region = "eu-west-2")) +Zarr.AWSS3.AWS.global_aws_config(Zarr.AWSS3.AWS.AWSConfig(creds=nothing, region="us-west-2")) ```` Then we can directly open a zarr group stored on s3 ````@example aws -z = zopen("s3://zarr-demo/store/foo/bar") +z = zopen("s3://mur-sst/zarr-v1") ```` -So we see that the store points to a zarr group with a single variable `baz`. +So we see that the store points to a zarr group with a few arrays ````@example aws -v = z["baz"] +v = z["analysed_sst"] ```` -The variable seems to contain an ASCIIString. +And we can read the attributes from the array ````@example aws -String(v[:]) +v.attrs +```` + +Or some data + +````@example aws +v[1:1000,1:1000,1] ```` ## Accessing CMIP6 data on GCS @@ -156,7 +162,7 @@ a[:,:,:] = reshape(1.0:24.0, (2,3,4)) Now we test if the data can be accessed ````@example minio -a2 = zopen("s3://zarrdata/group_1/array_1") +a2 = zopen("s3://zarrdata/group_1/bar") a2[2,2,1:4] ```` ````` diff --git a/src/Storage/consolidated.jl b/src/Storage/consolidated.jl index 4b91af8..0b28f55 100644 --- a/src/Storage/consolidated.jl +++ b/src/Storage/consolidated.jl @@ -42,7 +42,7 @@ _pdict(d::ConsolidatedStore,p) = filter(((k,v),)->startswith(k,p),d.cons) function subdirs(d::ConsolidatedStore,p) p2 = _unconcpath(d,p) d2 = _pdict(d,p2) - _searchsubdict(d2,p,(sp,lp)->length(sp) > lp+1) + _searchsubdict(d2, p2, (sp, lp) -> length(sp) > lp + 1) end function subkeys(d::ConsolidatedStore,p) diff --git a/test/storage.jl b/test/storage.jl index 4d2093f..9e4fac7 100644 --- a/test/storage.jl +++ b/test/storage.jl @@ -171,15 +171,15 @@ end end @testset "AWS S3 Storage" begin - Zarr.AWSS3.AWS.global_aws_config(Zarr.AWSS3.AWS.AWSConfig(creds=nothing, region="eu-west-2")) - S3,p = Zarr.storefromstring("s3://zarr-demo/store/foo") - @test storagesize(S3,p) == 0 - @test Zarr.is_zgroup(S3,p) == true + Zarr.AWSS3.AWS.global_aws_config(Zarr.AWSS3.AWS.AWSConfig(creds=nothing, region="us-west-2")) + S3, p = Zarr.storefromstring("s3://mur-sst/zarr-v1") + @test Zarr.is_zgroup(S3, p) + @test storagesize(S3, p) == 10551 S3group = zopen(S3,path=p) - S3Array = S3group.groups["bar"].arrays["baz"] - @test eltype(S3Array) == Zarr.ASCIIChar - @test storagesize(S3Array) == 69 - @test String(S3Array[:]) == "Hello from the cloud!" + S3Array = S3group["time"] + @test eltype(S3Array) == Int64 + @test storagesize(S3Array) == 72184 + @test S3Array[1:5] == [0, 1, 2, 3, 4] end @testset "GCS Storage" begin