Skip to content

Commit

Permalink
adding skip if offline to tests, more to do
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Nov 7, 2019
1 parent 8e6f201 commit 8e69da5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Package: soilDB
Type: Package
Title: Soil Database Interface
Version: 2.4
Date: 2019-11-06
Authors@R: c(person(given="Dylan", family="Beaudette", role = c("cre", "aut"), email = "[email protected]"), person(given="Jay", family="Skovlin", role = c("aut")), person(given="Stephen", family="Roecker", role = c("aut")) )
Author: Dylan Beaudette [cre, aut], Jay Skovlin [aut], Stephen Roecker [aut]
Expand Down
25 changes: 21 additions & 4 deletions tests/testthat/test-fetchKSSL.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
context("fetchKSSL() -- requires internet connection")

## sample data
x <- fetchKSSL(series='sierra')
x.morph <- fetchKSSL(series='sierra', returnMorphologicData = TRUE)
x.morp.simple.colors <- fetchKSSL(series='sierra', returnMorphologicData = TRUE, simplifyColors = TRUE)
test_that("fetchKSSL() works", {

skip_if_offline()

## sample data
x <<- fetchKSSL(series='sierra')
x.morph <<- fetchKSSL(series='sierra', returnMorphologicData = TRUE)
x.morp.simple.colors <<- fetchKSSL(series='sierra', returnMorphologicData = TRUE, simplifyColors = TRUE)

})


test_that("fetchKSSL() returns an SPC or list", {

skip_if_offline()

# standard request
expect_match(class(x), 'SoilProfileCollection')

Expand All @@ -23,6 +32,8 @@ test_that("fetchKSSL() returns an SPC or list", {

test_that("fetchKSSL() returns reasonable data", {

skip_if_offline()

# standard request
expect_equal(nrow(site(x)) > 0, TRUE)
expect_equal(nrow(horizons(x)) > 0, TRUE)
Expand All @@ -33,6 +44,8 @@ test_that("fetchKSSL() returns reasonable data", {

test_that("fetchKSSL() returns data associated with named series (sierra)", {

skip_if_offline()

# all of the results should contain the search term
f <- grepl('sierra', x$taxonname, ignore.case = TRUE)
expect_equal(all(f), TRUE)
Expand All @@ -42,6 +55,8 @@ test_that("fetchKSSL() returns data associated with named series (sierra)", {

test_that("fetchKSSL() returns NULL with bogus query", {

skip_if_offline()

# a message is printed and NULL returned when no results
res <- suppressMessages(fetchKSSL(series='XXX'))
expect_null(res)
Expand All @@ -51,6 +66,8 @@ test_that("fetchKSSL() returns NULL with bogus query", {

test_that("fetchKSSL() fails gracefully when morphology data are missing", {

skip_if_offline()

# pedon_key 37457 is missing:
# * most lab data
# * all morphologic data
Expand Down
34 changes: 25 additions & 9 deletions tests/testthat/test-fetchOSD.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
context("fetchOSD() -- requires internet connection")


## sample data
x <- fetchOSD(soils = c('sierra', 'cecil'))
x.extended <- fetchOSD(soils = c('sierra', 'cecil'), extended = TRUE)
test_that("fetchOSD() works", {

skip_if_offline()

## sample data
x <<- fetchOSD(soils = c('sierra', 'cecil'))
x.extended <<- fetchOSD(soils = c('sierra', 'cecil'), extended = TRUE)

# standard request
expect_match(class(x), 'SoilProfileCollection')


})



test_that("fetchOSD() returns NULL with bogus query", {

skip_if_offline()

# a message is printed and NULL returned when no results
res <- suppressMessages(fetchOSD(soils='XXX'))
expect_null(res)

})

test_that("fetchOSD() returns an SPC", {

# standard request
expect_match(class(x), 'SoilProfileCollection')

})


test_that("fetchOSD() returns a list + SPC in extended mode", {

skip_if_offline()

# extended request
expect_match(class(x.extended), 'list')
expect_match(class(x.extended$SPC), 'SoilProfileCollection')
Expand All @@ -31,6 +41,8 @@ test_that("fetchOSD() returns a list + SPC in extended mode", {

test_that("fetchOSD() returns reasonable data", {

skip_if_offline()

# standard request
expect_equal(nrow(site(x)) == 2, TRUE)
expect_equal(nrow(horizons(x)) > 0, TRUE)
Expand All @@ -41,6 +53,8 @@ test_that("fetchOSD() returns reasonable data", {

test_that("fetchOSD() returns reasonable data in extended mode", {

skip_if_offline()

# extended request
expect_equal(
names(x.extended),
Expand All @@ -51,6 +65,8 @@ test_that("fetchOSD() returns reasonable data in extended mode", {

test_that("fetchOSD() returns data associated with named series (sierra|cecil)", {

skip_if_offline()

# all of the results should contain the search term
f <- grepl('sierra|cecil', x$id, ignore.case = TRUE)
expect_equal(all(f), TRUE)
Expand Down

0 comments on commit 8e69da5

Please sign in to comment.