Skip to content

Commit 6e8b670

Browse files
committed
Smarter test skipping
1 parent 9137de7 commit 6e8b670

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

tests/testthat/helper.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ skip_on_actions <- function() {
55
skip("On GitHub Actions")
66
}
77

8+
skip_if_catalogue_function_tests_skipped <- function() {
9+
if (nzchar(Sys.getenv("SKIP_CATALOGUE_FUNCTION_TESTS"))) {
10+
skip("Skipping catalogue function tests")
11+
}
12+
}
13+
814
make_local_cded_cache <- function(dir = tempdir(), env = parent.frame()) {
915
cache_dir <- file.path(dir, "cded")
1016
make_mapsheet_dirs(cache_dir)
1117

1218
# Use withr::defer to cleanup tempdir after exiting tests
1319
# https://www.tidyverse.org/blog/2020/04/self-cleaning-test-fixtures/
14-
withr::defer({
15-
unlink(cache_dir, recursive = TRUE, force = TRUE)
16-
}, envir = env)
20+
withr::defer(
21+
{
22+
unlink(cache_dir, recursive = TRUE, force = TRUE)
23+
},
24+
envir = env
25+
)
1726

1827
cache_dir
1928
}

tests/testthat/test-cache-utils.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ context("test-cache-utils")
33
test_that("show_cached_files works", {
44
skip_on_cran()
55
skip_if_offline()
6+
skip_if_catalogue_function_tests_skipped()
67

78
datadir <- file.path(tempdir(), "bcmaps")
89
withr::local_options(list("bcmaps.data_dir" = datadir))
@@ -18,9 +19,11 @@ test_that("show_cached_files works", {
1819
expect_equal(cache_info$is_dir, c(FALSE, TRUE))
1920
})
2021

21-
test_that("the cache is deleted",{
22+
test_that("the cache is deleted", {
2223
skip_on_cran()
2324
skip_if_offline()
25+
skip_if_catalogue_function_tests_skipped()
26+
2427
expect_is(airzones(ask = FALSE, force = TRUE), "sf")
2528
expect_true(delete_cache("airzones"))
2629
expect_is(airzones(ask = FALSE, force = TRUE), "sf")

tests/testthat/test-cded.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mapsheets_50_sf <- mapsheets_50K()
55
test_that("list_mapsheet_files works", {
66
skip_on_cran()
77
skip_if_offline()
8-
skip_if(nzchar(Sys.getenv("SKIP_CATALOGUE_FUNCTION_TESTS")))
8+
skip_if_catalogue_function_tests_skipped()
99

1010
res <- list_mapsheet_files("https://pub.data.gov.bc.ca/datasets/175624/82g/")
1111
expect_type(res, "character")
@@ -31,6 +31,7 @@ test_that("making cded cache directory works", {
3131
test_that("get_mapsheet_tiles works", {
3232
skip_on_cran()
3333
skip_if_offline()
34+
skip_if_catalogue_function_tests_skipped()
3435

3536
cache_dir <- make_local_cded_cache()
3637

@@ -81,6 +82,7 @@ test_that("get_mapsheet_tiles works", {
8182
test_that("cded works with tiles_50K", {
8283
skip_on_cran()
8384
skip_if_offline()
85+
skip_if_catalogue_function_tests_skipped()
8486

8587
vrt <- cded(tiles_50K = c("102o14", "095d01"))
8688

@@ -97,6 +99,7 @@ test_that("cded works with tiles_50K", {
9799
test_that("cded works with aoi", {
98100
skip_on_cran()
99101
skip_if_offline()
102+
skip_if_catalogue_function_tests_skipped()
100103

101104
aoi <- st_buffer(
102105
mapsheets_sf[mapsheets_sf$MAP_TILE_DISPLAY_NAME == "102o", ],
@@ -132,6 +135,7 @@ test_that("cded works with aoi", {
132135
test_that("cded works with aoi with a different projection as mapsheets_250K", {
133136
skip_on_cran()
134137
skip_if_offline()
138+
skip_if_catalogue_function_tests_skipped()
135139

136140
aoi <- st_transform(
137141
st_buffer(
@@ -157,6 +161,7 @@ test_that("cded works with aoi with a different projection as mapsheets_250K", {
157161
if (require("stars")) {
158162
skip_on_cran()
159163
skip_if_offline()
164+
skip_if_catalogue_function_tests_skipped()
160165

161166
pol1 <- mapsheets_50K()[1, ]
162167
s <- st_as_stars(pol1)
@@ -172,6 +177,7 @@ if (require("stars")) {
172177
if (require("terra")) {
173178
skip_on_cran()
174179
skip_if_offline()
180+
skip_if_catalogue_function_tests_skipped()
175181

176182
pol1 <- mapsheets_50K()[1, ]
177183
r <- rast(pol1)

tests/testthat/test-data_functions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn_names <- setdiff(fn_names, donttest)
1717
test_that("All sf layer function work without error and returns an sf object.", {
1818
skip_on_cran()
1919
skip_if_offline()
20-
skip_if(nzchar(Sys.getenv("SKIP_CATALOGUE_FUNCTION_TESTS")))
20+
skip_if_catalogue_function_tests_skipped()
2121

2222
for (i in seq_along(fn_names)) {
2323
# cat("\n", fn_names[i]) #for debugging

tests/testthat/test-utils.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ sf_bbox_to_vec <- function(x) {
2222

2323
test_that("bc_bbox works with all classes", {
2424
skip_on_cran()
25+
skip_if_offline()
26+
skip_if_catalogue_function_tests_skipped()
27+
2528
sf_out <- sf_bbox_to_vec(bc_bbox())
2629
expect_equivalent(bc_bbox(), sf::st_bbox(bc_bound()))
2730
expect_equal(Extent_to_vec(bc_bbox("raster")), sf_out)
2831
})
2932

3033
test_that("bc_bbox works with all classes and numeric crs", {
3134
skip_on_cran()
35+
skip_if_offline()
36+
skip_if_catalogue_function_tests_skipped()
37+
3238
sf_out <- sf_bbox_to_vec(bc_bbox(crs = 4326))
3339
expect_equal(Extent_to_vec(bc_bbox("raster", crs = 4326)), sf_out)
3440
})
@@ -51,6 +57,12 @@ test_that("clean_geos_version works", {
5157
expect_equal(clean_geos_version("3.9.0dev1"), "3.9.0-9999-1")
5258
expect_equal(clean_geos_version("3.9.0"), "3.9.0")
5359

54-
expect_equal(unclass(numeric_version(clean_geos_version("3.9.0dev1"))), list(c(3, 9, 0, 9999, 1)))
55-
expect_equal(unclass(numeric_version(clean_geos_version("3.9.0-dev-1"))), list(c(3, 9, 0, 9999, 1)))
60+
expect_equal(
61+
unclass(numeric_version(clean_geos_version("3.9.0dev1"))),
62+
list(c(3, 9, 0, 9999, 1))
63+
)
64+
expect_equal(
65+
unclass(numeric_version(clean_geos_version("3.9.0-dev-1"))),
66+
list(c(3, 9, 0, 9999, 1))
67+
)
5668
})

0 commit comments

Comments
 (0)