Skip to content

Commit 6a84962

Browse files
authored
Merge pull request #231 from patr1ckm/test-ref-ctrl
REF test_control to helper-objects
2 parents 4230ef8 + c6d686e commit 6a84962

23 files changed

+27
-98
lines changed

tests/testthat/helper-objects.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
2+
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
3+
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

tests/testthat/test_boost_tree_C50.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library(dplyr)
66
# ------------------------------------------------------------------------------
77

88
context("boosted tree execution with C5.0")
9+
source("helper-objects.R")
910

1011
data("lending_club")
1112
lending_club <- head(lending_club, 200)
@@ -17,10 +18,6 @@ lc_basic <-
1718
boost_tree(mode = "classification") %>%
1819
set_engine("C5.0", bands = 2)
1920

20-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
21-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
22-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
23-
2421
# ------------------------------------------------------------------------------
2522

2623
test_that('C5.0 execution', {

tests/testthat/test_boost_tree_spark.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ library(dplyr)
55
# ------------------------------------------------------------------------------
66

77
context("boosted tree execution with spark")
8-
9-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
10-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
11-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
8+
source("helper-objects.R")
129

1310
# ------------------------------------------------------------------------------
1411

tests/testthat/test_boost_tree_xgboost.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ library(parsnip)
44
# ------------------------------------------------------------------------------
55

66
context("boosted tree execution with xgboost")
7+
source("helper-objects.R")
78

89
num_pred <- names(iris)[1:4]
910

1011
iris_xgboost <-
1112
boost_tree(trees = 2, mode = "classification") %>%
1213
set_engine("xgboost")
1314

14-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
15-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
16-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
17-
1815
# ------------------------------------------------------------------------------
1916

2017
test_that('xgboost execution, classification', {
@@ -101,10 +98,6 @@ bad_rf_reg <-
10198
boost_tree(mode = "regression") %>%
10299
set_engine("xgboost", sampsize = -10)
103100

104-
ctrl <- list(verbosity = 1, catch = FALSE)
105-
caught_ctrl <- list(verbosity = 1, catch = TRUE)
106-
quiet_ctrl <- list(verbosity = 0, catch = TRUE)
107-
108101
test_that('xgboost execution, regression', {
109102

110103
skip_if_not_installed("xgboost")

tests/testthat/test_linear_reg.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library(tibble)
77

88
context("linear regression")
99
source("helpers.R")
10+
source("helper-objects.R")
1011

1112
# ------------------------------------------------------------------------------
1213

@@ -209,10 +210,6 @@ num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
209210
iris_bad_form <- as.formula(Species ~ term)
210211
iris_basic <- linear_reg() %>% set_engine("lm")
211212

212-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
213-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
214-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
215-
216213
# ------------------------------------------------------------------------------
217214

218215
test_that('lm execution', {

tests/testthat/test_linear_reg_glmnet.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library(tidyr)
66
# ------------------------------------------------------------------------------
77

88
context("linear regression execution with glmnet")
9+
source("helper-objects.R")
910

1011
num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
1112
iris_bad_form <- as.formula(Species ~ term)
@@ -14,10 +15,6 @@ iris_basic <- linear_reg(penalty = .1, mixture = .3) %>%
1415
no_lambda <- linear_reg(mixture = .3) %>%
1516
set_engine("glmnet")
1617

17-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
18-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
19-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
20-
2118
# ------------------------------------------------------------------------------
2219

2320
test_that('glmnet execution', {

tests/testthat/test_linear_reg_keras.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library(tibble)
77

88
context("keras linear regression")
99
source("helpers.R")
10+
source("helper-objects.R")
1011

1112
# ------------------------------------------------------------------------------
1213

tests/testthat/test_linear_reg_spark.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ library(dplyr)
55
# ------------------------------------------------------------------------------
66

77
context("linear regression execution with spark")
8-
9-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
10-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
11-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
8+
source("helper-objects.R")
129

1310
# ------------------------------------------------------------------------------
1411

tests/testthat/test_logistic_reg.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library(tibble)
77

88
context("logistic regression")
99
source("helpers.R")
10+
source("helper-objects.R")
1011

1112
# ------------------------------------------------------------------------------
1213

@@ -219,9 +220,6 @@ lending_club <- head(lending_club, 200)
219220
lc_form <- as.formula(Class ~ log(funded_amnt) + int_rate)
220221
num_pred <- c("funded_amnt", "annual_inc", "num_il_tl")
221222
lc_basic <- logistic_reg() %>% set_engine("glm")
222-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
223-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
224-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
225223

226224
test_that('glm execution', {
227225

tests/testthat/test_logistic_reg_glmnet.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library(tidyr)
77
# ------------------------------------------------------------------------------
88

99
context("logistic regression execution with glmnet")
10+
source("helper-objects.R")
1011

1112
data("lending_club")
1213
lending_club <- head(lending_club, 200)
@@ -15,10 +16,6 @@ num_pred <- c("funded_amnt", "annual_inc", "num_il_tl")
1516
lc_bad_form <- as.formula(funded_amnt ~ term)
1617
lc_basic <- logistic_reg() %>% set_engine("glmnet")
1718

18-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
19-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
20-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
21-
2219
# ------------------------------------------------------------------------------
2320

2421
test_that('glmnet execution', {

tests/testthat/test_logistic_reg_spark.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ library(dplyr)
55
# ------------------------------------------------------------------------------
66

77
context("logistic regression execution with spark")
8-
9-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
10-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
11-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
8+
source("helper-objects.R")
129

1310
# ------------------------------------------------------------------------------
1411

tests/testthat/test_logistic_reg_stan.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library(tibble)
66
# ------------------------------------------------------------------------------
77

88
context("execution tests for stan logistic regression")
9+
source("helper-objects.R")
910

1011
data("lending_club")
1112
lending_club <- head(lending_club, 200)

tests/testthat/test_mars.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library(rlang)
66

77
context("mars tests")
88
source("helpers.R")
9+
source("helper-objects.R")
910

1011
# ------------------------------------------------------------------------------
1112

@@ -124,10 +125,6 @@ num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
124125
iris_bad_form <- as.formula(Species ~ term)
125126
iris_basic <- mars(mode = "regression") %>% set_engine("earth")
126127

127-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
128-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
129-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
130-
131128
# ------------------------------------------------------------------------------
132129

133130
test_that('mars execution', {

tests/testthat/test_mlp_keras.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ library(tibble)
55
# ------------------------------------------------------------------------------
66

77
context("simple neural network execution with keras")
8+
source("helper-objects.R")
89

910
num_pred <- names(iris)[1:4]
1011

1112
iris_keras <-
1213
mlp(mode = "classification", hidden_units = 2, epochs = 10) %>%
1314
set_engine("keras", verbose = 0)
1415

15-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
16-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
17-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
18-
1916
nn_dat <- read.csv("nnet_test.txt")
2017

2118
# ------------------------------------------------------------------------------
@@ -143,10 +140,6 @@ bad_keras_reg <-
143140
mlp(mode = "regression") %>%
144141
set_engine("keras", min.node.size = -10)
145142

146-
ctrl <- list(verbosity = 1, catch = FALSE)
147-
caught_ctrl <- list(verbosity = 1, catch = TRUE)
148-
quiet_ctrl <- list(verbosity = 0, catch = TRUE)
149-
150143
# ------------------------------------------------------------------------------
151144

152145

tests/testthat/test_mlp_nnet.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ library(parsnip)
44
# ------------------------------------------------------------------------------
55

66
context("simple neural network execution with nnet")
7+
source("helper-objects.R")
78

89
num_pred <- names(iris)[1:4]
910

1011
iris_nnet <-
1112
mlp(mode = "classification", hidden_units = 5) %>%
1213
set_engine("nnet")
1314

14-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
15-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
16-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
17-
1815
# ------------------------------------------------------------------------------
1916

2017
test_that('nnet execution, classification', {
@@ -94,10 +91,6 @@ bad_rf_reg <-
9491
mlp(mode = "regression") %>%
9592
set_engine("nnet", sampsize = -10)
9693

97-
ctrl <- list(verbosity = 1, catch = FALSE)
98-
caught_ctrl <- list(verbosity = 1, catch = TRUE)
99-
quiet_ctrl <- list(verbosity = 0, catch = TRUE)
100-
10194
# ------------------------------------------------------------------------------
10295

10396

tests/testthat/test_multinom_reg_glmnet.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ library(tibble)
66
# ------------------------------------------------------------------------------
77

88
context("multinom regression execution with glmnet")
9-
10-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
11-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
12-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
9+
source("helper-objects.R")
1310

1411
rows <- c(1, 51, 101)
1512

tests/testthat/test_multinom_reg_spark.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ library(dplyr)
55
# ------------------------------------------------------------------------------
66

77
context("multinomial regression execution with spark")
8-
9-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
10-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
11-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
8+
source("helper-objects.R")
129

1310
# ------------------------------------------------------------------------------
1411

tests/testthat/test_nearest_neighbor_kknn.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ library(rlang)
55
# ------------------------------------------------------------------------------
66

77
context("nearest neighbor execution with kknn")
8+
source("helper-objects.R")
89

910
num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
1011
iris_bad_form <- as.formula(Species ~ term)
@@ -13,10 +14,6 @@ iris_basic <- nearest_neighbor(mode = "classification",
1314
weight_func = "triangular") %>%
1415
set_engine("kknn")
1516

16-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
17-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
18-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
19-
2017
# ------------------------------------------------------------------------------
2118

2219
test_that('kknn execution', {

tests/testthat/test_rand_forest_randomForest.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ library(tibble)
55
# ------------------------------------------------------------------------------
66

77
context("random forest execution with randomForest")
8+
source("helper-objects.R")
89

910
# ------------------------------------------------------------------------------
1011

@@ -17,10 +18,6 @@ lc_basic <- rand_forest(mode = "classification") %>%
1718
bad_rf_cls <- rand_forest(mode = "classification") %>%
1819
set_engine("randomForest", sampsize = -10)
1920

20-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
21-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
22-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
23-
2421
# ------------------------------------------------------------------------------
2522

2623
test_that('randomForest classification execution', {
@@ -156,10 +153,6 @@ bad_ranger_reg <- rand_forest(mode = "regression") %>%
156153
bad_rf_reg <- rand_forest(mode = "regression") %>%
157154
set_engine("randomForest", sampsize = -10)
158155

159-
ctrl <- list(verbosity = 1, catch = FALSE)
160-
caught_ctrl <- list(verbosity = 1, catch = TRUE)
161-
quiet_ctrl <- list(verbosity = 0, catch = TRUE)
162-
163156
# ------------------------------------------------------------------------------
164157

165158
test_that('randomForest regression execution', {

tests/testthat/test_rand_forest_ranger.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library(rlang)
66
# ------------------------------------------------------------------------------
77

88
context("random forest execution with ranger")
9+
source("helper-objects.R")
910

1011
# ------------------------------------------------------------------------------
1112

@@ -19,10 +20,6 @@ lc_ranger <- rand_forest(mode = "classification") %>% set_engine("ranger", seed
1920
bad_ranger_cls <- rand_forest(mode = "classification") %>% set_engine("ranger", replace = "bad")
2021
bad_rf_cls <- rand_forest(mode = "classification") %>% set_engine("ranger", sampsize = -10)
2122

22-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
23-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
24-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
25-
2623
# ------------------------------------------------------------------------------
2724

2825
test_that('ranger classification execution', {
@@ -178,10 +175,6 @@ car_basic <- rand_forest(mode = "regression") %>% set_engine("ranger")
178175
bad_ranger_reg <- rand_forest(mode = "regression") %>% set_engine("ranger", replace = "bad")
179176
bad_rf_reg <- rand_forest(mode = "regression") %>% set_engine("ranger", sampsize = -10)
180177

181-
ctrl <- list(verbosity = 1, catch = FALSE)
182-
caught_ctrl <- list(verbosity = 1, catch = TRUE)
183-
quiet_ctrl <- list(verbosity = 0, catch = TRUE)
184-
185178
# ------------------------------------------------------------------------------
186179

187180
test_that('ranger regression execution', {

tests/testthat/test_rand_forest_spark.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ library(dplyr)
55
# ------------------------------------------------------------------------------
66

77
context("random forest execution with spark")
8-
9-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
10-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
11-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
8+
source("helper-objects.R")
129

1310
# ------------------------------------------------------------------------------
1411

tests/testthat/test_surv_reg_flexsurv.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ library(tibble)
66

77
# ------------------------------------------------------------------------------
88

9+
source("helper-objects.R")
10+
911
basic_form <- Surv(time, status) ~ age
1012
complete_form <- Surv(time) ~ age
1113

1214
surv_basic <- surv_reg() %>% set_engine("flexsurv")
13-
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
14-
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
15-
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
1615

1716
# ------------------------------------------------------------------------------
1817

0 commit comments

Comments
 (0)