tests/testthat/test-gbifRetriever.R

context("Testing gbifRetriever")

library(occCite)

test_that("gbifRetriever behaves as expected", {
  skip_on_cran()
  test <- try(rgbif::occ_count(country = "DK"),
              silent = T
  )
  skip_if(class(test) != "numeric", "GBIF connection unsuccessful")

  oldwd <- getwd()
  on.exit(setwd(oldwd))
  setwd(dir = system.file("extdata/", package = "occCite"))
  taxon <- "Protea cynaroides"

  testResult <- occCite:::gbifRetriever(taxon)

  expect_equal(class(testResult), "list")
  expect_equal(class(testResult[[1]]), "data.frame")
  expect_equal(names(testResult)[[1]], "OccurrenceTable")
  expect_equal(class(testResult[[2]]), "occ_download_meta")
  expect_equal(names(testResult)[[2]], "Metadata")
  expect_equal(class(testResult[[3]]), "occ_download_get")
  expect_equal(names(testResult)[[3]], "RawOccurrences")
})

test_that("gbifRetriever warns when there's no internet connection", {
  skip_on_cran()
  test <- try(rgbif::occ_count(country = "DK"),
              silent = T
  )
  skip_if(is(test, "numeric"), "GBIF connection successful")

  oldwd <- getwd()
  on.exit(setwd(oldwd))
  setwd(dir = system.file("extdata/", package = "occCite"))
  taxon <- "Protea cynaroides"

  expect_warning(occCite:::gbifRetriever())
  expect_warning(occCite:::gbifRetriever(taxon))
})

Try the occCite package in your browser

Any scripts or data that you put into this service are public.

occCite documentation built on Aug. 5, 2022, 5:09 p.m.