Skip to content

Commit

Permalink
bug fix: check if portal website is online
Browse files Browse the repository at this point in the history
  • Loading branch information
LuiseQuoss committed Jul 10, 2024
1 parent 9634a0f commit e81af6f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ebvcube 0.2.2
## Bug fixes
- edit test file for ebv_download: make sure the portal website is up

# ebvcube 0.2.1
## Bug fixes
- remove old url of codecov from badge
Expand Down
48 changes: 33 additions & 15 deletions tests/testthat/test-download.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
# basic tests for ebv_download ----
test_that("test ebv_download ID=numeric", {
dir <- tempdir()
data <- ebv_download(27, dir, verbose = FALSE)
expect_true(basename(data) %in% list.files(dir))
})
#check URL
invalid_url <- function(url_in,t=2){
con <- url(url_in)
check <- suppressWarnings(try(open.connection(con,open="rt",timeout=t),silent=T)[1])
suppressWarnings(try(close.connection(con),silent=T))
ifelse(is.null(check),FALSE,TRUE)
}

portal_down <- invalid_url('https://portal.geobon.org/api/v1/datasets')

if(portal_down){
#expect an error
expect_error(ebv_download(27, dir, verbose = FALSE))
}else{
#run 'normal' tests
test_that("test ebv_download ID=numeric", {
dir <- tempdir()
data <- ebv_download(27, dir, verbose = FALSE)
expect_true(basename(data) %in% list.files(dir))
})

test_that("test ebv_download ID=doi", {
dir <- tempdir()
data <- ebv_download('10.25829/f2rdp4', dir, verbose = FALSE)
expect_true(basename(data) %in% list.files(dir))
})

test_that("test ebv_download ID=title", {
dir <- tempdir()
data <- ebv_download('Local bird diversity (cSAR/BES-SIM)', dir, verbose = FALSE)
expect_true(basename(data) %in% list.files(dir))
})
}

test_that("test ebv_download ID=doi", {
dir <- tempdir()
data <- ebv_download('10.25829/f2rdp4', dir, verbose = FALSE)
expect_true(basename(data) %in% list.files(dir))
})

test_that("test ebv_download ID=title", {
dir <- tempdir()
data <- ebv_download('Local bird diversity (cSAR/BES-SIM)', dir, verbose = FALSE)
expect_true(basename(data) %in% list.files(dir))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-ebv_manipulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ test_that("test ebv_create, ebv_add_data and ebv_attribute", {
#write tif to netCDF
ebv_add_data(filepath = file, datacubepath = 'scenario_3/metric_2/ebv_cube',
entity=1,timestep=1:3, band = 1:3,
data=temprast, verbose=FALSE)
data=temprast, verbose=FALSE, ignore_RAM = TRUE)
data <- ebv_read(file, 'scenario_3/metric_2/ebv_cube',1,1:3, 'a', verbose=FALSE)
expect_equal(data[90,180,3], array[90,180,3])
expect_equal(data[90,80,2], array[90,80,2])
Expand Down

0 comments on commit e81af6f

Please sign in to comment.