Skip to content

Commit

Permalink
Testing spatial functions in global.R (#90)
Browse files Browse the repository at this point in the history
* Code to generate link in processing #87

* Renames Establishment means earlier in workflow to remove processing in server.R

* Moved renaming of voucher location to repository to earlier workflow and out of server. Removed creation of URL from server and directly using link field.

* Suppressed warnings from APCalign #87

* Removed URL creaton in downloadhandler

* Small test for load_places

* Specifying dependencies and simple test for circle

* Updated snapshot

* Tests for spatial functions in infinitylists

* Test and code to fail gracefully #91
  • Loading branch information
fontikar authored Mar 1, 2024
1 parent 32fedc6 commit 3ca4e11
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ check_and_download_update <- function() {
"infinitylists",
"/releases/latest"
)

# Simulate network down
network_down <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE))

if(httr::http_error(url)| network_down){
message("No internet connection or data source down, try again later")
return(NULL)
}
response <- httr::GET(url)
release_data <-
jsonlite::fromJSON(httr::content(response, "text"))
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-galah_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ test_that("Download exceutes", {
expect_named(odonata)
expect_s3_class(odonata, "tbl_df")
})


test_that("Fails gracefully", {
# in my tests
Sys.setenv("NETWORK_UP" = TRUE)
expect_message(check_and_download_update())
})
49 changes: 49 additions & 0 deletions tests/testthat/test-spatial-global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
test_that("Loading a place successfully", {
places <- list.files(system.file(package = "infinitylists", "extdata", "places"))
paths <- file.path(system.file(package = "infinitylists", "extdata", "places", places))

kmls <- purrr::map(paths,
~load_place(.x)
)

expect_visible(purrr::map(paths,
~load_place(.x))
)

expect_type(kmls[[1]], "list")

expect_visible(places)
expect_type(places, "character")
})


test_that("Circle or buffer is added", {
# malabar
radii <- seq(10,100, by = 10)

expect_visible(purrr::map(radii,
~create_circle_polygon(lat = 33.9679, long = 151.2511, .x)
))

with_circles <- purrr::map(radii,
~create_circle_polygon(lat = 33.9679, long = 151.2511, .x)
)
expect_type(with_circles[[1]], "list")

expect_error(add_buffer(with_circles, 5))
})

test_that("Intersections are working", {
occ <- dplyr::tibble(lat = 33.9679, long = 151.2511)
occ_sf <- sf::st_as_sf(occ, coords = c("long", "lat"), crs = 4326)

expect_true(points_in_target(occ_sf, create_circle_polygon(lat = 33.9679, long = 151.2511, 10)))

expect_true(points_in_buffer(occ_sf, create_circle_polygon(lat = 33.9679, long = 151.2511, 10), buffer_size = 10))
})






0 comments on commit 3ca4e11

Please sign in to comment.