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 Aqua tests and resolve method ambiguities #119

Merged
merged 9 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ julia = "1.9"

[extras]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RemoteFiles = "cbe49d4c-5af1-5b60-bb70-0a60aa018e1b"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"

[targets]
test = ["ArchGDAL", "DataFrames", "Makie", "Plots", "RemoteFiles", "ZipFile", "Test"]
test = ["ArchGDAL", "Aqua", "DataFrames", "Makie", "Plots", "RemoteFiles", "ZipFile", "Test"]
2 changes: 1 addition & 1 deletion ext/ShapefileMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GeoInterfaceMakie.@enable Shapefile.LinearRing
Makie.plottype(tbl::Shapefile.Table) = Makie.plottype(Shapefile.shapes(tbl))
Makie.plottype(shp::Shapefile.Handle) = Makie.plottype(Shapefile.shapes(shp))

for T in (Any, Union{Type{Any}, Type{<:Makie.AbstractPlot}}, Type{<:Makie.Poly}, Type{<:Makie.Lines}, Makie.PointBased)
for T in (Makie.ConversionTrait, Type{<:Makie.AbstractPlot}, Type{<:Makie.Poly}, Type{<:Makie.Lines}, Makie.PointBased)
@eval begin
Makie.convert_arguments(t::$T, tbl::Shapefile.Table) =
Makie.convert_arguments(t, Shapefile.shapes(tbl))
Expand Down
3 changes: 1 addition & 2 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ struct SubPolygon{L<:LinearRing} <: AbstractVector{L}
end
GI.isgeometry(::Type{<:SubPolygon}) = true
GI.geomtrait(::SubPolygon) = GI.PolygonTrait()
GI.is3d(::GI.PolygonTrait, p::SubPolygon) = GI.is3d(first(p))
GI.ismeasured(::GI.PolygonTrait, p::SubPolygon) = GI.measures(first(p))
GI.ncoord(::GI.PolygonTrait, ::SubPolygon{<:LinearRing{P}}) where {P} = _ncoord(P)
GI.ngeom(::GI.PolygonTrait, sp::SubPolygon) = length(sp)
# `is3d` and `ismeasured` are defined in `extents.jl`
Base.@propagate_inbounds GI.getgeom(::GI.PolygonTrait, sp::SubPolygon, i::Integer) =
getindex(sp, i)

Expand Down
22 changes: 22 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ using Shapefile
using GeoFormatTypes
using Test

import Aqua

const GI = GeoInterface

import GeoInterfaceRecipes # for ambiguity ignore list only

using Shapefile: Point, PointM, PointZ, Polygon, PolygonM, PolygonZ, Polyline,
PolylineM, PolylineZ, MultiPoint, MultiPointM, MultiPointZ,
Expand Down Expand Up @@ -133,6 +136,8 @@ test_shapes = Dict(
SubPolygon => SubPolygon([LinearRing{Point}(view(points, 1:4))]),
)

@testset "Shapefile.jl" begin
asinghvi17 marked this conversation as resolved.
Show resolved Hide resolved

@testset "GeoInterface compatibility" begin
foreach(test_shapes) do (k, s)
@test GeoInterface.testgeometry(s)
Expand Down Expand Up @@ -255,3 +260,20 @@ include("table.jl")
include("writer.jl")

cleanup()

@testset "Aqua.jl" begin
Aqua.test_all(
Shapefile;
# Exclude ambiguities from imported packages as well as GeoInterfaceRecipes,
# since the ambiguities there are not the kind that would actually cause problems.
ambiguities = (; recursive = false, exclude = [GeoInterfaceRecipes.RecipesBase.apply_recipe,]),
# GeoInterfaceRecipes and GeoInterfaceMakie are considered stale dependencies
# but are actually used in extensions on Plots and Makie respectively, so we need them!
stale_deps = (; ignore = [:GeoInterfaceRecipes, :GeoInterfaceMakie]),
# too much headache for now - will go through this again if I'm sure
# CompatHelper is working, but the tests are good flags for new versions with
# suspicious behaviour.
deps_compat = false,
)
end
end
4 changes: 2 additions & 2 deletions test/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ne_cities = Shapefile.Table(path(natural_earth, "ne_cities_shp"))
if eltype(a) <: Union{Missing, String}
# ne_cities has non-ascii characters
@test all(isequal.(
replace.(skipmissing(a), !isascii => x -> '_' ^ textwidth(x)),
skipmissing(a),#replace.(skipmissing(a), !isascii => x -> '_' ^ textwidth(x)),
skipmissing(b)
))
else
Expand Down Expand Up @@ -105,7 +105,7 @@ wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",637813
)
for r in ne_land
@test Shapefile.shape(r) isa Shapefile.Polygon
@test r.featurecla === "Land"
@test r.featurecla == "Land"
end
df_land = DataFrames.DataFrame(ne_land)
@test size(df_land) == (127, 4)
Expand Down
Loading