Skip to content
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 27 commits into from
Aug 5, 2024
Merged

Conversation

rafaqz
Copy link
Member

@rafaqz rafaqz commented May 6, 2024

WIP conversion of all tests to use our new @test_all_implementations macro to make sure all geometries work everywhere.

@asinghvi17 I added some helpers for nicer testset titles that combine the topic and the module name.

Closes #134

(probably doesn't work currently !)

  • TODO: There is no GI.convert for features and feature collections so we cant pass features into the macro. We should add it to GeoInterface with a fallback that just converts the geometries and rewraps them with GI Feature.

Copy link
Member

@asinghvi17 asinghvi17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but every test file will have to include("helper.jl") because they're wrapped inside SafeTestsets.

test/helpers.jl Outdated Show resolved Hide resolved
test/helpers.jl Outdated Show resolved Hide resolved
test/helpers.jl Outdated Show resolved Hide resolved
test/helpers.jl Outdated Show resolved Hide resolved
test/helpers.jl Outdated
end
end
quote
for mod in (GeoInterface, ArchGDAL, GeometryBasics, LibGEOS)
Copy link
Collaborator

@skygering skygering May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to pull these out to the top of the file as a const list to make it clear which ones are tested without having to skim the whole file. Also, that way if other geometries make it into the scene we can easily add to the test.

Also, do we want the GeoInterface conversion to be tuples? Or do we not care about the point type here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move it up. Hopefully the point type doesn't matter much...

Copy link
Collaborator

@skygering skygering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad we have this. In a few places I was trying to make examples of different types of geometries to test this. It is nice that this is automated now.

@rafaqz
Copy link
Member Author

rafaqz commented May 15, 2024

@asinghvi17
Copy link
Member

I can deal with the GeometryBasics stuff today, will push a change to the CI to use that branch once I have.

@asinghvi17
Copy link
Member

Looks like the distance test failures are because GB and AG polygons hold LineStringTraits, whereas LG and GI polygons hold LinearRingTraits.

@rafaqz
Copy link
Member Author

rafaqz commented May 16, 2024

@asinghvi17 do you want to update the barycentric tests with @test_all_implementations? none of the geometries have variable names yet to pass to the macro, and you will probably do that naming in a more sensible way than me

@asinghvi17
Copy link
Member

Sure, will push it up in a bit.

@felixcremer
Copy link
Member

 we finally have a big test suite to throw at everything and a way to do it easily :D

Does this mean we should add GeometryOps as reverse dependency test to these other packages?

@rafaqz
Copy link
Member Author

rafaqz commented May 17, 2024

Maybe at some stage. We could add an env var to only test one package

Comment on lines 159 to 166
@test_all_implementations (g1, g2) begin
if swap_points
g1, g2 = g2, g1
sg1, sg2 = sg2, sg1
end
go_val = GO_f(g1, g2)
lg_val = LG_f(g1, g2)
@test go_val == lg_val
go_val != lg_val && println("\n↑ TEST INFO: $sg1 $f_name $sg2 - $sdesc \n\n")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is killing test logs - it is literally impossible to read them because of the number of testsets. There must be a better way to handle this case - maybe using an external loop over the modules instead of an internal one over the geometries?

Copy link
Member Author

@rafaqz rafaqz Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inverting the loop wont change the amount of printing as its in the middle already/either way.

I think we instead need to remove that line? Maybe we could make it a testset instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the printing is an issue because as we fix the test cases, those will naturally fix themselves. I guess the problem is that each case has an individual testset - we should change that so that each module just runs all the test cases instead.

Maybe in this case we could use an explicit loop instead of the macro?

asinghvi17 added a commit that referenced this pull request Jun 11, 2024
rafaqz pushed a commit that referenced this pull request Jun 11, 2024
* Move types to a new `types.jl` file

so they are more accessible and general

* Add GEOSCorrection and LibGEOSExt

* Minor fixes

* Write out stubs for not-yet-implemented functions

* Implement `GEOS` algorithm

* Update ext/GeometryOpsLibGEOSExt/segmentize.jl

* switch from typed keys to no keys

* fix erroneous typing in buffer

* add test skeleton + move enforce to GO proper

* Switch to SafeTestsets for tests

This is meant to assure that conflicts in e.g. polygon definitions are avoided, and that tests are immediately runnable as files.

* Test segmentize properly

* Apply suggestions from code review

* Fix tests

* Allow LibGEOS to perform natural conversion on DE-9IM and poly set ops

* Describe exactly why the filter statement exists in the extension

* Remove GEOS correction (not working yet)

* Add TopologyPreserve simplification method

* Add a basic comment to not_implemented_yet.jl

* Add a "default" implementation for buffer that returns GO geoms

* Switch back to explicit conversion to LG in all simple overrides

* Fix incorrect references

* Add Downloads and NaturalEarth to the test env

* Fix primitive tests

* Add a hack for LibGEOS geometrycollection conversion

* Fix accidental swapping in x and y in test

* Add overlaps testing for GEOS

* Bump version to v0.1.7 (#150)

* Set compat for LibGEOS to be after the GeometryCollection patch

* Force `simplify` to always be called with GEOS() for GEOS functions

* Go back to regular testsets from SafeTestsets

* Revert the geom relations tests for #135

* Get simplify working as well

* Activate the LibGEOS listed tests

* Fix the segmentize test

* Fix buffer
test/helpers.jl Outdated Show resolved Hide resolved
@asinghvi17
Copy link
Member

I'm going to make a PR that changes the implementation to be a custom @test instead of a custom @testset

@rafaqz
Copy link
Member Author

rafaqz commented Aug 2, 2024

@asinghvi17 did you end up working on this? otherwise I can finish it

@asinghvi17
Copy link
Member

I am currently on the road so haven't got anything done...go for it! Are you doing this in the a and b list generators?

@rafaqz
Copy link
Member Author

rafaqz commented Aug 2, 2024

not sure you mean by a and b list generators...

@rafaqz
Copy link
Member Author

rafaqz commented Aug 2, 2024

Do you know if there is a macro utility other packages use to walk the AST and replace $var with var, and make a vars list at the same time?

It seems like a generic thing someone has written

Oops the parser actualy does that! Not sure how we can get interpolated variables to do the conversion step.

@asinghvi17
Copy link
Member

Oops, somehow I confused this for the other issue. I did a bit of work on this, will push it tomorrow!

@asinghvi17
Copy link
Member

asinghvi17 commented Aug 2, 2024

BenchmarkTools probably has something for the var stuff

@rafaqz
Copy link
Member Author

rafaqz commented Aug 2, 2024

Ok BenchmarkTools quasiquote! is what we want:

https://github.com/JuliaCI/BenchmarkTools.jl/blob/cb09e406b84c6a75f257e2b8dbec7fa4f8b8aca5/src/execution.jl#L361-L380

Its small enough to just copy/paste

@rafaqz rafaqz marked this pull request as ready for review August 4, 2024 00:41
@rafaqz
Copy link
Member Author

rafaqz commented Aug 4, 2024

This should be good to go.

I think I've made the printing a bunch shorter. But its still mostly the @testset_implements macro as doing this in a @test_implements macro doesn't really work - the geoms are used in the shared setup code.

I've also actually used SafeTestsets.jl (we depended on it but didnt use it) and updated everything for that.

One thought I have is we should show wherever we are manually skipping packages - like maybe print a warning about it?

@asinghvi17
Copy link
Member

asinghvi17 commented Aug 5, 2024

I guess I'm not totally clear on where the setup code needs to be package specific?

I've also actually used SafeTestsets.jl (we depended on it but didnt use it) and updated everything for that.

👍

One thought I have is we should show wherever we are manually skipping packages - like maybe print a warning about it?

What defines "skipping packages"? E.g. GeometryBasics doesn't support geometrycollections out of the box...

Similarly I don't think there's infrastructure to convert to Shapefile geoms, or GeoJSON geoms. Are we implicitly skipping those?

One thought I had was to define e.g. GI.convert(ClockwiseExteriorWindingOrder, geom) to enable us to test winding order, closed vs unclosed rings, etc. That can probably go in another PR though.


export @test_implementations, @testset_implementations

const TEST_MODULES = [GeoInterface, ArchGDAL, GeometryBasics, LibGEOS]
Copy link
Member

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?

@asinghvi17
Copy link
Member

Overall, aside from those comments, I think we should merge!

Copy link
Member

@asinghvi17 asinghvi17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sold!

@rafaqz
Copy link
Member Author

rafaqz commented Aug 5, 2024

By skipping I mean manually passing a subset of the defaults - so we would notify about skips by just getting the setdiff of the passed modules and the standard ones and putting it in @warn. But that can be later.

@rafaqz rafaqz merged commit 266454d into main Aug 5, 2024
5 of 6 checks passed
@rafaqz rafaqz deleted the test_all_implementations branch August 5, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test all available geometry sources
4 participants