Skip to content

Commit e2f18d6

Browse files
test(fix): skip when SDA fails (#461)
1 parent 0105ad4 commit e2f18d6

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

R/SoilDataViewer.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ get_SDV_legend_elements <- function(WHERE,
2727
FROM sdvattribute WHERE ", ak))
2828

2929
if (inherits(x, 'try-error')) {
30-
message(x[1])
3130
return(invisible(x))
3231
}
3332

@@ -42,6 +41,12 @@ get_SDV_legend_elements <- function(WHERE,
4241
})
4342
})
4443

44+
# check for try-error
45+
err <- sapply(y, inherits, "try-error")
46+
if (any(err)) {
47+
return(y[[which(err)[1]]])
48+
}
49+
4550
if ((length(y) == 1) && length(y[[1]]) == 1 && simplify) {
4651
return(y[[1]][[1]])
4752
} else if (simplify) return(do.call('c', y))

tests/testthat/test-SoilDataViewer.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ test_that("get_SDV_legend_elements works", {
99
# simplify=TRUE, one where clause returning one legend
1010
res <- get_SDV_legend_elements("attributekey = 427")
1111

12+
skip_if(inherits(res, 'try-error'))
13+
1214
expect_true(inherits(res, 'data.frame'))
1315

1416
# simplify=TRUE, two where clauses returning list of length 3 = 2 + 1 legends

tests/testthat/test-fetchSDA_spatial.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_that("fetchSDA_spatial basic mupolygon functionality", {
1111
# expect 3, relatively non-extensive join delineations
1212
single.mukey <- fetchSDA_spatial(x = "2924882", by.col = 'mukey')
1313

14-
skip_if(inherits(single.mukey, 'try-error'))
14+
skip_if(is.null(single.mukey) || inherits(single.mukey, 'try-error'))
1515

1616
expect_equivalent(nrow(single.mukey), 3)
1717

tests/testthat/test-get_SDA_interpretation.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ test_that("dynamically determine target row counts", {
1919
r1 <- SDA_query(sprintf(q, area_in))
2020
r2a <- SDA_query(sprintf(q, comp_in[1]))
2121

22-
expect_true(inherits(r1, 'data.frame') || is.null(r1))
22+
# ensure fixtures exist
23+
target_area_rows <<- NULL
24+
target_area_rows_all <<- NULL
25+
26+
skip_if(is.null(r1) || inherits(r1, 'try-error'))
27+
28+
expect_true(inherits(r1, 'data.frame'))
2329

2430
target_area_rows <<- nrow(r1) # 1:1 with mukey
2531
target_area_rows_all <<- nrow(r2a) # 1:1 with component

tests/testthat/test-get_SDA_property.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_that("dynamically determine target row counts", {
66
skip_if_offline()
77

88
skip_on_cran()
9-
9+
1010
q <- "SELECT areasymbol, mapunit.mukey, muname FROM mapunit
1111
INNER JOIN legend ON mapunit.lkey = legend.lkey
1212
%s"
@@ -23,8 +23,14 @@ test_that("dynamically determine target row counts", {
2323
r2c <- SDA_query(sprintf(q, comp_in[3]))
2424
r3a <- SDA_query(sprintf(q, chor_in[1]))
2525
r3b <- SDA_query(sprintf(q, chor_in[2]))
26-
27-
expect_true(inherits(r1, 'data.frame') || is.null(r1))
26+
27+
# ensure fixtures exist
28+
target_area_rows <<- NULL
29+
target_area_rows_all <<- NULL
30+
31+
skip_if(is.null(r1) || inherits(r1, 'try-error'))
32+
33+
expect_true(inherits(r1, 'data.frame'))
2834

2935
target_area_rows <<- nrow(r1) # 1:1 with mukey
3036
target_area_rows_all <<- nrow(r2a) # 1:1 with component

0 commit comments

Comments
 (0)