From ef4fbbf4c68433019a41c8b4123a0d9e168568e0 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 8 Nov 2024 14:44:51 -0800 Subject: [PATCH 1/2] don't call source() in tests --- tests/testthat/test-discretize_cart.R | 2 -- tests/testthat/test-discretize_xgb.R | 2 -- tests/testthat/test-embed.R | 3 --- tests/testthat/test-feature_hash.R | 3 --- tests/testthat/test-lencode_bayes.R | 3 --- tests/testthat/test-lencode_glm.R | 3 --- tests/testthat/test-lencode_mixed.R | 3 --- tests/testthat/test-pca_sparse.R | 2 -- tests/testthat/test-pca_sparse_bayes.R | 2 -- tests/testthat/test-pca_truncated.R | 2 -- tests/testthat/test-umap.R | 2 -- tests/testthat/test-woe.R | 2 -- 12 files changed, 29 deletions(-) diff --git a/tests/testthat/test-discretize_cart.R b/tests/testthat/test-discretize_cart.R index 794960a..9c99e55 100644 --- a/tests/testthat/test-discretize_cart.R +++ b/tests/testthat/test-discretize_cart.R @@ -2,8 +2,6 @@ library(testthat) library(dplyr) library(rpart) -source(test_path("make_binned_data.R")) - set.seed(8497) sim_tr_cls <- sim_data_2class(1000) sim_te_cls <- sim_data_2class(100) diff --git a/tests/testthat/test-discretize_xgb.R b/tests/testthat/test-discretize_xgb.R index 1dc3686..5aebc82 100644 --- a/tests/testthat/test-discretize_xgb.R +++ b/tests/testthat/test-discretize_xgb.R @@ -5,8 +5,6 @@ skip_on_cran() skip_if_not_installed("xgboost") skip_if_not_installed("modeldata") -source(test_path("make_binned_data.R")) - data("credit_data", package = "modeldata") data("ames", package = "modeldata") data("attrition", package = "modeldata") diff --git a/tests/testthat/test-embed.R b/tests/testthat/test-embed.R index b60cdc1..682693d 100644 --- a/tests/testthat/test-embed.R +++ b/tests/testthat/test-embed.R @@ -1,6 +1,3 @@ -source(testthat::test_path("make_example_data.R")) -source(testthat::test_path("test-helpers.R")) - # Stops noisy tensorflow messages withr::local_envvar(TF_CPP_MIN_LOG_LEVEL = "2") diff --git a/tests/testthat/test-feature_hash.R b/tests/testthat/test-feature_hash.R index d99840d..fce451b 100644 --- a/tests/testthat/test-feature_hash.R +++ b/tests/testthat/test-feature_hash.R @@ -1,6 +1,3 @@ -source(testthat::test_path("make_example_data.R")) -source(testthat::test_path("test-helpers.R")) - test_that("basic usage", { skip_on_cran() skip_if_not_installed("keras") diff --git a/tests/testthat/test-lencode_bayes.R b/tests/testthat/test-lencode_bayes.R index b06452b..13b937e 100644 --- a/tests/testthat/test-lencode_bayes.R +++ b/tests/testthat/test-lencode_bayes.R @@ -1,6 +1,3 @@ -source(testthat::test_path("make_example_data.R")) -source(testthat::test_path("test-helpers.R")) - opts <- list(seed = 34677, chains = 2, iter = 500) omit_warning <- function(pattern) { diff --git a/tests/testthat/test-lencode_glm.R b/tests/testthat/test-lencode_glm.R index 5115ed4..2890166 100644 --- a/tests/testthat/test-lencode_glm.R +++ b/tests/testthat/test-lencode_glm.R @@ -1,6 +1,3 @@ -source(testthat::test_path("make_example_data.R")) -source(testthat::test_path("test-helpers.R")) - test_that("factor encoded predictor", { class_test <- recipe(x2 ~ ., data = ex_dat) %>% step_lencode_glm(x3, outcome = vars(x2), id = "id") %>% diff --git a/tests/testthat/test-lencode_mixed.R b/tests/testthat/test-lencode_mixed.R index 3cffa10..69bb3d4 100644 --- a/tests/testthat/test-lencode_mixed.R +++ b/tests/testthat/test-lencode_mixed.R @@ -1,6 +1,3 @@ -source(testthat::test_path("make_example_data.R")) -source(testthat::test_path("test-helpers.R")) - test_that("factor encoded predictor", { skip_if_not_installed("Matrix", "1.6-2") skip_if_not_installed("lme4", "1.1-35.1") diff --git a/tests/testthat/test-pca_sparse.R b/tests/testthat/test-pca_sparse.R index 1c10600..d004b9c 100644 --- a/tests/testthat/test-pca_sparse.R +++ b/tests/testthat/test-pca_sparse.R @@ -1,5 +1,3 @@ -source(testthat::test_path("test-helpers.R")) - test_that("step_pca_sparse", { skip_if_not_installed("irlba") skip_if_not_installed("modeldata") diff --git a/tests/testthat/test-pca_sparse_bayes.R b/tests/testthat/test-pca_sparse_bayes.R index f17a778..ef6e93e 100644 --- a/tests/testthat/test-pca_sparse_bayes.R +++ b/tests/testthat/test-pca_sparse_bayes.R @@ -1,5 +1,3 @@ -source(testthat::test_path("test-helpers.R")) - test_that("step_pca_sparse_bayes", { skip_if_not_installed("VBsparsePCA") skip_if_not_installed("modeldata") diff --git a/tests/testthat/test-pca_truncated.R b/tests/testthat/test-pca_truncated.R index 224f7b9..2536733 100644 --- a/tests/testthat/test-pca_truncated.R +++ b/tests/testthat/test-pca_truncated.R @@ -1,5 +1,3 @@ -source(testthat::test_path("test-helpers.R")) - test_that("step_pca_truncated", { skip_if_not_installed("irlba") skip_if_not_installed("modeldata") diff --git a/tests/testthat/test-umap.R b/tests/testthat/test-umap.R index eec6b56..a5c221c 100644 --- a/tests/testthat/test-umap.R +++ b/tests/testthat/test-umap.R @@ -1,5 +1,3 @@ -source(testthat::test_path("test-helpers.R")) - iris_dat <- iris iris_dat[, 1:4] <- scale(iris_dat[, 1:4]) diff --git a/tests/testthat/test-woe.R b/tests/testthat/test-woe.R index d5735f0..54ea928 100644 --- a/tests/testthat/test-woe.R +++ b/tests/testthat/test-woe.R @@ -1,5 +1,3 @@ -source(testthat::test_path("test-helpers.R")) - set.seed(1) df <- data.frame( x1 = sample(c("A", "B", "C"), size = 20, replace = TRUE) %>% factor(), From a24956060e23162ea3461dd67eb2fde9d44443e8 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 8 Nov 2024 14:45:00 -0800 Subject: [PATCH 2/2] rename test helpers --- tests/testthat/{make_binned_data.R => helper-make_binned_data.R} | 0 .../testthat/{make_example_data.R => helper-make_example_data.R} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/testthat/{make_binned_data.R => helper-make_binned_data.R} (100%) rename tests/testthat/{make_example_data.R => helper-make_example_data.R} (100%) diff --git a/tests/testthat/make_binned_data.R b/tests/testthat/helper-make_binned_data.R similarity index 100% rename from tests/testthat/make_binned_data.R rename to tests/testthat/helper-make_binned_data.R diff --git a/tests/testthat/make_example_data.R b/tests/testthat/helper-make_example_data.R similarity index 100% rename from tests/testthat/make_example_data.R rename to tests/testthat/helper-make_example_data.R