From 60077fca2c602ab63d6cab708c75b04e8504e85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 16 Oct 2023 14:15:10 -0400 Subject: [PATCH] refactor(gbif): use testitem --- GBIF/Project.toml | 3 +- GBIF/src/GBIF.jl | 17 ++++++ GBIF/src/occurrence.jl | 88 +++++++++++++++++++++++++++++++ GBIF/src/paging.jl | 21 ++++++++ GBIF/src/query.jl | 23 ++++++++ GBIF/src/taxon.jl | 56 +++++++++++++------- GBIF/src/types/iterators.jl | 31 ++++++++++- GBIF/test/Project.toml | 1 + GBIF/test/edgecases.jl | 13 ----- GBIF/test/iteration.jl | 19 ------- GBIF/test/methods.jl | 11 ---- GBIF/test/occurrence.jl | 22 -------- GBIF/test/occurrences.jl | 49 ----------------- GBIF/test/paging.jl | 24 --------- GBIF/test/query.jl | 19 ------- GBIF/test/querycleaning.jl | 16 ------ GBIF/test/runtests.jl | 35 +----------- GBIF/test/tables.jl | 11 ---- GBIF/test/taxon.jl | 32 ----------- src/SpeciesDistributionToolkit.jl | 2 + src/io/geotiff.jl | 3 +- 21 files changed, 225 insertions(+), 271 deletions(-) delete mode 100644 GBIF/test/edgecases.jl delete mode 100644 GBIF/test/iteration.jl delete mode 100644 GBIF/test/methods.jl delete mode 100644 GBIF/test/occurrence.jl delete mode 100644 GBIF/test/occurrences.jl delete mode 100644 GBIF/test/paging.jl delete mode 100644 GBIF/test/query.jl delete mode 100644 GBIF/test/querycleaning.jl delete mode 100644 GBIF/test/tables.jl delete mode 100644 GBIF/test/taxon.jl diff --git a/GBIF/Project.toml b/GBIF/Project.toml index e1a2fe1be..16420c410 100644 --- a/GBIF/Project.toml +++ b/GBIF/Project.toml @@ -1,13 +1,14 @@ name = "GBIF" uuid = "ee291a33-5a6c-5552-a3c8-0f29a1181037" authors = ["Timothée Poisot "] -version = "0.4.4" +version = "0.4.5" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe" [compat] HTTP = "0.8, 0.9, 1" diff --git a/GBIF/src/GBIF.jl b/GBIF/src/GBIF.jl index 1e850e6ae..6addc41ec 100644 --- a/GBIF/src/GBIF.jl +++ b/GBIF/src/GBIF.jl @@ -1,5 +1,7 @@ module GBIF +using TestItems + using HTTP using JSON using Dates @@ -78,4 +80,19 @@ include("paging.jl") export occurrence, occurrences export occurrences! +@testitem "We can use the Query package" begin + using Query + using DataFrames + t = taxon("Mammalia", strict=false) + set = occurrences(t) + [occurrences!(set) for i in 1:10] + + tdf = view(set) |> + @filter(_.rank == "SPECIES") |> + @map({_.key, _.taxon.name, _.country}) |> + DataFrame + + @test typeof(tdf) <: DataFrame +end + end # module diff --git a/GBIF/src/occurrence.jl b/GBIF/src/occurrence.jl index 4c02d7bbc..c108bb995 100644 --- a/GBIF/src/occurrence.jl +++ b/GBIF/src/occurrence.jl @@ -58,6 +58,20 @@ function occurrence(key::Integer)::GBIFRecord return occurrence(string(key)) end +@testitem "We can get an occurrence by its ID" begin + k = 3986160931 + o = occurrence(k) + @test typeof(o) == GBIFRecord + @test o.key == k +end + +@testitem "We can get a malformed occurrence" begin + k = 1039645472 + o = occurrence(k) + @test typeof(o) == GBIFRecord + @test o.key == k +end + function _internal_occurrences_getter(query::Pair...) validate_occurrence_query.(query) occ_s_url = gbifurl * "occurrence/search" @@ -112,6 +126,20 @@ function occurrences(t::GBIFTaxon, query::Pair...) return occurrences(taxon_query, query...) end +@testitem "Getting occurrences by taxon returns a GBIFRecords" begin + iver_id = taxon(5298019) + @test typeof(occurrences(iver_id)) <: GBIFRecords +end + +@testitem "Getting occurrences by taxon returns the correct taxa" begin + t = taxon(5298019) + occ = occurrences(t) + @test typeof(occ) <: GBIFRecords + for o in occ + @test o.taxon.species == Pair("Iris versicolor", 5298019) + end +end + """ occurrences(t::Vector{GBIFTaxon}, query::Pair...) @@ -126,3 +154,63 @@ function occurrences(ts::Vector{GBIFTaxon}, query::Pair...) end return occurrences(taxon_query..., query...) end + +@testitem "We get the correct country when looking for occurrences by country" begin + occ = occurrences("country" => "ES") + @test typeof(occ) <: GBIFRecords + for o in occ + @test o.country == "Spain" + end +end + +@testitem "We can pass the taxon data manually" begin +set1 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true) +@test typeof(set1) == GBIFRecords +@test length(set1) == 20 +end + +@testitem "We can get the latest occurrences" begin +set2 = occurrences() +@test typeof(set2) == GBIFRecords +@test length(set2) == 20 +end + +@testitem "We can use tuples to show intervals" begin +set3 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true, "decimalLatitude" => (0.0, 50.0)) +@test typeof(set3) == GBIFRecords +@test length(set3) == 20 +end + +@testitem "We can complete a query using a while loop" begin +serval = GBIF.taxon("Leptailurus serval", strict=true) +obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40)) +while length(obs) < count(obs) + occurrences!(obs) +end +@test length(obs) == count(obs) +end + +@testitem "We can query multiple taxa at once" begin +serval = GBIF.taxon("Leptailurus serval", strict=true) +leopard = GBIF.taxon("Panthera pardus", strict=true) +obs = occurrences([leopard, serval], "hasCoordinate" => true, "occurrenceStatus" => "PRESENT") +@test typeof(obs) == GBIFRecords +end + +@testitem "We can complete a query with a specific page size" begin +obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40), "limit" => 45) +while length(obs) < count(obs) + occurrences!(obs) +end +@test length(obs) == count(obs) +end + +@testitem "Records of absence are correctly represented" begin +o = occurrences("occurrenceStatus" => "ABSENT") +@test o[1].presence == false +end + +@testitem "Records of presence are correctly represented" begin +o = occurrences("occurrenceStatus" => "PRESENT") +@test o[1].presence == true +end diff --git a/GBIF/src/paging.jl b/GBIF/src/paging.jl index c7b1d59aa..a2a2f7130 100644 --- a/GBIF/src/paging.jl +++ b/GBIF/src/paging.jl @@ -47,3 +47,24 @@ function occurrences!(o::GBIFRecords) o.occurrences[start:stop] = retrieved end end + +@testitem "We always get one page by default" begin + set = occurrences() + occurrences!(set) + @test length(set) == 40 +end + +@testitem "We can get multiple pages on repeated calls" begin + set = occurrences("limit" => 40) + occurrences!(set) + @test length(set) == 80 + @test length(set) == length(unique([o.key for o in set])) +end + +@testitem "We can page over queries" begin + setQ = occurrences(taxon("Iris versicolor", rank=:SPECIES), "limit" => 10) + occurrences!(setQ) + @test length(setQ) == 20 + occurrences!(setQ) + @test length(setQ) == length(unique([o.key for o in setQ])) +end \ No newline at end of file diff --git a/GBIF/src/query.jl b/GBIF/src/query.jl index 2b2a8c185..e11d8fc1f 100644 --- a/GBIF/src/query.jl +++ b/GBIF/src/query.jl @@ -92,3 +92,26 @@ function validate_occurrence_query(query::Pair) end end end + +@testitem "Using a single argument does not change the type of the argument" begin + queryset = ["hasCoordinate" => true] + @test length(occurrences(queryset...)) > 0 + + queryset = ["hasCoordinate" => true] + @test length(occurrences(taxon("Alces alces"), queryset...)) > 0 +end + +@testitem "We cannot search for a wrong country code" begin + qpars = Pair("country", "ABC") + @test_warn "country code" GBIF.validate_occurrence_query(qpars) +end + +@testitem "We cannot search with an unsupported keyword" begin + qpars = Pair("years", "1234") + @test_warn "parameter is not allowed" GBIF.validate_occurrence_query(qpars) +end + +@testitem "We cannot search with an unsupported enumerated value" begin + qpars = Pair("establishmentMeans", "just vibes") + @test_warn "is not a valid value" GBIF.validate_occurrence_query(qpars) +end \ No newline at end of file diff --git a/GBIF/src/taxon.jl b/GBIF/src/taxon.jl index 66c2fbd73..38378661a 100644 --- a/GBIF/src/taxon.jl +++ b/GBIF/src/taxon.jl @@ -8,15 +8,15 @@ reference taxonomy. Optional arguments are -- `rank::Union{Symbol,Nothing}=:SPECIES` -- the rank of the taxon you want. This - is part of a controlled vocabulary, and can only be one of `:DOMAIN`, - `:CLASS`, `:CULTIVAR`, `:FAMILY`, `:FORM`, `:GENUS`, `:INFORMAL`, `:ORDER`, - `:PHYLUM,`, `:SECTION`, `:SUBCLASS`, `:VARIETY`, `:TRIBE`, `:KINGDOM`, - `:SUBFAMILY`, `:SUBFORM`, `:SUBGENUS`, `:SUBKINGDOM`, `:SUBORDER`, - `:SUBPHYLUM`, `:SUBSECTION`, `:SUBSPECIES`, `:SUBTRIBE`, `:SUBVARIETY`, - `:SUPERCLASS`, `:SUPERFAMILY`, `:SUPERORDER`, and `:SPECIES` + - `rank::Union{Symbol,Nothing}=:SPECIES` -- the rank of the taxon you want. This + is part of a controlled vocabulary, and can only be one of `:DOMAIN`, + `:CLASS`, `:CULTIVAR`, `:FAMILY`, `:FORM`, `:GENUS`, `:INFORMAL`, `:ORDER`, + `:PHYLUM,`, `:SECTION`, `:SUBCLASS`, `:VARIETY`, `:TRIBE`, `:KINGDOM`, + `:SUBFAMILY`, `:SUBFORM`, `:SUBGENUS`, `:SUBKINGDOM`, `:SUBORDER`, + `:SUBPHYLUM`, `:SUBSECTION`, `:SUBSPECIES`, `:SUBTRIBE`, `:SUBVARIETY`, + `:SUPERCLASS`, `:SUPERFAMILY`, `:SUPERORDER`, and `:SPECIES` -- `strict::Bool=true` -- whether the match should be strict, or fuzzy + - `strict::Bool=true` -- whether the match should be strict, or fuzzy Finally, one can also specify other levels of the taxonomy, using `kingdom`, `phylum`, `class`, `order`, `family`, and `genus`, all of which can either be @@ -26,17 +26,19 @@ If a match is found, the result will be given as a `GBIFTaxon`. If not, this function will return `nothing` and give a warning. """ function taxon(name::String; - rank::Union{Symbol,Nothing}=:SPECIES, strict::Bool=true, - kingdom::Union{String,Nothing}=nothing, phylum::Union{String,Nothing}=nothing, class::Union{String,Nothing}=nothing, - order::Union{String,Nothing}=nothing, family::Union{String,Nothing}=nothing, genus::Union{String,Nothing}=nothing) + rank::Union{Symbol, Nothing} = :SPECIES, strict::Bool = true, + kingdom::Union{String, Nothing} = nothing, phylum::Union{String, Nothing} = nothing, + class::Union{String, Nothing} = nothing, + order::Union{String, Nothing} = nothing, family::Union{String, Nothing} = nothing, + genus::Union{String, Nothing} = nothing) @assert rank ∈ [ :DOMAIN, :CLASS, :CULTIVAR, :FAMILY, :FORM, :GENUS, :INFORMAL, :ORDER, :PHYLUM, :SECTION, :SUBCLASS, :VARIETY, :TRIBE, :KINGDOM, :SUBFAMILY, :SUBFORM, :SUBGENUS, :SUBKINGDOM, :SUBORDER, :SUBPHYLUM, :SUBSECTION, :SUBSERIES, :SUBSPECIES, :SUBTRIBE, :SUBVARIETY, :SUPERCLASS, :SUPERFAMILY, :SUPERORDER, - :SPECIES + :SPECIES, ] - args = Dict{String,Any}("name" => name, "strict" => strict) + args = Dict{String, Any}("name" => name, "strict" => strict) isnothing(rank) || (args["rank"] = String(rank)) isnothing(kingdom) || (args["kingdom"] = String(kingdom)) @@ -47,7 +49,7 @@ function taxon(name::String; isnothing(genus) || (args["genus"] = String(genus)) sp_s_url = gbifurl * "species/match" - sp_s_req = HTTP.get(sp_s_url, query=args) + sp_s_req = HTTP.get(sp_s_url; query = args) if sp_s_req.status == 200 body = JSON.parse(String(sp_s_req.body)) # This will throw warnings for various reasons related to matchtypes @@ -78,17 +80,35 @@ This function will look for a taxon by its taxonID in the GBIF reference taxonomy. """ function taxon(id::Int) - args = Dict{String,Any}("id" => id) + args = Dict{String, Any}("id" => id) sp_s_url = gbifurl * "species/$id" - sp_s_req = HTTP.get(sp_s_url, query=args) + sp_s_req = HTTP.get(sp_s_url; query = args) if sp_s_req.status == 200 body = JSON.parse(String(sp_s_req.body)) return GBIFTaxon(body) else - throw(ErrorException("Impossible to retrieve information for taxonID $(id) -- HTML error code $(sp_s_req.status)")) + throw( + ErrorException( + "Impossible to retrieve information for taxonID $(id) -- HTML error code $(sp_s_req.status)", + ), + ) end - end taxon(t::Pair) = taxon(t.second) + +@testitem "We can get a taxon by its name" begin + iver = taxon("Iris versicolor"; rank = :SPECIES) + @test iver.species == Pair("Iris versicolor", 5298019) +end + +@testitem "We can get a taxon by its GBIF ID" begin + iver_id = taxon(5298019) + @test iver_id.species == ("Iris versicolor" => 5298019) +end + +@testitem "We do not get a species field when looking for a genus" begin + i_sp = taxon("Lamellodiscus"; rank = :GENUS, strict = true) + @test ismissing(i_sp.species) +end diff --git a/GBIF/src/types/iterators.jl b/GBIF/src/types/iterators.jl index cf41b2c7c..1c5b76a5a 100644 --- a/GBIF/src/types/iterators.jl +++ b/GBIF/src/types/iterators.jl @@ -21,6 +21,12 @@ function getindex(o::GBIFRecords, r::UnitRange{Int64}) return view(o)[r] end +@testitem "Occurrences have a length and a typeof" begin + set = occurrences() + @test typeof(set[1]) == GBIFRecord + @test length(set[1:4]) == 4 +end + function iterate(o::GBIFRecords) return iterate(collect(view(o))) end @@ -29,7 +35,30 @@ function iterate(o::GBIFRecords, t::Union{Int64, Nothing}) return iterate(collect(view(o)), t) end +@testitem "We can iterate over records" begin + set = occurrences() + @test iterate(set) == (set[1], 2) + @test iterate(set, 2) == (set[2], 3) +end + +@testitem "We can iterate over records made with a non-empty query" begin + plotor = taxon("Procyon lotor") + plotor_occ = occurrences(plotor) + occurrences!(plotor_occ) + for o in plotor_occ + @test typeof(o) <: GBIFRecord + @test o.taxon.species.second == plotor.species.second + end +end + # Tables.jl interface Tables.istable(::Type{GBIFRecords}) = true Tables.rowaccess(::Type{GBIFRecords}) = true -Tables.rows(records::GBIFRecords) = view(records) \ No newline at end of file +Tables.rows(records::GBIFRecords) = view(records) + +@testitem "We can convert records to a data frame" begin + using DataFrames + + df = DataFrame(occurrences()) + @test typeof(df) <: DataFrame +end \ No newline at end of file diff --git a/GBIF/test/Project.toml b/GBIF/test/Project.toml index 7b1419d81..cf7140671 100644 --- a/GBIF/test/Project.toml +++ b/GBIF/test/Project.toml @@ -2,3 +2,4 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a" diff --git a/GBIF/test/edgecases.jl b/GBIF/test/edgecases.jl deleted file mode 100644 index 71ee2c5e6..000000000 --- a/GBIF/test/edgecases.jl +++ /dev/null @@ -1,13 +0,0 @@ -module GBIFEdgeCasesTest -using Test -using GBIF - -# When there is a single argument used for a query, sometimes the second position gets -# converted to not text -queryset = ["hasCoordinate" => true] -@test length(occurrences(queryset...)) > 0 - -queryset = ["hasCoordinate" => true] -@test length(occurrences(taxon("Alces alces"), queryset...)) > 0 - -end diff --git a/GBIF/test/iteration.jl b/GBIF/test/iteration.jl deleted file mode 100644 index a6ac1f44a..000000000 --- a/GBIF/test/iteration.jl +++ /dev/null @@ -1,19 +0,0 @@ -module TestIteration - - using GBIF - using Test - - set = occurrences() - - @test iterate(set) == (set[1], 2) - @test iterate(set, 2) == (set[2], 3) - - plotor = taxon("Procyon lotor") - plotor_occ = occurrences(plotor) - occurrences!(plotor_occ) - for o in plotor_occ - @test typeof(o) <: GBIFRecord - @test o.taxon.species.second == plotor.species.second - end - -end diff --git a/GBIF/test/methods.jl b/GBIF/test/methods.jl deleted file mode 100644 index 14c6029bb..000000000 --- a/GBIF/test/methods.jl +++ /dev/null @@ -1,11 +0,0 @@ -module TestMethods - - using GBIF - using Test - - set = occurrences() - - @test typeof(set[1]) == GBIFRecord - @test length(set[1:4]) == 4 - -end diff --git a/GBIF/test/occurrence.jl b/GBIF/test/occurrence.jl deleted file mode 100644 index 135c8e5b7..000000000 --- a/GBIF/test/occurrence.jl +++ /dev/null @@ -1,22 +0,0 @@ -module TestOccurrence - -using GBIF -using Test - -# This occurrence exists -k = 3986160931 -o = occurrence(k) -@test typeof(o) == GBIFRecord -@test o.key == k - -# This occurrence has been deleted, so this needs some wrapping -# It has been added back at some point -# k = 1258202889 -# @test_throws "cannot be accessed - error code" occurrence(k) - -# This occurrence is incorrectly formatted for some reason -k = 1039645472 -o = occurrence(k) -@test typeof(o) == GBIFRecord - -end diff --git a/GBIF/test/occurrences.jl b/GBIF/test/occurrences.jl deleted file mode 100644 index 6af1b5de1..000000000 --- a/GBIF/test/occurrences.jl +++ /dev/null @@ -1,49 +0,0 @@ -module TestGBIFRecords - -using GBIF -using Test - -# Version using pairs -set1 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true) -@test typeof(set1) == GBIFRecords -@test length(set1) == 20 - -# Version with no query parameters -set2 = occurrences() -@test typeof(set2) == GBIFRecords -@test length(set2) == 20 - -# Version using ranged pairs -set3 = occurrences("scientificName" => "Mus musculus", "year" => 1999, "hasCoordinate" => true, "decimalLatitude" => (0.0, 50.0)) -@test typeof(set3) == GBIFRecords -@test length(set3) == 20 - -# Version with the full query - this one has about 250 records -serval = GBIF.taxon("Leptailurus serval", strict=true) -obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40)) -while length(obs) < count(obs) - occurrences!(obs) -end -@test length(obs) == count(obs) - -# Version with multiple taxa -serval = GBIF.taxon("Leptailurus serval", strict=true) -leopard = GBIF.taxon("Panthera pardus", strict=true) -obs = occurrences([leopard, serval], "hasCoordinate" => true, "occurrenceStatus" => "PRESENT") -@test typeof(obs) == GBIFRecords - -# Version with the full query AND a set page size - this one has about 250 records -obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40), "limit" => 45) -while length(obs) < count(obs) - occurrences!(obs) -end -@test length(obs) == count(obs) - -# Check ABSENT records -o = occurrences("occurrenceStatus" => "ABSENT") -@test o[1].presence == false - -o = occurrences("occurrenceStatus" => "PRESENT") -@test o[1].presence == true - -end diff --git a/GBIF/test/paging.jl b/GBIF/test/paging.jl deleted file mode 100644 index 1e7b62cdd..000000000 --- a/GBIF/test/paging.jl +++ /dev/null @@ -1,24 +0,0 @@ -module TestPaging - - using GBIF - using Test - - # No query - set = occurrences() - occurrences!(set) - @test length(set) == 40 - - # No query, different limit - set = occurrences("limit" => 40) - occurrences!(set) - @test length(set) == 80 - @test length(set) == length(unique([o.key for o in set])) - - # Query and different limit - setQ = occurrences(taxon("Iris versicolor", rank=:SPECIES), "limit" => 10) - occurrences!(setQ) - @test length(setQ) == 20 - occurrences!(setQ) - @test length(setQ) == length(unique([o.key for o in setQ])) - -end diff --git a/GBIF/test/query.jl b/GBIF/test/query.jl deleted file mode 100644 index 97e458414..000000000 --- a/GBIF/test/query.jl +++ /dev/null @@ -1,19 +0,0 @@ -module TestQuery - - using GBIF - using DataFrames - using Query - using Test - - t = taxon("Mammalia", strict=false) - set = occurrences(t) - [occurrences!(set) for i in 1:10] - - tdf = view(set) |> - @filter(_.rank == "SPECIES") |> - @map({_.key, _.taxon.name, _.country}) |> - DataFrame - - @test typeof(tdf) <: DataFrame - -end diff --git a/GBIF/test/querycleaning.jl b/GBIF/test/querycleaning.jl deleted file mode 100644 index efafea46e..000000000 --- a/GBIF/test/querycleaning.jl +++ /dev/null @@ -1,16 +0,0 @@ -module TestQuery - - using GBIF - using Test - - # Filtering with wrong parameters - qpars = Dict("country" => "ABC") - @test_warn "country code" GBIF.check_records_parameters!(qpars) - - qpars = Dict("years" => "1234") - @test_warn "not a supported field" GBIF.check_records_parameters!(qpars) - - qpars = Dict("establishmentMeans" => "LOLWUT") - @test_warn "values in establishmentMeans were invalid" GBIF.check_records_parameters!(qpars) - -end diff --git a/GBIF/test/runtests.jl b/GBIF/test/runtests.jl index bb998db4c..29a98fd89 100644 --- a/GBIF/test/runtests.jl +++ b/GBIF/test/runtests.jl @@ -1,34 +1,3 @@ -using GBIF -using Test +using TestItemRunner -global anyerrors = false - -tests = [ - "species retrieval" => "taxon.jl", - "single occurrence functions" => "occurrence.jl", - "multiple occurrences" => "occurrences.jl", - "paging" => "paging.jl", - "iteration" => "iteration.jl", - "methods" => "methods.jl", - "query support" => "query.jl", - "tables interface" => "tables.jl", - "edge cases" => "edgecases.jl", -] - -for test in tests - try - include(test.second) - println("\033[1m\033[32m✓\033[0m\t$(test.first)") - catch e - global anyerrors = true - println("\033[1m\033[31m×\033[0m\t$(test.first)") - println("\033[1m\033[38m→\033[0m\ttest/$(test.second)") - showerror(stdout, e, backtrace()) - println() - break - end -end - -if anyerrors - throw("Tests failed") -end +@run_package_tests filter=ti->!(:skipci in ti.tags) verbose=true \ No newline at end of file diff --git a/GBIF/test/tables.jl b/GBIF/test/tables.jl deleted file mode 100644 index 9d0a18fa5..000000000 --- a/GBIF/test/tables.jl +++ /dev/null @@ -1,11 +0,0 @@ -module TestDataFrames - - using GBIF - using DataFrames - using Test - - df = DataFrame(occurrences()) - - @test typeof(df) <: DataFrame - -end diff --git a/GBIF/test/taxon.jl b/GBIF/test/taxon.jl deleted file mode 100644 index 2fb41a1cc..000000000 --- a/GBIF/test/taxon.jl +++ /dev/null @@ -1,32 +0,0 @@ -module TestSpecies - - using GBIF - using Test - - iver = taxon("Iris versicolor", rank=:SPECIES) - @test iver.species == Pair("Iris versicolor", 5298019) - - iver_id = taxon(5298019) # test using taxon id - @test iver_id.species == iver.species - - @test iver_id == taxon(Pair("Iris versicolor", 5298019)) - - i_sp = taxon(iver.genus.first; rank=:GENUS, family=iver.family.first, strict=false) - @test ismissing(i_sp.species) - - @test typeof(occurrences(i_sp)) <: GBIFRecords - - iver_occ = occurrences(iver) - @test typeof(iver_occ) <: GBIFRecords - for iocc in iver_occ - @test iocc.taxon.species == Pair("Iris versicolor", 5298019) - end - - iver_occ_spain = occurrences(iver, "country" => "ES") - @test typeof(iver_occ_spain) <: GBIFRecords - for iocc in iver_occ_spain - @test iocc.taxon.species == Pair("Iris versicolor", 5298019) - @test iocc.country == "Spain" - end - -end diff --git a/src/SpeciesDistributionToolkit.jl b/src/SpeciesDistributionToolkit.jl index d2efb1161..6773a9029 100644 --- a/src/SpeciesDistributionToolkit.jl +++ b/src/SpeciesDistributionToolkit.jl @@ -1,5 +1,7 @@ module SpeciesDistributionToolkit +using TestItems + import ArchGDAL import GDAL diff --git a/src/io/geotiff.jl b/src/io/geotiff.jl index cbb0b635d..3ba47503e 100644 --- a/src/io/geotiff.jl +++ b/src/io/geotiff.jl @@ -292,8 +292,7 @@ function _write_geotiff( return _write_geotiff(file, convert.(SimpleSDMPredictor, layers); kwargs...) end -@testitem "We can write a GeoTiff file" begin - +@testitem "We can write a GeoTiff file" begin layer = SimpleSDMPredictor(RasterData(EarthEnv, LandCover); layer = 1) D = SimpleSDMLayers._inner_type(layer)