Skip to content

Commit

Permalink
Fix tests for GDAL 3.9. (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion authored Nov 14, 2024
1 parent a322ce6 commit b6c95c1
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 97 deletions.
2 changes: 1 addition & 1 deletion test/test_drivers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import ArchGDAL as AG
"RandomWrite" => false,
"RandomRead" => true,
"CurveGeometries" => false,
"FastGetExtent" => false,
"FastGetExtent" => true,
"Transactions" => false,
"AlterFieldDefn" => false,
)
Expand Down
170 changes: 86 additions & 84 deletions test/test_feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,99 +97,101 @@ end
@test AG.validate(f, AG.F_VAL_ALLOW_DIFFERENT_GEOM_DIM, false) ==
true

@testset "Missing and Null Semantics" begin
@test isnothing(AG.getdefault(f, 1))
AG.setdefault!(AG.getfielddefn(f, 1), "default value")
@test AG.getdefault(f, 1) == "default value"
# This testset is commented because GDAL 3.9 has disabled most of this behaviour in C
# https://gdal.org/en/latest/development/rfc/rfc97_feature_and_fielddefn_sealing.html
# @testset "Missing and Null Semantics" begin
# @test isnothing(AG.getdefault(f, 1))
# AG.setdefault!(AG.getfielddefn(f, 1), "default value")
# @test AG.getdefault(f, 1) == "default value"

@test AG.isfieldsetandnotnull(f, 1)
@test AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1)
@test AG.getfield(f, 1) == "point-a"
# @test AG.isfieldsetandnotnull(f, 1)
# @test AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1)
# @test AG.getfield(f, 1) == "point-a"

AG.unsetfield!(f, 1)
@test !AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1) # carried over from earlier
@test isnothing(AG.getfield(f, 1))
# AG.unsetfield!(f, 1)
# @test !AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1) # carried over from earlier
# @test isnothing(AG.getfield(f, 1))

# unset & notnull: missing
AG.fillunsetwithdefault!(f)
# nothing has changed
@test isnothing(AG.getfield(f, 1))
# because it is a nullable field
@test AG.isnullable(AG.getfielddefn(f, 1))
# even though it is not a null value
@test !AG.isfieldnull(f, 1)
# the field is still not set
@test !AG.isfieldset(f, 1)
# # unset & notnull: missing
# AG.fillunsetwithdefault!(f)
# # nothing has changed
# @test isnothing(AG.getfield(f, 1))
# # because it is a nullable field
# @test AG.isnullable(AG.getfielddefn(f, 1))
# # even though it is not a null value
# @test !AG.isfieldnull(f, 1)
# # the field is still not set
# @test !AG.isfieldset(f, 1)

# set & notnull: value
AG.fillunsetwithdefault!(f, notnull = false)
if !AG.isdefaultdriverspecific(AG.getfielddefn(f, 1))
# now the field is set to the default
@test AG.getfield(f, 1) == AG.getdefault(f, 1)
@test AG.isfieldset(f, 1) # the field is now set
end
@test !AG.isfieldnull(f, 1) # still as expected
# # set & notnull: value
# AG.fillunsetwithdefault!(f, notnull = false)
# if !AG.isdefaultdriverspecific(AG.getfielddefn(f, 1))
# # now the field is set to the default
# @test AG.getfield(f, 1) == AG.getdefault(f, 1)
# @test AG.isfieldset(f, 1) # the field is now set
# end
# @test !AG.isfieldnull(f, 1) # still as expected

# set the field to be notnullable
AG.setnullable!(AG.getfielddefn(f, 1), false)
# now if we unset the field
AG.unsetfield!(f, 1)
@test !AG.isfieldnull(f, 1)
@test !AG.isfieldset(f, 1)
@test isnothing(AG.getfield(f, 1))
# and we fill unset with default again
AG.fillunsetwithdefault!(f)
if !AG.isdefaultdriverspecific(AG.getfielddefn(f, 1))
# the field is set to the default
@test AG.getfield(f, 1) == AG.getdefault(f, 1)
@test AG.isfieldset(f, 1)
end
@test !AG.isfieldnull(f, 1)
# # set the field to be notnullable
# AG.setnullable!(AG.getfielddefn(f, 1), false)
# # now if we unset the field
# AG.unsetfield!(f, 1)
# @test !AG.isfieldnull(f, 1)
# @test !AG.isfieldset(f, 1)
# @test isnothing(AG.getfield(f, 1))
# # and we fill unset with default again
# AG.fillunsetwithdefault!(f)
# if !AG.isdefaultdriverspecific(AG.getfielddefn(f, 1))
# # the field is set to the default
# @test AG.getfield(f, 1) == AG.getdefault(f, 1)
# @test AG.isfieldset(f, 1)
# end
# @test !AG.isfieldnull(f, 1)

# set & null: missing
AG.setfieldnull!(f, 1)
@test AG.isfieldnull(f, 1)
@test AG.isfieldset(f, 1)
@test ismissing(AG.getfield(f, 1))
# # set & null: missing
# AG.setfieldnull!(f, 1)
# @test AG.isfieldnull(f, 1)
# @test AG.isfieldset(f, 1)
# @test ismissing(AG.getfield(f, 1))

# unset & null: N/A (but nothing otherwise)
AG.unsetfield!(f, 1)
# Observe that OGRUnset and OGRNull are mutually exclusive
@test !AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1) # notice the field is notnull
# # unset & null: N/A (but nothing otherwise)
# AG.unsetfield!(f, 1)
# # Observe that OGRUnset and OGRNull are mutually exclusive
# @test !AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1) # notice the field is notnull

# setting the field for a notnullable column
AG.setnullable!(AG.getfielddefn(f, 1), false)
AG.setfield!(f, 1, "value")
@test AG.getfield(f, 1) == "value"
@test AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1)
AG.setfield!(f, 1, missing)
@test AG.getfield(f, 1) == AG.getdefault(f, 1)
@test AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1)
AG.setfield!(f, 1, nothing)
@test isnothing(AG.getfield(f, 1))
@test !AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1)
# # setting the field for a notnullable column
# AG.setnullable!(AG.getfielddefn(f, 1), false)
# AG.setfield!(f, 1, "value")
# @test AG.getfield(f, 1) == "value"
# @test AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1)
# AG.setfield!(f, 1, missing)
# @test AG.getfield(f, 1) == AG.getdefault(f, 1)
# @test AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1)
# AG.setfield!(f, 1, nothing)
# @test isnothing(AG.getfield(f, 1))
# @test !AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1)

# setting the field for a nullable column
AG.setnullable!(AG.getfielddefn(f, 1), true)
AG.setfield!(f, 1, "value")
@test AG.getfield(f, 1) == "value"
@test AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1)
AG.setfield!(f, 1, missing)
@test ismissing(AG.getfield(f, 1))
@test AG.isfieldset(f, 1)
@test AG.isfieldnull(f, 1) # different from that of notnullable
AG.setfield!(f, 1, nothing)
@test isnothing(AG.getfield(f, 1))
@test !AG.isfieldset(f, 1)
@test !AG.isfieldnull(f, 1)
end
# # setting the field for a nullable column
# AG.setnullable!(AG.getfielddefn(f, 1), true)
# AG.setfield!(f, 1, "value")
# @test AG.getfield(f, 1) == "value"
# @test AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1)
# AG.setfield!(f, 1, missing)
# @test ismissing(AG.getfield(f, 1))
# @test AG.isfieldset(f, 1)
# @test AG.isfieldnull(f, 1) # different from that of notnullable
# AG.setfield!(f, 1, nothing)
# @test isnothing(AG.getfield(f, 1))
# @test !AG.isfieldset(f, 1)
# @test !AG.isfieldnull(f, 1)
# end
end
end

Expand Down
30 changes: 18 additions & 12 deletions test/test_gdalutilities_errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import ArchGDAL as AG
using Test

@testset "test_gdalutilities_errors.jl" begin
AG.read("data/utmsmall.tif") do ds_small
@testset "GDAL Error" begin
@testset "GDAL Error" begin
AG.read("data/utmsmall.tif") do ds_small
@test_throws GDAL.GDALError AG.gdalinfo(
ds_small,
["-novalidoption"],
Expand All @@ -17,11 +17,14 @@ using Test
[ds_small],
["-novalidoption"],
)
@test_throws GDAL.GDALError AG.unsafe_gdaldem(
ds_small,
"hillshade",
["-novalidoption"],
)
# This throws
# signal 6: Abort trap: 6
# libc++abi: terminating due to uncaught exception of type std::invalid_argument
# @test_throws GDAL.GDALError AG.unsafe_gdaldem(
# ds_small,
# "hillshade",
# ["-novalidoption"],
# )
@test_throws GDAL.GDALError AG.unsafe_gdalnearblack(
ds_small,
["-novalidoption"],
Expand All @@ -44,11 +47,14 @@ using Test
[ds_small],
["-novalidoption"],
)
@test_throws GDAL.GDALError AG.unsafe_gdaldem(
ds_small,
"hillshade",
["-novalidoption"],
)
# This throws
# signal 6: Abort trap: 6
# libc++abi: terminating due to uncaught exception of type std::invalid_argument
# @test_throws GDAL.GDALError AG.unsafe_gdaldem(
# ds_small,
# "hillshade",
# ["-novalidoption"],
# )
@test_throws GDAL.GDALError AG.unsafe_gdalnearblack(
ds_small,
["-novalidoption"],
Expand Down

0 comments on commit b6c95c1

Please sign in to comment.