Skip to content

Commit

Permalink
- Robustify CLUTO test setup (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-s authored May 26, 2022
1 parent a0119db commit a5c3824
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ autoplot-repeated-show-blocks-true-show-labels-true.svg$
^figs$
^CRAN-SUBMISSION$
^cache$
^inst/vcluster$
^inst/vcluster\.exe$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,4 @@ cover-letter.pdf
*.zip
CRAN-SUBMISSION
.editorconfig
inst/vcluster*
5 changes: 4 additions & 1 deletion R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ check_cluto_path = function() {
package = "mlr3spatiotempcv"))
}, # nocov end
"Linux" = {
if (Sys.info()[["machine"]] != "x86_64") {
stopf("CLUTO on Linux only works on x86_64 architecture.")
}
if (!file.exists(system.file("vcluster",
package = "mlr3spatiotempcv"))) {
stopf("vcluster.exe not found. Please install CLUTO first.
stopf("vcluster executable not found. Please install CLUTO first.
See ?ResamplingSptCVCluto for instructions.", wrap = TRUE)
}
# nocov start
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/setup-cluto.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# install CLUTO executable into $PROJ_ROOT/inst/ for testthat to work
# system.file() is shimed in testthat and pkgload::load_all()
if (Sys.getenv("NOT_CRAN") != "") {
gist_url = "https://gist.githubusercontent.com/pat-s/6430470cf817050e27d26c43c0e9be72/raw/9a1bee360880be5c2ab8dc5168b4ff9543e499d6/install-cluto.R"
if (Sys.info()[["sysname"]] == "Linux") {
if (!file.exists(system.file("vcluster", package = "mlr3spatiotempcv"))) {
source(gist_url)
}
}
if (Sys.info()[["sysname"]] == "Windows") {
if (!file.exists(system.file("vcluster.exe", package = "mlr3spatiotempcv"))) {
source(gist_url)
}
}
}
23 changes: 9 additions & 14 deletions tests/testthat/test-ResamplingSptCVCluto.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ test_that("resampling iterations equals folds", {
skip_on_cran()
skip_on_os("mac")
skip_if_not_installed("skmeans")
skip_if(Sys.info()[["machine"]] != "x86_64")

library(mlr3spatiotempcv)
task = tsk("cookfarm")
rsp = rsmp("sptcv_cluto", folds = 2, time_var = "Date")
rsp$instantiate(task)
Expand All @@ -16,11 +18,13 @@ test_that("reps can be printed", {
skip_on_cran()
skip_on_os("mac")
skip_if_not_installed("skmeans")
skip_if(Sys.info()[["machine"]] != "x86_64")

task = tsk("cookfarm")
rsp = rsmp("repeated_sptcv_cluto",
folds = 3, repeats = 5,
time_var = "Date")
time_var = "Date"
)
rsp$instantiate(task)

expect_equal(rsp$repeats(4:8), c(2, 2, 2, 3, 3))
Expand All @@ -30,35 +34,26 @@ test_that("resampling iterations equals folds * repeats", {
skip_on_cran()
skip_on_os("mac")
skip_if_not_installed("skmeans")
skip_if(Sys.info()[["machine"]] != "x86_64")

task = tsk("cookfarm")
rsp = rsmp("repeated_sptcv_cluto",
folds = 3, repeats = 2,
time_var = "Date")
time_var = "Date"
)
rsp$instantiate(task)

expect_equal(rsp$iters, 6)
})

test_that("check_cluto_path() works", {
skip_on_cran()
skip_on_os("mac")
skip_if_not_installed("skmeans")
withr::with_envvar(c("CLUTO_PATH" = ""), {
task = tsk("cookfarm")
rsp = rsmp("sptcv_cluto",
folds = 3,
time_var = "Date")
expect_error(rsp$instantiate(task), "vcluster.exe not found")
})
})

# spatial only -----------------------------------------------------------------

test_that("clustering on coords only works", {
skip_on_cran()
skip_on_os("mac")
skip_if_not_installed("skmeans")
skip_if(Sys.info()[["machine"]] != "x86_64")

task = tsk("cookfarm")
rsp = rsmp("sptcv_cluto", folds = 2)
Expand Down

0 comments on commit a5c3824

Please sign in to comment.