From a5c382470231033bbd561ed25172a494db9953ea Mon Sep 17 00:00:00 2001 From: Patrick Schratz Date: Thu, 26 May 2022 14:25:51 +0200 Subject: [PATCH] - Robustify CLUTO test setup (#182) --- .Rbuildignore | 2 ++ .gitignore | 1 + R/helper.R | 5 ++++- tests/testthat/setup-cluto.R | 15 ++++++++++++++ tests/testthat/test-ResamplingSptCVCluto.R | 23 +++++++++------------- 5 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 tests/testthat/setup-cluto.R diff --git a/.Rbuildignore b/.Rbuildignore index 30ab3e83e..36f2c5108 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -39,3 +39,5 @@ autoplot-repeated-show-blocks-true-show-labels-true.svg$ ^figs$ ^CRAN-SUBMISSION$ ^cache$ +^inst/vcluster$ +^inst/vcluster\.exe$ diff --git a/.gitignore b/.gitignore index 4bad55606..545ce603a 100644 --- a/.gitignore +++ b/.gitignore @@ -418,3 +418,4 @@ cover-letter.pdf *.zip CRAN-SUBMISSION .editorconfig +inst/vcluster* diff --git a/R/helper.R b/R/helper.R index 3a788fe46..aa9f6f760 100644 --- a/R/helper.R +++ b/R/helper.R @@ -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 diff --git a/tests/testthat/setup-cluto.R b/tests/testthat/setup-cluto.R new file mode 100644 index 000000000..464baa7ec --- /dev/null +++ b/tests/testthat/setup-cluto.R @@ -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) + } + } +} diff --git a/tests/testthat/test-ResamplingSptCVCluto.R b/tests/testthat/test-ResamplingSptCVCluto.R index a6ed6ea50..8c6bf2d6c 100644 --- a/tests/testthat/test-ResamplingSptCVCluto.R +++ b/tests/testthat/test-ResamplingSptCVCluto.R @@ -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) @@ -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)) @@ -30,28 +34,18 @@ 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 ----------------------------------------------------------------- @@ -59,6 +53,7 @@ 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)