|
1 |
| -using CommonDataModel: iswritable, attribnames, parentdataset, load!, dataset |
2 |
| -using Dates |
3 |
| -using DiskArrays |
4 |
| -using NCDatasets |
5 | 1 | using Test
|
6 | 2 | using ZarrDatasets
|
7 | 3 |
|
8 | 4 | @testset "ZarrDatasets.jl" begin
|
9 |
| - fname = tempname() |
10 |
| - mkpath(fname) |
11 |
| - |
12 |
| - nczarr_name = "file://" * fname * "#mode=zarr" |
13 |
| - @debug "filenames " nczarr_name fname |
14 |
| - v = randn(2,3) |
15 |
| - ds = NCDataset(nczarr_name,"c") |
16 |
| - defVar(ds,"var",v,("lon","lat"),attrib = Dict( |
17 |
| - "foo" => "bar", |
18 |
| - "int_attribute" => 1, |
19 |
| - "float_attribute" => 1., |
20 |
| - "scale_factor" => 1.23)) |
21 |
| - ds.attrib["title"] = "test file" |
22 |
| - close(ds) |
23 |
| - |
24 |
| - ds = NCDataset(nczarr_name) |
25 |
| - dsz = ZarrDataset(fname) |
26 |
| - |
27 |
| - @test Set(dimnames(dsz)) == Set(dimnames(ds)) |
28 |
| - |
29 |
| - for (name,len) in ds.dim |
30 |
| - @test dsz.dim[name] == len |
31 |
| - end |
32 |
| - |
33 |
| - for (varname,v) in ds |
34 |
| - @test haskey(dsz,varname) |
35 |
| - |
36 |
| - v2 = dsz[varname] |
37 |
| - @test Array(v2) == Array(v) |
38 |
| - |
39 |
| - for (attribname,attribval) in v.attrib |
40 |
| - @test v2.attrib[attribname] == attribval |
41 |
| - end |
42 |
| - end |
43 |
| - |
44 |
| - for (attribname,attribval) in ds.attrib |
45 |
| - @test dsz.attrib[attribname] == attribval |
46 |
| - end |
47 |
| - |
48 |
| - io = IOBuffer() |
49 |
| - show(io,dsz) |
50 |
| - str = String(take!(io)) |
51 |
| - @test occursin("title",str) |
52 |
| - |
53 |
| - @test !iswritable(dsz) |
54 |
| - @test "title" in attribnames(dsz) |
55 |
| - @test isnothing(parentdataset(dsz)) |
56 |
| - |
57 |
| - zvar = ZarrDataset(fname) do ds3 |
58 |
| - Array(ds3["var"]) |
59 |
| - end |
60 |
| - |
61 |
| - @test DiskArrays.haschunks(dsz["var"]) == DiskArrays.Chunked() |
62 |
| - @test length(DiskArrays.eachchunk(dsz["var"])) ≥ 1 |
63 |
| - @test zvar == Array(ds["var"]) |
64 |
| - |
65 |
| - v = dsz["var"].var |
66 |
| - buffer = zeros(eltype(v),size(v)) |
67 |
| - load!(v,buffer,:,:) |
68 |
| - |
69 |
| - @test buffer == Array(ds["var"].var) |
70 |
| - |
71 |
| - @test dataset(dsz["var"]) == dsz |
72 |
| - close(ds) |
73 |
| - close(dsz) |
| 5 | + include("test_cdm.jl") |
| 6 | + include("test_multifile.jl") |
74 | 7 | end
|
0 commit comments