|
1 | 1 | # basic tests for ebv_download ---- |
2 | | -#check url |
3 | | -portal_down <- ebv_i_check_url('https://portal.geobon.org/api/v1/datasets') |
4 | | - |
5 | | -if(portal_down){ |
6 | | - #expect an error |
7 | | - expect_error(ebv_download(27, dir, verbose = FALSE)) |
8 | | - }else{ |
9 | | - #run 'normal' tests |
10 | | - test_that("test ebv_download ID=numeric", { |
11 | | - dir <- tempdir() |
12 | | - data <- ebv_download(27, dir, verbose = FALSE) |
13 | | - expect_true(basename(data) %in% list.files(dir)) |
14 | | - #clean |
15 | | - unlink(dir, recursive=TRUE) |
16 | | - }) |
17 | | - |
18 | | - test_that("test ebv_download ID=doi", { |
19 | | - dir <- tempdir() |
20 | | - data <- ebv_download('10.25829/f2rdp4', dir, verbose = FALSE) |
21 | | - expect_true(basename(data) %in% list.files(dir)) |
22 | | - #clean |
23 | | - unlink(dir, recursive=TRUE) |
24 | | - }) |
25 | | - |
26 | | - test_that("test ebv_download ID=title 1", { |
27 | | - dir <- tempdir() |
28 | | - data <- ebv_download('Local bird diversity (cSAR/BES-SIM)', dir, verbose = FALSE) |
29 | | - expect_true(basename(data) %in% list.files(dir)) |
30 | | - #clean |
31 | | - unlink(dir, recursive=TRUE) |
32 | | - }) |
33 | | - |
34 | | - test_that("test ebv_download ID=title 2", { |
35 | | - dir <- tempdir() |
36 | | - data <- ebv_download("Global trends in biodiversity (BES-SIM PREDICTS)", dir, verbose = FALSE) |
37 | | - expect_true(basename(data) %in% list.files(dir)) |
38 | | - #clean |
39 | | - unlink(dir, recursive=TRUE) |
40 | | - }) |
41 | | - |
42 | | - test_that("test ebv_download DOIs in download overview table", { |
43 | | - data <- ebv_download(verbose=FALSE) |
44 | | - #check col names |
45 | | - expect_equal(names(data), c("id","title","doi")) |
46 | | - #check a view DOIs |
47 | | - expect_equal(data[data$id==7, 'doi'], '10.25829/f2rdp4') |
48 | | - expect_equal(data[data$id==42, 'doi'], '10.25829/tder31') |
49 | | - expect_equal(data[data$id==28, 'doi'], '10.25829/bk5g87') |
50 | | - }) |
| 2 | +skip_if_portal_tests_unavailable <- function() { |
| 3 | + testthat::skip_on_ci() |
| 4 | + testthat::skip_if_offline() |
51 | 5 |
|
| 6 | + if (ebv_i_check_url("https://portal.geobon.org/api/v1/datasets")) { |
| 7 | + testthat::skip("EBV Data Portal API is not reachable") |
| 8 | + } |
52 | 9 | } |
53 | 10 |
|
| 11 | +test_that("test ebv_download ID=numeric", { |
| 12 | + skip_if_portal_tests_unavailable() |
| 13 | + |
| 14 | + dir <- tempdir() |
| 15 | + data <- ebv_download(27, dir, verbose = FALSE) |
| 16 | + expect_true(basename(data) %in% list.files(dir)) |
| 17 | + unlink(dir, recursive = TRUE) |
| 18 | +}) |
| 19 | + |
| 20 | +test_that("test ebv_download ID=doi", { |
| 21 | + skip_if_portal_tests_unavailable() |
| 22 | + |
| 23 | + dir <- tempdir() |
| 24 | + data <- ebv_download("10.25829/f2rdp4", dir, verbose = FALSE) |
| 25 | + expect_true(basename(data) %in% list.files(dir)) |
| 26 | + unlink(dir, recursive = TRUE) |
| 27 | +}) |
| 28 | + |
| 29 | +test_that("test ebv_download ID=title 1", { |
| 30 | + skip_if_portal_tests_unavailable() |
| 31 | + |
| 32 | + dir <- tempdir() |
| 33 | + data <- ebv_download("Local bird diversity (cSAR/BES-SIM)", dir, verbose = FALSE) |
| 34 | + expect_true(basename(data) %in% list.files(dir)) |
| 35 | + unlink(dir, recursive = TRUE) |
| 36 | +}) |
| 37 | + |
| 38 | +test_that("test ebv_download ID=title 2", { |
| 39 | + skip_if_portal_tests_unavailable() |
| 40 | + |
| 41 | + dir <- tempdir() |
| 42 | + data <- ebv_download("Global trends in biodiversity (BES-SIM PREDICTS)", dir, verbose = FALSE) |
| 43 | + expect_true(basename(data) %in% list.files(dir)) |
| 44 | + unlink(dir, recursive = TRUE) |
| 45 | +}) |
| 46 | + |
| 47 | +test_that("test ebv_download DOIs in download overview table", { |
| 48 | + skip_if_portal_tests_unavailable() |
| 49 | + |
| 50 | + data <- ebv_download(verbose = FALSE) |
| 51 | + expect_equal(names(data), c("id", "title", "doi")) |
| 52 | + expect_equal(data[data$id == 7, "doi"], "10.25829/f2rdp4") |
| 53 | + expect_equal(data[data$id == 42, "doi"], "10.25829/tder31") |
| 54 | + expect_equal(data[data$id == 28, "doi"], "10.25829/bk5g87") |
| 55 | +}) |
| 56 | + |
54 | 57 |
|
0 commit comments