Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: escape all examples for non-installed pkgs
Browse files Browse the repository at this point in the history
pat-s committed May 31, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
Czaki Grzegorz Bokota
1 parent aa8448a commit 9f1bb0e
Showing 12 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# for graph learner tests
loadNamespace("mlr3pipelines")
loadNamespace("mlr3")

# Create 6x6 point grid with 1m distance between points
@@ -203,6 +202,8 @@ test_graph_learner = function(task, resampling,
learner = "classif.featureless",
measure = "classif.ce") {

loadNamespace("mlr3pipelines")

if (!is.null(time_var)) {
task$set_col_roles(time_var, "time")
task$set_col_roles(space_var, "space")
6 changes: 6 additions & 0 deletions tests/testthat/test-1-autoplot.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# generic tests

test_that("errors are thrown for non-valid argument settings", {
skip_if_not_installed("sf")
skip_if_not_installed("patchwork")
skip_if_not_installed("ggtext")
task = test_make_twoclass_task()
# type does not matter here
rsp = rsmp("spcv_coords")
@@ -454,6 +457,9 @@ test_that("plot() works for 'repeated_spcv_cstf'", {
})

test_that("autoplot time + space", {
skip_if_not_installed("sf")
skip_if_not_installed("patchwork")
skip_if_not_installed("ggtext")
# special data with five temporal levels
data = cookfarm_sample
b = mlr3::as_data_backend(data)
3 changes: 3 additions & 0 deletions tests/testthat/test-ResamplingRepeatedSpCVDisc.R
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ test_that("resampling iterations equals folds * repeats", {
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius + buffer", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_disc",
@@ -55,6 +56,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius + buffer"
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_disc",
@@ -80,6 +82,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius", {
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - replace", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_disc",
9 changes: 9 additions & 0 deletions tests/testthat/test-ResamplingRepeatedSpCVTiles.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("folds can be printed", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
rsp = rsmp("repeated_spcv_tiles",
repeats = 2, nsplit = c(4L, 3L), reassign = FALSE)
@@ -8,6 +9,7 @@ test_that("folds can be printed", {
})

test_that("reps can be printed", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
rsp = rsmp("repeated_spcv_tiles",
repeats = 5, nsplit = c(4L, 3L), reassign = FALSE)
@@ -17,6 +19,7 @@ test_that("reps can be printed", {
})

test_that("resampling iterations equals folds * repeats", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
rsp = rsmp("repeated_spcv_tiles",
repeats = 2, reassign = FALSE, nsplit = c(4L, 3L))
@@ -26,6 +29,7 @@ test_that("resampling iterations equals folds * repeats", {
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_tiles",
@@ -50,6 +54,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit"
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_tiles",
@@ -73,6 +78,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", {
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_tiles",
@@ -98,6 +104,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation",
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_tiles",
@@ -123,6 +130,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation"
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_tiles",
@@ -148,6 +156,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset",
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user offset", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("repeated_spcv_tiles",
3 changes: 3 additions & 0 deletions tests/testthat/test-ResamplingSpCVBlock.R
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: selection =
})

test_that("mlr3spatiotempcv indices are the same as blockCV indices: cols and rows", {
skip_if_not_installed("sf")
task = test_make_blockCV_test_task()

sf::sf_use_s2(use_s2 = FALSE)
@@ -102,6 +103,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: cols and ro
})

test_that("mlr3spatiotempcv indices are the same as blockCV indices: rasterLayer", {
skip_if_not_installed("sf")

# cran test failure (Error: no arguments in initialization list)
testthat::skip_on_os("solaris")
@@ -140,6 +142,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: rasterLayer
})

test_that("Error when selection = checkboard and folds > 2", {
skip_if_not_installed("sf")
task = test_make_blockCV_test_task()
expect_error(rsmp("spcv_block", range = 10000L,
selection = "checkerboard", folds = 5)$instantiate(task))
1 change: 1 addition & 0 deletions tests/testthat/test-ResamplingSpCVDisc.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("mlr3spatiotempcv is equal to sperrorest (repeated)", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_disc", folds = 3L, radius = 200L, buffer = 200L)
7 changes: 7 additions & 0 deletions tests/testthat/test-ResamplingSpCVTiles.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("mlr3spatiotempcv is equal to sperrorest (repeated)", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles", reassign = FALSE, nsplit = c(4L, 3L))
@@ -21,6 +22,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated)", {
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles",
@@ -44,6 +46,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit"
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles",
@@ -67,6 +70,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", {
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles",
@@ -92,6 +96,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation",
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles",
@@ -117,6 +122,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation"
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles",
@@ -142,6 +148,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset",
})

test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user offset", {
skip_if_not_installed("sperrorest")
task = tsk("ecuador")
set.seed(42)
rsp = rsmp("spcv_tiles",
3 changes: 3 additions & 0 deletions tests/testthat/test-TaskClassifST.R
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ test_that("coordinates can be used as features", {
})

test_that("sf objects can be used for task creation", {
skip_if_not_installed("sf")
task = test_make_sf_twoclass_task()

expect_output(print(task))
@@ -33,6 +34,7 @@ test_that("sf objects can be used for task creation", {
})

test_that("sf objects can be used for task creation", {
skip_if_not_installed("sf")
task = test_make_sf_regr_task()

expect_output(print(task))
@@ -42,6 +44,7 @@ test_that("sf objects can be used for task creation", {

# https://github.com/mlr-org/mlr3spatiotempcv/issues/151
test_that("tasks created from sf objects do not duplicate rows", {
skip_if_not_installed("sf")
data = test_make_sf_twoclass_df()

task = TaskClassifST$new(
2 changes: 2 additions & 0 deletions tests/testthat/test-as_task.R
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ test_that("as_task_classif_st.data.rame works", {
})

test_that("as_task_classif_st.sf works", {
skip_if_not_installed("sf")
data("ecuador", package = "mlr3spatiotempcv")
ecuador_sf = sf::st_as_sf(ecuador, coords = c("x", "y"), crs = "epsg:32717")
new_task = as_task_classif_st(ecuador_sf, target = "slides", positive = "TRUE")
@@ -48,6 +49,7 @@ test_that("as_task_regr_st.data.rame works", {
})

test_that("as_task_regr_st.sf works", {
skip_if_not_installed("sf")
data("cookfarm_sample", package = "mlr3spatiotempcv")
cookfarm_sf = sf::st_as_sf(cookfarm_sample, coords = c("x", "y"), crs = 26911)
new_task = as_task_regr_st(cookfarm_sf, target = "PHIHOX")
4 changes: 4 additions & 0 deletions tests/testthat/test-autotuner.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
test_that("AutoTuner works with sptcv methods", {

skip_if_not_installed("mlr3tuning")
skip_if_not_installed("paradox")

library("paradox")
library("mlr3tuning")
library("mlr3spatiotempcv")
3 changes: 3 additions & 0 deletions tests/testthat/test-helper-DataBackend.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
test_that("get_coordinates function works", {

skip_if_not_installed("mlr3spatial")
skip_if_not_installed("sf")
requireNamespace("mlr3spatial", quietly = TRUE)
task_1 = tsk("ecuador")

@@ -15,6 +16,7 @@ test_that("get_coordinates function works", {

test_that("get_crs function works", {
skip_if_not_installed("mlr3spatial")
skip_if_not_installed("sf")
requireNamespace("mlr3spatial", quietly = TRUE)

task_1 = tsk("ecuador")
@@ -30,6 +32,7 @@ test_that("get_crs function works", {
test_that("assert_spatial_task function works", {

skip_if_not_installed("mlr3spatial")
skip_if_not_installed("sf")
requireNamespace("mlr3spatial", quietly = TRUE)

task_1 = tsk("ecuador")
8 changes: 8 additions & 0 deletions tests/testthat/test-mlr_sptcv_generic.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
library(mlr3)

test_that("no duplicated ids", {
skip_if_not_installed("blockCV")
skip_if_not_installed("sf")
spcv_rsp = mlr_resamplings$mget(
as.data.table(mlr_resamplings)[map_lgl(key, grepl, pattern = "spcv"), key]
)
@@ -17,6 +19,8 @@ test_that("no duplicated ids", {
})

test_that("grouping throws errors when 'groups' is set", {
skip_if_not_installed("blockCV")
skip_if_not_installed("sf")
task = test_make_twoclass_task(group = TRUE)

spcv_rsp = rsmps(c("spcv_coords", "spcv_env"), folds = 2)
@@ -31,6 +35,8 @@ test_that("grouping throws errors when 'groups' is set", {
})

test_that("train and test set getter functions are working", {
skip_if_not_installed("blockCV")
skip_if_not_installed("sf")
task = test_make_twoclass_task()

spcv_rsp = rsmps(c("spcv_coords", "spcv_env"), folds = 2)
@@ -45,6 +51,8 @@ test_that("train and test set getter functions are working", {
})

test_that("train and test set getter functions are working", {
skip_if_not_installed("blockCV")
skip_if_not_installed("sf")
task = test_make_twoclass_task()

spcv_rsp = rsmps(c("repeated_spcv_coords", "repeated_spcv_env"), folds = 2)

0 comments on commit 9f1bb0e

Please sign in to comment.