Skip to content

Commit

Permalink
Fixes to tests to avoid deprecated functions
Browse files Browse the repository at this point in the history
- remove `without_internet()` which calls `with_mock`, which is deprecated
- remove `httptest2` from Suggests
- remove unused `with_mock_dir()` calls
  • Loading branch information
mjwestgate committed Nov 16, 2023
1 parent b1fb9c3 commit d426cbe
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 123 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Imports:
Suggests:
covr,
gt,
httptest2,
kableExtra,
knitr,
magrittr,
Expand Down
5 changes: 3 additions & 2 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ build_taxa_query <- function(ids) {
list(taxonKey = ids)
}else{
wrapped_ids <- paste0("\"", ids, "\"")
id_tag <- "lsid"
glue(
"(lsid:",
"({id_tag}:",
glue_collapse(wrapped_ids,
sep = glue(" OR lsid:")),
sep = glue(" OR {id_tag}:")),
")")
}
}
Expand Down
16 changes: 5 additions & 11 deletions R/collect_taxa.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,10 @@ collect_taxa_la <- function(.query){
clean_la_taxa(search_terms = search_terms) |>
bind_rows()
if(ncol(result) > 1){
atlas <- pour("atlas", "region")
if(atlas == "France") {
name <- c("referenceID")
} else {
if (atlas == "Portugal") {
name <- c("usageKey")
} else {
name <- c("guid")
}
}
name <- switch(pour("atlas", "region"),
"France" = "referenceID",
"Portugal" = "usageKey",
"guid")
result <- result |>
filter(!duplicated({{name}})) |>
mutate("search_term" = search_terms, .before = 1)
Expand Down Expand Up @@ -104,7 +98,7 @@ clean_la_taxa <- function(result, search_terms){
list_of_results <- list(a)
}
}

# find best string match to search term
if (length(list_of_results) > 1) { # i.e. more than one match
if ("name" %in% list_of_results[[1]]) {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(testthat)
library(galah)
library(httptest2)

galah_config(directory = tempdir(),
email = "ala4r@ala.org.au",
caching = FALSE,
Expand Down
76 changes: 0 additions & 76 deletions tests/testthat/_snaps/galah_identify.md

This file was deleted.

1 change: 0 additions & 1 deletion tests/testthat/setup.R

This file was deleted.

6 changes: 0 additions & 6 deletions tests/testthat/test-atlas_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ test_that("atlas_counts filters correctly with galah_geolocate/galah_polygon", {
skip_if_offline()
wkt <- "POLYGON ((146.5425 -42.63203, 146.8312 -43.13203, 147.4085 -43.13203, 147.6972 -42.63203, 147.4085 -42.13203, 146.8312 -42.13203, 146.5425 -42.63203))" |>
sf::st_as_sfc()
with_mock_dir("galah_identify", {
identify <- galah_identify("Perameles")
})
base_query <- galah_call() |>
identify("Perameles") |>
filter(year >= 2020) |>
Expand All @@ -132,9 +129,6 @@ test_that("atlas_counts filters correctly with galah_geolocate/galah_bbox", {
skip_if_offline()
wkt <- "POLYGON ((146.5425 -42.63203, 146.8312 -43.13203, 147.4085 -43.13203, 147.6972 -42.63203, 147.4085 -42.13203, 146.8312 -42.13203, 146.5425 -42.63203))" |>
sf::st_as_sfc()
with_mock_dir("galah_identify", {
identify <- galah_identify("Perameles")
})
base_query <- galah_call() |>
identify("Perameles") |>
filter(year >= 2020) |>
Expand Down
42 changes: 19 additions & 23 deletions tests/testthat/test-atlas_occurrences.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
without_internet({
test_that("atlas_occurrences fails nicely if no email is provided", {
galah_config(email = "", run_checks = FALSE)
expect_error({
galah_call() |>
filter(year == 1900) |>
compute()
})
galah_config(email = "ala4r@ala.org.au", run_checks = TRUE)
test_that("atlas_occurrences fails nicely if no email is provided", {
galah_config(email = "", run_checks = FALSE)
expect_error({
galah_call() |>
filter(year == 1900) |>
compute()
})
galah_config(email = "ala4r@ala.org.au", run_checks = TRUE)
})

test_that("atlas_occurrences doesn't allow large downloads", {
Expand All @@ -25,20 +23,18 @@ test_that("atlas_occurrences gives a nice error for invalid emails", {
galah_config(email = "ala4r@ala.org.au")
})

without_internet({
test_that("collapse(type = 'occurrences') creates an object, but doesn't ping an API", {
result <- galah_call() |>
identify("Perameles") |>
collapse()
expect_equal(length(result), 4)
expect_true(inherits(result, "query_set"))
types <- unlist(lapply(result, function(a){a$type}))
expect_equal(types,
c("metadata/fields",
"metadata/reasons",
"metadata/taxa-single",
"data/occurrences"))
})
test_that("collapse(type = 'occurrences') creates an object, but doesn't ping an API", {
result <- galah_call() |>
identify("Perameles") |>
collapse()
expect_equal(length(result), 4)
expect_true(inherits(result, "query_set"))
types <- unlist(lapply(result, function(a){a$type}))
expect_equal(types,
c("metadata/fields",
"metadata/reasons",
"metadata/taxa-single",
"data/occurrences"))
})

test_that("`compute(type = 'occurrences')` works", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-international-Brazil.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test_that("search_all(taxa) works for Brazil", {
skip_if_offline()
x <- search_all(taxa, "Mammalia")
# Just a side note:
# Searching on the brazilian atlas is pretty unpredictable.
# Searching on the Brazilian atlas is pretty unpredictable.
# e.g. "Animalia" & "Mammalia" do not return results in search
# "Fungi" returns a Candelaria species, rather than the kingdom
expect_gte(nrow(x), 1)
Expand Down

0 comments on commit d426cbe

Please sign in to comment.