Skip to content

Commit 6d4f8f6

Browse files
committed
update tests
1 parent 5f96396 commit 6d4f8f6

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

test/datasets.jl

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ h = get_var_handle(ds_nc, "tas")
3838
@test all(isapprox.(h[1:2,1:2], [215.893 217.168; 215.805 217.03]))
3939
@test allow_parallel_write(ds_nc) == false
4040
@test allow_missings(ds_nc) == false
41+
#Repeat the same test with an open get_var_handle
42+
ds_nc2 = YAXArrayBase.to_dataset(p2)
43+
YAXArrayBase.open_dataset_handle(ds_nc2) do ds_nc
44+
@test ds_nc.handle[] !== nothing
45+
vn = get_varnames(ds_nc)
46+
@test sort(vn) == ["area", "lat", "lat_bnds", "lon", "lon_bnds", "msk_rgn",
47+
"plev", "pr", "tas", "time", "time_bnds", "ua"]
48+
@test get_var_dims(ds_nc, "tas") == ["lon", "lat", "time"]
49+
@test get_var_dims(ds_nc, "area") == ["lon", "lat"]
50+
@test get_var_dims(ds_nc, "time") == ["time"]
51+
@test get_var_dims(ds_nc, "time_bnds") == ["bnds", "time"]
52+
@test get_var_attrs(ds_nc,"tas")["long_name"] == "air_temperature"
53+
h1 = get_var_handle(ds_nc, "tas",persist=true)
54+
@test !(h1 isa NetCDF.NcVar)
55+
@test !YAXArrayBase.iscompressed(h1)
56+
@test all(isapprox.(h1[1:2,1:2], [215.893 217.168; 215.805 217.03]))
57+
h2 = get_var_handle(ds_nc, "tas",persist=false)
58+
@test h2 isa NetCDF.NcVar
59+
@test !YAXArrayBase.iscompressed(h2)
60+
@test all(isapprox.(h2[1:2,1:2], [215.893 217.168; 215.805 217.03]))
61+
@test allow_parallel_write(ds_nc) == false
62+
@test allow_missings(ds_nc) == false
63+
end
4164
end
4265

4366
@testset "Reading Zarr" begin
@@ -71,22 +94,22 @@ end
7194
@test allow_missings(ds_tif) == true
7295
end
7396
function test_write(T)
74-
p = tempname()
75-
ds = create_empty(T, p)
76-
add_var(ds, 0.5:1:9.5, "lon", ("lon",), Dict("units"=>"degrees_east"))
77-
add_var(ds, 20:-1.0:1, "lat", ("lat",), Dict("units"=>"degrees_north"))
78-
v = add_var(ds, Float32, "tas", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius"))
97+
p = tempname()
98+
ds = create_empty(T, p)
99+
add_var(ds, 0.5:1:9.5, "lon", ("lon",), Dict("units"=>"degrees_east"))
100+
add_var(ds, 20:-1.0:1, "lat", ("lat",), Dict("units"=>"degrees_north"))
101+
v = add_var(ds, Float32, "tas", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius"))
79102

80-
v[:,:] = collect(reshape(1:200, 10, 20))
103+
v[:,:] = collect(reshape(1:200, 10, 20))
81104

82-
@test sort(get_varnames(ds)) == ["lat","lon","tas"]
83-
@test get_var_dims(ds, "tas") == ["lon", "lat"]
84-
@test get_var_dims(ds, "lon") == ["lon"]
85-
@test get_var_attrs(ds,"tas")["units"] == "Celsius"
86-
h = get_var_handle(ds, "lon")
87-
@test h[:] == 0.5:1:9.5
88-
v = get_var_handle(ds, "tas")
89-
@test v[1:2,1:2] == [1 11; 2 12]
105+
@test sort(get_varnames(ds)) == ["lat","lon","tas"]
106+
@test get_var_dims(ds, "tas") == ["lon", "lat"]
107+
@test get_var_dims(ds, "lon") == ["lon"]
108+
@test get_var_attrs(ds,"tas")["units"] == "Celsius"
109+
h = get_var_handle(ds, "lon")
110+
@test h[:] == 0.5:1:9.5
111+
v = get_var_handle(ds, "tas")
112+
@test v[1:2,1:2] == [1 11; 2 12]
90113
end
91114

92115
@testset "Writing NetCDF" begin

0 commit comments

Comments
 (0)