-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add macro to test all implementations #135
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e12b1e5
add macro to test all implementations
rafaqz 7a1159c
few more
rafaqz eb76c60
Apply suggestions from code review
asinghvi17 bbdedfd
Double interpolation to escape quotenode
asinghvi17 edb37df
mostly passing
rafaqz 81577e5
Eval in missing GeometryBasics methods
asinghvi17 0c5c889
Add a few more GB methods + comments
asinghvi17 270d660
Add LibGEOS geometry collection constructor
asinghvi17 f46f8dd
Add Downloads to Project
asinghvi17 cb5320f
fix reproject test
rafaqz 49a9d32
test most of the rest
rafaqz 25af6ce
fix macro names
rafaqz 98cf808
more tests
rafaqz 2772248
fix macro inputs
rafaqz 3cbc3bb
Update barycentric.jl
asinghvi17 4b1e87b
put string in testset name
rafaqz 189c30b
mls
rafaqz a3af803
mostly passing
rafaqz 3d7e4d2
Merge branch 'main' into test_all_implementations
asinghvi17 af838d6
Merge branch 'main' into test_all_implementations
asinghvi17 0f94b72
Remove LibGEOS eval
asinghvi17 5a8bdc5
Merge branch 'main' into test_all_implementations
asinghvi17 8fec1b1
Merge branch 'main' into test_all_implementations
rafaqz 5312099
new macros
rafaqz 738e9cd
refactor tests
rafaqz 483dd65
bugfix title
rafaqz c1f6433
Merge branch 'main' into test_all_implementations
asinghvi17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import GeometryOps as GO, GeoInterface as GI | ||
using FlexiJoins, DataFrames | ||
using Test | ||
using FlexiJoins | ||
using DataFrames | ||
import GeometryOps as GO | ||
import GeoInterface as GI | ||
using ..TestHelpers | ||
|
||
points = GI.MultiPoint(tuple.(rand(100), rand(100))) | ||
|
||
pl = GI.Polygon([GI.LinearRing([(0, 0), (1, 0), (1, 1), (0, 0)])]) | ||
pu = GI.Polygon([GI.LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)])]) | ||
poly_df = DataFrame(geometry = [pl, pu], color = [:red, :blue]) | ||
|
||
points = tuple.(rand(100), rand(100)) | ||
points_df = DataFrame(geometry = points) | ||
|
||
@testset "Basic integration" begin | ||
|
||
@test_nowarn joined_df = FlexiJoins.innerjoin((poly_df, points_df), by_pred(:geometry, GO.contains, :geometry)) | ||
@testset_implementations "Polygon DataDrame" begin | ||
points_df = DataFrame(geometry=collect(GI.getpoint($points))) | ||
poly_df = DataFrame(geometry=[$pl, $pu], color=[:red, :blue]) | ||
# Test that the join happened correctly | ||
joined_df = FlexiJoins.innerjoin((poly_df, points_df), by_pred(:geometry, GO.contains, :geometry)) | ||
@test all(GO.contains.((pl,), joined_df.geometry_1[joined_df.color .== :red])) | ||
@test all(GO.contains.((pu,), joined_df.geometry_1[joined_df.color .== :blue])) | ||
@test all(GO.contains.(($pl,), joined_df.geometry_1[joined_df.color .== :red])) | ||
@test all(GO.contains.(($pu,), joined_df.geometry_1[joined_df.color .== :blue])) | ||
# Test that within also works | ||
@test_nowarn joined_df = FlexiJoins.innerjoin((points_df, poly_df), by_pred(:geometry, GO.within, :geometry)) | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
module TestHelpers | ||
|
||
using Test, GeoInterface, ArchGDAL, GeometryBasics, LibGEOS | ||
|
||
export @test_implementations, @testset_implementations | ||
|
||
const TEST_MODULES = [GeoInterface, ArchGDAL, GeometryBasics, LibGEOS] | ||
|
||
# Monkey-patch GeometryBasics to have correct methods. | ||
# TODO: push this up to GB! | ||
|
||
@eval GeometryBasics begin | ||
# MultiGeometry ncoord implementations | ||
GeoInterface.ncoord(::GeoInterface.MultiPolygonTrait, ::GeometryBasics.MultiPolygon{N}) where N = N | ||
GeoInterface.ncoord(::GeoInterface.MultiLineStringTrait, ::GeometryBasics.MultiLineString{N}) where N = N | ||
GeoInterface.ncoord(::GeoInterface.MultiPointTrait, ::GeometryBasics.MultiPoint{N}) where N = N | ||
# LinearRing and LineString confusion | ||
GeometryBasics.geointerface_geomtype(::GeoInterface.LinearRingTrait) = LineString | ||
function GeoInterface.convert(::Type{LineString}, ::GeoInterface.LinearRingTrait, geom) | ||
return GeoInterface.convert(LineString, GeoInterface.LineStringTrait(), geom) # forward to the linestring conversion method | ||
end | ||
# Line interface | ||
GeometryBasics.geointerface_geomtype(::GeoInterface.LineTrait) = Line | ||
function GeoInterface.convert(::Type{Line}, ::GeoInterface.LineTrait, geom) | ||
p1, p2 = GeoInterface.getpoint(geom) | ||
return Line(GeoInterface.convert(Point, GeoInterface.PointTrait(), p1), GeoInterface.convert(Point, GeoInterface.PointTrait(), p2)) | ||
end | ||
# GeometryCollection interface - currently just a large Union | ||
const _ALL_GB_GEOM_TYPES = Union{Point, Line, LineString, Polygon, MultiPolygon, MultiLineString, MultiPoint} | ||
GeometryBasics.geointerface_geomtype(::GeoInterface.GeometryCollectionTrait) = Vector{_ALL_GB_GEOM_TYPES} | ||
function GeoInterface.convert(::Type{Vector{_ALL_GB_GEOM_TYPES}}, ::GeoInterface.GeometryCollectionTrait, geoms) | ||
return _ALL_GB_GEOM_TYPES[GeoInterface.convert(GeometryBasics, g) for g in GeoInterface.getgeom(geoms)] | ||
end | ||
end | ||
|
||
|
||
# Macro to run a block of `code` for multiple modules, | ||
# using GeoInterface.convert for each var in `args` | ||
macro test_implementations(code::Expr) | ||
_test_implementations_inner(TEST_MODULES, code) | ||
end | ||
macro test_implementations(modules::Union{Expr,Vector}, code::Expr) | ||
_test_implementations_inner(modules, code) | ||
end | ||
|
||
function _test_implementations_inner(modules::Union{Expr,Vector}, code::Expr) | ||
vars = Dict{Symbol,Symbol}() | ||
code1 = _quasiquote!(code, vars) | ||
modules1 = modules isa Expr ? modules.args : modules | ||
tests = Expr(:block) | ||
|
||
for mod in modules1 | ||
expr = Expr(:block) | ||
for (var, genkey) in pairs(vars) | ||
push!(expr.args, :($genkey = $GeoInterface.convert($mod, $var))) | ||
end | ||
push!(expr.args, :(@test $code1)) | ||
push!(tests.args, expr) | ||
end | ||
|
||
return esc(tests) | ||
end | ||
|
||
# Macro to run a block of `code` for multiple modules, | ||
# using GeoInterface.convert for each var in `args` | ||
macro testset_implementations(code::Expr) | ||
_testset_implementations_inner("", TEST_MODULES, code) | ||
end | ||
macro testset_implementations(arg, code::Expr) | ||
if arg isa String || arg isa Expr && arg.head == :string | ||
_testset_implementations_inner(arg, TEST_MODULES, code) | ||
else | ||
_testset_implementations_inner("", arg, code) | ||
end | ||
end | ||
macro testset_implementations(title, modules::Union{Expr,Vector}, code::Expr) | ||
_testset_implementations_inner(title, modules, code) | ||
end | ||
|
||
function _testset_implementations_inner(title, modules::Union{Expr,Vector}, code::Expr) | ||
vars = Dict{Symbol,Symbol}() | ||
code1 = _quasiquote!(code, vars) | ||
modules1 = modules isa Expr ? modules.args : modules | ||
testsets = Expr(:block) | ||
|
||
for mod in modules1 | ||
expr = Expr(:block) | ||
for (var, genkey) in pairs(vars) | ||
push!(expr.args, :($genkey = $GeoInterface.convert($mod, $var))) | ||
end | ||
label = title == "" ? "$mod" : "$title: $mod" | ||
push!(expr.args, :(@testset $label $code1)) | ||
push!(testsets.args, expr) | ||
end | ||
|
||
return esc(testsets) | ||
end | ||
|
||
# Taken from BenchmarkTools.jl | ||
_quasiquote!(ex, vars) = ex | ||
function _quasiquote!(ex::Expr, vars::Dict) | ||
if ex.head === :($) | ||
v = ex.args[1] | ||
gen = if v isa Symbol | ||
haskey(vars, v) ? vars[v] : gensym(v) | ||
else | ||
gensym() | ||
end | ||
vars[v] = gen | ||
return v | ||
elseif ex.head !== :quote | ||
for i in 1:length(ex.args) | ||
ex.args[i] = _quasiquote!(ex.args[i], vars) | ||
end | ||
end | ||
return ex | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be configurable by Preferences.jl or an env variable?