tests/testthat/test-fetchNASISLabData.R

context("fetchNASISLabData() -- requires local NASIS and ODBC connection")

## helper functions used to skip tests that rely on special conditions
# http://r-pkgs.had.co.nz/tests.html
#
# * NASIS on the local machine
# * pedons / component missing from local database



check_local_NASIS_labdata_available <- function() {

  # attempt to load pedons
  res <- try(suppressWarnings(fetchNASISLabData(SS = FALSE)), silent = TRUE)
  if (inherits(res, 'try-error')) {
    skip("no NCSS Lab Data in local NASIS database")
  }
}


## tests

test_that("fetchNASISLabData returns reasonable data", {

  # test for conditions permitting this test to run
  if(!local_NASIS_defined()) {
    skip("local NASIS database not available")
  }

  # test for lab data to check
  check_local_NASIS_labdata_available()

  # get data
  # ignore warnings for now
  x <- suppressWarnings(fetchNASISLabData(SS = FALSE))

  # expected outcomes
  expect_true(inherits(x, 'SoilProfileCollection'))
  expect_equal(nrow(site(x)) > 0, TRUE)
  expect_equal(nrow(horizons(x)) > 0, TRUE)
  expect_equal(idname(x), 'labpeiid')
  expect_equal(hzidname(x), 'labphiid')
  expect_equal(horizonDepths(x), c("hzdept", "hzdepb"))
})

Try the soilDB package in your browser

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

soilDB documentation built on June 22, 2024, 9:53 a.m.