From bcb76c398329a964cab0ca14cc8c294bcf4fe46b Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Fri, 15 Jan 2021 18:40:58 -0800 Subject: [PATCH] Use testthat::skip_on_cran #155; closes #127 --- R/AAAA.R | 52 ++++----- tests/testthat/test-OSDquery.R | 30 ++--- tests/testthat/test-ROSETTA.R | 113 +++++++++--------- tests/testthat/test-SDA_query.R | 48 ++------ tests/testthat/test-fetchKSSL.R | 134 +++++++++------------- tests/testthat/test-fetchNASIS.R | 6 +- tests/testthat/test-fetchNASISWebReport.R | 74 +++++------- tests/testthat/test-fetchOSD.R | 102 ++++++---------- tests/testthat/test-fetchSCAN.R | 30 ++--- tests/testthat/test-fetchSDA_component.R | 44 +++---- tests/testthat/test-fetchSDA_spatial.R | 14 +-- tests/testthat/test-fetchSoilGrids.R | 34 +++--- tests/testthat/test-siblings.R | 34 +++--- 13 files changed, 275 insertions(+), 440 deletions(-) diff --git a/R/AAAA.R b/R/AAAA.R index 45a45c2e8..425ac532e 100644 --- a/R/AAAA.R +++ b/R/AAAA.R @@ -1,27 +1,25 @@ - -# setup a new environment to store error messages, etc. -soilDB.env <- new.env(hash=TRUE, parent = parent.frame()) - -# safely register some options at package load time -.onLoad <- function(libname, pkgname) { - - ## TODO: normalize these option names - # set to FALSE at CRAN submission time: do not test APIs, this protects from API failures - # set to TRUE for testing non-NASIS components on machines that don't have local ODBC connection setup - options(.soilDB_testNetworkFunctions=TRUE) - - # function verbosity - options(soilDB.verbose=FALSE) - - # set default local nasis authentication - options(soilDB.NASIS.credentials="DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y") - - # update according to win 7 or 10 - si <- Sys.info() - if( grepl('windows', si['sysname'], ignore.case = TRUE) & grepl('8|10', si['release'], ignore.case = TRUE) ) { - options(soilDB.NASIS.credentials="DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y365") - } -} - - - + +# setup a new environment to store error messages, etc. +soilDB.env <- new.env(hash=TRUE, parent = parent.frame()) + +# safely register some options at package load time +.onLoad <- function(libname, pkgname) { + + # deprecated: soilDB 2.5.9 CRAN release + options(.soilDB_testNetworkFunctions=TRUE) + + # function verbosity + options(soilDB.verbose=FALSE) + + # set default local nasis authentication + options(soilDB.NASIS.credentials="DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y") + + # update according to win 7 or 10 + si <- Sys.info() + if( grepl('windows', si['sysname'], ignore.case = TRUE) & grepl('8|10', si['release'], ignore.case = TRUE) ) { + options(soilDB.NASIS.credentials="DSN=nasis_local;UID=NasisSqlRO;PWD=nasisRe@d0n1y365") + } +} + + + diff --git a/tests/testthat/test-OSDquery.R b/tests/testthat/test-OSDquery.R index 6c1ad4142..9bd74d4a9 100644 --- a/tests/testthat/test-OSDquery.R +++ b/tests/testthat/test-OSDquery.R @@ -1,38 +1,30 @@ context("OSDquery() -- requires internet connection") test_that("OSDquery() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # a message is printed and NULL returned when no results res <- suppressMessages(OSDquery(geog_assoc_soils = 'pardee')) - + # standard request expect_true(inherits(res, 'data.frame')) - + }) test_that("OSDquery() returns NULL with bogus query", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # a message is printed and NULL returned when no results res <- suppressMessages(OSDquery(geog_assoc_soils = 'XXX')) expect_null(res) - + }) diff --git a/tests/testthat/test-ROSETTA.R b/tests/testthat/test-ROSETTA.R index a9d358f85..a5cc20efe 100644 --- a/tests/testthat/test-ROSETTA.R +++ b/tests/testthat/test-ROSETTA.R @@ -3,110 +3,101 @@ context("ROSETTA() -- requires internet connection") # example data x <<- structure( list( - musym = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, - 1L), - cokey = c(20392868L, 20392868L, 20392870L, 20392870L, 20392870L, - 20392870L, 20393517L, 20394343L, 20394343L, 20394343L), - compname = c("Aluf", - "Aluf", "Hitilo", "Hitilo", "Hitilo", "Hitilo", "Aransas", "Muskogee", - "Muskogee", "Muskogee"), - comppct_r = c(47L, 47L, 22L, 22L, 22L, - 22L, 100L, 20L, 20L, 20L), - hzname = c("H1", "H2", "H1", "H2", - "H3", "H4", "H1", "H1", "H2", "H3"), - hzdept_r = c(0L, 127L, 0L, - 117L, 137L, 157L, 0L, 0L, 38L, 64L), - hzdepb_r = c(127L, 203L, - 117L, 137L, 157L, 203L, 152L, 38L, 64L, 203L), - sandtotal_r = c(94.4, - 91, 94.1, 55.4, 59.3, 62.8, 23.3, 11.7, 6.8, 23.3), - silttotal_r = c(0.6, - 1, 1.4, 17.6, 13.7, 19.2, 29.2, 69.8, 63.2, 29.2), - claytotal_r = c(5, - 8, 4.5, 27, 27, 18, 47.5, 18.5, 30, 47.5), - dbthirdbar_r = c(1.6, - 1.55, 1.55, 1.58, 1.58, 1.5, 1.45, 1.38, 1.35, 1.33), - wthirdbar_decimal = c(0.117, + musym = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L), + cokey = c(20392868L, 20392868L, 20392870L, 20392870L, 20392870L, + 20392870L, 20393517L, 20394343L, 20394343L, 20394343L), + compname = c("Aluf", + "Aluf", "Hitilo", "Hitilo", "Hitilo", "Hitilo", "Aransas", "Muskogee", + "Muskogee", "Muskogee"), + comppct_r = c(47L, 47L, 22L, 22L, 22L, + 22L, 100L, 20L, 20L, 20L), + hzname = c("H1", "H2", "H1", "H2", + "H3", "H4", "H1", "H1", "H2", "H3"), + hzdept_r = c(0L, 127L, 0L, + 117L, 137L, 157L, 0L, 0L, 38L, 64L), + hzdepb_r = c(127L, 203L, + 117L, 137L, 157L, 203L, 152L, 38L, 64L, 203L), + sandtotal_r = c(94.4, + 91, 94.1, 55.4, 59.3, 62.8, 23.3, 11.7, 6.8, 23.3), + silttotal_r = c(0.6, + 1, 1.4, 17.6, 13.7, 19.2, 29.2, 69.8, 63.2, 29.2), + claytotal_r = c(5, + 8, 4.5, 27, 27, 18, 47.5, 18.5, 30, 47.5), + dbthirdbar_r = c(1.6, + 1.55, 1.55, 1.58, 1.58, 1.5, 1.45, 1.38, 1.35, 1.33), + wthirdbar_decimal = c(0.117, 0.129, 0.106, 0.252, 0.261, 0.211, 0.369, 0.286, 0.308, 0.399 - ), - wfifteenbar_decimal = c(0.049, 0.062, 0.039, 0.181, 0.156, + ), + wfifteenbar_decimal = c(0.049, 0.062, 0.039, 0.181, 0.156, 0.122, 0.285, 0.134, 0.165, 0.255) - ), - row.names = c(NA, -10L), - class = "data.frame", + ), + row.names = c(NA, -10L), + class = "data.frame", SDA_id = "Table" ) test_that("ROSETTA() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # attempting to use all possible soil properties vars <- c('sandtotal_r', 'silttotal_r', 'claytotal_r', 'dbthirdbar_r', 'wthirdbar_decimal', 'wfifteenbar_decimal') - + # submit request r <- ROSETTA(x, vars = vars) - + # correct object expect_true(inherits(r, 'data.frame')) - + # input / output are conformal expect_true(nrow(r) == nrow(x)) - + # output contains new columns expect_true(all(c('theta_r', 'theta_s', 'alpha', 'npar', 'ksat') %in% names(r))) - + }) test_that("correct model selection in the presence of NA", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - - + + skip_on_cran() + # sprinkle NA x$dbthirdbar_r[1] <- NA x$wthirdbar_decimal[2] <- NA x$wfifteenbar_decimal[3] <- NA x$sandtotal_r[9] <- NA x[10, ] <- NA - + # attempting to use all possible soil properties vars <- c('sandtotal_r', 'silttotal_r', 'claytotal_r', 'dbthirdbar_r', 'wthirdbar_decimal', 'wfifteenbar_decimal') - + # submit request r <- ROSETTA(x, vars = vars) - + # missing 1/3 bar Db -> model 2 expect_true(r$.rosetta.model[1] == 2) - + # missing 1/3 bar WT -> model 3 expect_true(r$.rosetta.model[2] == 3) - + # missing 15 bar WT -> model 4 expect_true(r$.rosetta.model[3] == 4) - + # no records missing -> model 5 expect_true(all(r$.rosetta.model[4:8] == 5)) - + # missing sand -> NA expect_true(is.na(r$theta_r[9]) & (r$.rosetta.model[9] == -1)) - + # all NA expect_true(all(is.na(r[10, c('theta_r', 'theta_s', 'alpha', 'npar', 'ksat')]))) - - + + }) diff --git a/tests/testthat/test-SDA_query.R b/tests/testthat/test-SDA_query.R index caf3cb28e..b14d48de8 100644 --- a/tests/testthat/test-SDA_query.R +++ b/tests/testthat/test-SDA_query.R @@ -5,11 +5,7 @@ test_that("SDA_query() works", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() ## sample data @@ -40,11 +36,7 @@ test_that("SDA_query() returns expected result", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # table dimensions expect_equal(nrow(x.1), 1) @@ -61,11 +53,7 @@ test_that("SDA_query() SQL error / no results -> NULL", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # bad SQL should result in a warning and try-error result. expect_true(inherits(expect_warning(SDA_query("SELECT this from that")), 'try-error')) @@ -81,11 +69,7 @@ test_that("SDA_spatialQuery() simple spatial query, tabular results", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() res <- suppressWarnings(SDA_spatialQuery(p, what = 'mukey')) @@ -101,11 +85,7 @@ test_that("SDA_spatialQuery() simple spatial query, spatial results", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # test with default db = "SSURGO" res <- suppressWarnings(SDA_spatialQuery(p, what = 'geom')) @@ -128,11 +108,7 @@ test_that("SDA_query() interprets column names", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # x.3 is from the component table expect_equal( @@ -148,11 +124,7 @@ test_that("SDA_query() interprets data type correctly", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # x.3 is from the component table expect_true(inherits(x.3$mukey, 'integer')) @@ -173,11 +145,7 @@ test_that("SDA_query() works with multi-line records", { skip_if_offline() - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # https://github.com/ncss-tech/soilDB/issues/28 expect_true(inherits(x.4, 'data.frame')) diff --git a/tests/testthat/test-fetchKSSL.R b/tests/testthat/test-fetchKSSL.R index 0385ebb9e..099acaa36 100644 --- a/tests/testthat/test-fetchKSSL.R +++ b/tests/testthat/test-fetchKSSL.R @@ -1,126 +1,98 @@ context("fetchKSSL() -- requires internet connection") test_that("fetchKSSL() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + ## sample data x <<- fetchKSSL(series='sierra') x.morph <<- fetchKSSL(series='sierra', returnMorphologicData = TRUE) x.morp.simple.colors <<- fetchKSSL(series='sierra', returnMorphologicData = TRUE, simplifyColors = TRUE) - + # standard request expect_true(inherits(x, 'SoilProfileCollection')) - - + + }) test_that("fetchKSSL() returns an SPC or list", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # SPC + morphologic data expect_true(inherits(x.morph, 'list')) expect_true(inherits(x.morph$SPC, 'SoilProfileCollection')) expect_true(inherits(x.morph$morph, 'list')) - + # simplified colors, merges into @horizons expect_false(is.null(x.morp.simple.colors$SPC$moist_soil_color)) - + }) test_that("fetchKSSL() returns reasonable data", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # standard request expect_equal(nrow(site(x)) > 0, TRUE) expect_equal(nrow(horizons(x)) > 0, TRUE) expect_equal(idname(x), 'pedon_key') expect_equal(horizonDepths(x), c("hzn_top", "hzn_bot")) - + }) test_that("fetchKSSL() returns data associated with named series (sierra)", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # all of the results should contain the search term f <- grepl('sierra', x$taxonname, ignore.case = TRUE) expect_equal(all(f), TRUE) - + }) test_that("fetchKSSL() returns data associated with multiple named series", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + x.multiple <- fetchKSSL(series=c('sierra', 'amador')) f <- unique(toupper(x.multiple$taxonname)) %in% c('SIERRA', 'AMADOR') expect_true(all(f)) - + }) test_that("fetchKSSL() returns NULL with bogus query", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # a message is printed and NULL returned when no results res <- suppressMessages(fetchKSSL(series='XXX')) expect_null(res) - + }) test_that("fetchKSSL() fails gracefully when morphology data are missing", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # pedon_key 37457 is missing: # * most lab data # * all morphologic data @@ -131,33 +103,31 @@ test_that("fetchKSSL() fails gracefully when morphology data are missing", { expect_false(res$morph$phpores) expect_false(res$morph$phstructure) expect_false(res$morph$pediagfeatures) - + }) test_that("fetchKSSL() geochem result", { - + # handy code snippet where res is KSSL data from mlra 17 - # dput(site(res$SPC)[unique(horizons(res$SPC)[horizons(res$SPC)$labsampnum %in% filter_geochem(res$geochem, + # dput(site(res$SPC)[unique(horizons(res$SPC)[horizons(res$SPC)$labsampnum %in% filter_geochem(res$geochem, # major_element_method = "4H1b", trace_element_method = "4H1a")$labsampnum,]$pedon_key) %in% # site(res$SPC)$pedon_key,]$pedlabsampnum) - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + + + skip_on_cran() + # get geochemical data for a single pedlabsampnum, do some basic filtering res <- fetchKSSL(pedlabsampnum = c("93P0249"), returnGeochemicalData = TRUE) - + expect_true(all(filter_geochem(res$geochem, prep_code='S')$prep_code == 'S')) - - expect_true(all(na.omit(filter_geochem(res$geochem, prep_code='S', - major_element_method = "4H1b", + + expect_true(all(na.omit(filter_geochem(res$geochem, prep_code='S', + major_element_method = "4H1b", trace_element_method = "4H1a")$prep_code == "S"))) - - expect_true(all(na.omit(filter_geochem(res$geochem, - major_element_method = "4H1b", + + expect_true(all(na.omit(filter_geochem(res$geochem, + major_element_method = "4H1b", trace_element_method = "4H1a")$prep_code == "S"))) }) diff --git a/tests/testthat/test-fetchNASIS.R b/tests/testthat/test-fetchNASIS.R index fbd6226fe..8c0dd21b9 100644 --- a/tests/testthat/test-fetchNASIS.R +++ b/tests/testthat/test-fetchNASIS.R @@ -94,10 +94,10 @@ test_that("fetchNASIS(from='pedons') nullFragsAreZero works as expected", { test_that("fetchNASIS(from='components') returns reasonable data", { - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail + skip_on_cran() + if(!local_NASIS_defined()) { - skip("in-house testing only") + skip("local NASIS database not available") } # must have components to complete test diff --git a/tests/testthat/test-fetchNASISWebReport.R b/tests/testthat/test-fetchNASISWebReport.R index a73648100..de30c5695 100644 --- a/tests/testthat/test-fetchNASISWebReport.R +++ b/tests/testthat/test-fetchNASISWebReport.R @@ -1,92 +1,72 @@ context("fetchNASISWebReport() -- requires internet connection") test_that("fetchNASISWebReport() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + ## sample data pn <- "MLRA 18 - Sierra sandy loam, 2 to 9 percent slopes" - + x <<- suppressMessages(fetchNASISWebReport(projectname = pn)) - + # standard request expect_true(inherits(x, 'list')) - + }) test_that("fetchNASISWebReport() returns an SPC of component/horizon data and data.frame of mapunits", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # SPC + morphologic data expect_true(inherits(x$spc, 'SoilProfileCollection')) expect_true(inherits(x$mapunit, 'data.frame')) - + }) test_that("fetchNASISWebReport() returns reasonable data", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # standard request expect_equal(nrow(site(x$spc)) > 0, TRUE) expect_equal(nrow(horizons(x$spc)) > 0, TRUE) expect_equal(idname(x$spc), 'coiid') expect_equal(hzidname(x$spc), 'chiid') expect_equal(horizonDepths(x$spc), c("hzdept_r", "hzdepb_r")) - + }) test_that("fetchNASISWebReport() returns data for component name (Sierra)", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # all major components are Sierra f <- grepl('Sierra', x$spc$compname[x$spc$majcompflag == 1], ignore.case = TRUE) expect_equal(all(f), TRUE) - + }) test_that("fetchNASISWebReport() returns NULL with bogus query", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # a message is printed and NULL returned when no results res <- suppressMessages(fetchNASISWebReport(projectname='XXX')) expect_null(res) - + }) diff --git a/tests/testthat/test-fetchOSD.R b/tests/testthat/test-fetchOSD.R index 645d1364d..495560cb2 100644 --- a/tests/testthat/test-fetchOSD.R +++ b/tests/testthat/test-fetchOSD.R @@ -5,137 +5,109 @@ context("fetchOSD() -- requires internet connection") extended.table.names <<- c("SPC", "competing", "geog_assoc_soils" ,"geomcomp", "hillpos", "mtnpos", "terrace", "flats", "pmkind", "pmorigin", "mlra", "climate.annual", "climate.monthly", "soilweb.metadata") test_that("fetchOSD() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + ## sample data x <<- fetchOSD(soils = c('sierra', 'cecil')) x.extended <<- fetchOSD(soils = c('sierra', 'cecil'), extended = TRUE) - + # standard request expect_true(inherits(x, 'SoilProfileCollection')) - + }) test_that("fetchOSD() returns NULL with bogus query", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # a message is printed and NULL returned when no results res <- suppressMessages(fetchOSD(soils='XXX')) expect_null(res) - + }) test_that("fetchOSD() returns a list + SPC in extended mode", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # extended request expect_true(inherits(x.extended, 'list')) expect_true(inherits(x.extended$SPC, 'SoilProfileCollection')) - + }) test_that("fetchOSD() returns reasonable data", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # standard request expect_equal(nrow(site(x)) == 2, TRUE) expect_equal(nrow(horizons(x)) > 0, TRUE) expect_equal(idname(x), 'id') expect_equal(horizonDepths(x), c("top", "bottom")) - + }) test_that("fetchOSD() returns reasonable data in extended mode", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # extended request expect_equal( names(x.extended), extended.table.names ) - + }) # https://github.com/ncss-tech/soilDB/issues/128 test_that("fetchOSD() returns warning in extended mode, when active + inactive series specified", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # warning added in response to #128 expect_warning( xx <- fetchOSD(soils = c('sierra', 'Breadsprings', 'Hagerwest', 'Tintero'), extended = TRUE) ) - + # extended request components expect_equal( names(xx), extended.table.names ) - + }) test_that("fetchOSD() returns data associated with named series (sierra|cecil)", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # all of the results should contain the search term f <- grepl('sierra|cecil', x$id, ignore.case = TRUE) expect_equal(all(f), TRUE) - + }) diff --git a/tests/testthat/test-fetchSCAN.R b/tests/testthat/test-fetchSCAN.R index 354a74edb..cfca879e6 100644 --- a/tests/testthat/test-fetchSCAN.R +++ b/tests/testthat/test-fetchSCAN.R @@ -1,37 +1,29 @@ context("fetchSCAN() -- requires internet connection") test_that("fetchSCAN() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + ## sample data x <<- fetchSCAN(site.code=2001, year=c(2014)) - + # standard request expect_true(inherits(x, 'list')) - + }) test_that("fetchSCAN() returns the right kind of data", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # metadata + some sensor data expect_true(inherits(x, 'list')) expect_true(inherits(x$metadata, 'data.frame')) expect_true(inherits(x$STO, 'data.frame')) expect_true(ncol(x$STO) == 7) - + }) diff --git a/tests/testthat/test-fetchSDA_component.R b/tests/testthat/test-fetchSDA_component.R index 6f485d1d3..9f040a9a4 100644 --- a/tests/testthat/test-fetchSDA_component.R +++ b/tests/testthat/test-fetchSDA_component.R @@ -4,18 +4,14 @@ context("fetchSDA() -- requires internet connection") test_that("fetchSDA() works", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # single component x <<- suppressMessages(fetchSDA(WHERE="nationalmusym = 'kzc4'")) - + # basic test expect_true(inherits(x, 'SoilProfileCollection')) }) @@ -23,39 +19,31 @@ test_that("fetchSDA() works", { ## tests test_that("fetchSDA() returns an SPC", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # SPC integrity and expected IDs / hz depths expect_equal(idname(x), 'cokey') expect_equal(horizonDepths(x), c('hzdept_r', 'hzdepb_r')) - + }) test_that("fetchSDA() returns expected results", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # there should be 2 components nad 10 horizons expect_equal(length(x), 2) expect_equal(nrow(x), 10) - + # should match original WHERE clause expect_equal(x$nationalmusym, c('kzc4', 'kzc4')) expect_equal(site(x)$nationalmusym, c('kzc4', 'kzc4')) - + # test that both components have no NRCS forest/range site assigned expect_equal(site(x)$ecoclassid, c(NA,NA)) }) diff --git a/tests/testthat/test-fetchSDA_spatial.R b/tests/testthat/test-fetchSDA_spatial.R index dd40270de..dd376108a 100644 --- a/tests/testthat/test-fetchSDA_spatial.R +++ b/tests/testthat/test-fetchSDA_spatial.R @@ -4,9 +4,7 @@ test_that("fetchSDA_spatial basic mupolygon functionality", { skip_if_offline() - if (!getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } + skip_on_cran() # expect 3, relatively nonextensive join delineations single.mukey <- fetchSDA_spatial(x = "2924882", by.col = 'mukey') @@ -31,9 +29,7 @@ test_that("fetchSDA_spatial sapolygon and gsmmupolygon", { skip_if_offline() - if (!getOption('.soilDB_testNetworkFunctions')) { - skip("in-house testing only") - } + skip_on_cran() # test SSA geometry sapolygon @@ -63,16 +59,16 @@ test_that("fetchSDA_spatial sapolygon and gsmmupolygon", { "Eastern Stanislaus Area, California", "Mariposa County Area, California", "Stanislaus County, California, Northern Part")) - + # test STATSGO mupolygon statsgo.bbox <- fetchSDA_spatial(660848, db = 'STATSGO', method = "bbox", add.fields = c("mapunit.muname","legend.areaname")) expect_equal(nrow(statsgo.bbox), 5) - + # skip_if_not_installed('sf') # suppressWarnings(requireNamespace("sf")) # suppressWarnings(requireNamespace("lwgeom")) - # # test CLIPAREASYMBOL + # # test CLIPAREASYMBOL # an_extent <- fetchSDA_spatial(x = 660972, db = 'STATSGO', chunk.size = 1, add.fields = "legend.areaname") # tst <- sf::st_as_sf(an_extent) # expect_equal(nrow(an_extent), 7) diff --git a/tests/testthat/test-fetchSoilGrids.R b/tests/testthat/test-fetchSoilGrids.R index 6df40eb7d..0ac82147f 100644 --- a/tests/testthat/test-fetchSoilGrids.R +++ b/tests/testthat/test-fetchSoilGrids.R @@ -1,41 +1,37 @@ context("fetchSoilGrids() -- requires internet connection") test_that("fetchSoilGrids() works as expected", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if (!getOption('.soilDB_testNetworkFunctions')) { - skip("in-house testing only") - } - - your.points <- data.frame(id = c("A", "B"), - lat = c(37.9, 38.1), - lon = c(-120.3, -121.5), + + skip_on_cran() + + your.points <- data.frame(id = c("A", "B"), + lat = c(37.9, 38.1), + lon = c(-120.3, -121.5), stringsAsFactors = FALSE) - + res <- fetchSoilGrids(your.points) - + # contents as expected expect_true(aqp::spc_in_sync(res)$valid) expect_true(all(aqp::checkHzDepthLogic(res)$valid)) - + expect_equal(length(res), 2) expect_equal(nrow(res), 2*6) - + expect_equal(ncol(site(res)), 1) expect_equal(ncol(horizons(res)), 2*25) - + # data conversion works expect_equal(res$claymean[1], 18.7) - + # default names kick in expect_silent( {res <- fetchSoilGrids(your.points, loc.names = NULL)} ) - + # bogus loc.names expect_error( {res <- fetchSoilGrids(your.points, loc.names = "foo")} ) - + # custom column names colnames(your.points) <- letters[1:3] expect_error( {res <- fetchSoilGrids(your.points, loc.names = "foo")} ) diff --git a/tests/testthat/test-siblings.R b/tests/testthat/test-siblings.R index 50da2c5d0..a57c72f0e 100644 --- a/tests/testthat/test-siblings.R +++ b/tests/testthat/test-siblings.R @@ -2,45 +2,37 @@ context("siblings() -- requires internet connection") test_that("siblings() returns reasonable data", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + x <- siblings('amador', component.data = TRUE) - + # standard request expect_true(inherits(x, 'list')) expect_equal(length(x), 2) - + expect_true(inherits(x$sib, 'data.frame')) expect_true(inherits(x$sib.data, 'data.frame')) - + expect_equal(names(x$sib), c('series', 'sibling', 'majcompflag', 'n')) }) test_that("siblings() returns skeleton with bogus query", { - + skip_if_offline() - - # hack for in-house testing only - # WWW services aren't always available and will cause CRAN to drop our package if tests fail - if( ! getOption('.soilDB_testNetworkFunctions') ) { - skip("in-house testing only") - } - + + skip_on_cran() + # a skeleton list should be returned res <- siblings('XXX') expect_true(inherits(res, 'list')) - + # TODO: elements should be NULL vs. FALSE - + }) # TODO: test cousins