Skip to content

Commit cc6bb34

Browse files
committed
expect_warning -> expect_snapshot when regex arg present
also transitioned on output of `translate`
1 parent c8297e2 commit cc6bb34

9 files changed

+32
-48
lines changed

tests/testthat/test_boost_tree_C50.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,11 @@ test_that('argument checks for data dimensions', {
143143
set_engine("C5.0") %>%
144144
set_mode("classification")
145145

146-
expect_warning(
147-
f_fit <- spec %>% fit(species ~ ., data = penguins),
148-
"1000 samples were requested"
146+
expect_snapshot(
147+
f_fit <- spec %>% fit(species ~ ., data = penguins)
149148
)
150-
expect_warning(
151-
xy_fit <- spec %>% fit_xy(x = penguins[, -1], y = penguins$species),
152-
"1000 samples were requested"
149+
expect_snapshot(
150+
xy_fit <- spec %>% fit_xy(x = penguins[, -1], y = penguins$species)
153151
)
154152

155153
expect_equal(f_fit$fit$control$minCases, nrow(penguins))

tests/testthat/test_boost_tree_xgboost.R

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,11 @@ test_that('early stopping', {
285285
regex = NA
286286
)
287287

288-
expect_warning(
288+
expect_snapshot(
289289
reg_fit <-
290290
boost_tree(trees = 20, stop_iter = 30, mode = "regression") %>%
291291
set_engine("xgboost", validation = .1) %>%
292-
fit(mpg ~ ., data = mtcars[-(1:4), ]),
293-
regex = "`early_stop` was reduced to 19"
292+
fit(mpg ~ ., data = mtcars[-(1:4), ])
294293
)
295294
expect_error(
296295
reg_fit <-
@@ -347,8 +346,7 @@ test_that('xgboost data conversion', {
347346
expect_equal(xgboost::getinfo(from_df$data, name = "label")[1:5], rep(1, 5))
348347

349348
mtcars_y <- factor(mtcars$mpg < 15, levels = c(TRUE, FALSE, "na"), labels = c("low", "high", "missing"))
350-
expect_warning(from_df <- parsnip:::as_xgb_data(mtcar_x, mtcars_y, event_level = "second"),
351-
regexp = "`event_level` can only be set for binary variables.")
349+
expect_snapshot(from_df <- parsnip:::as_xgb_data(mtcar_x, mtcars_y, event_level = "second"))
352350

353351
})
354352

@@ -395,13 +393,11 @@ test_that('argument checks for data dimensions', {
395393
penguins_dummy <- model.matrix(species ~ ., data = penguins)
396394
penguins_dummy <- as.data.frame(penguins_dummy[, -1])
397395

398-
expect_warning(
399-
f_fit <- spec %>% fit(species ~ ., data = penguins),
400-
"1000 samples were requested"
396+
expect_snapshot(
397+
f_fit <- spec %>% fit(species ~ ., data = penguins)
401398
)
402-
expect_warning(
403-
xy_fit <- spec %>% fit_xy(x = penguins_dummy, y = penguins$species),
404-
"1000 samples were requested"
399+
expect_snapshot(
400+
xy_fit <- spec %>% fit_xy(x = penguins_dummy, y = penguins$species)
405401
)
406402
expect_equal(f_fit$fit$params$colsample_bynode, 1)
407403
expect_equal(f_fit$fit$params$min_child_weight, nrow(penguins))

tests/testthat/test_decision_tree.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ test_that('argument checks for data dimensions', {
5656
set_engine("rpart") %>%
5757
set_mode("regression")
5858

59-
expect_warning(
60-
f_fit <- spec %>% fit(body_mass_g ~ ., data = penguins),
61-
"1000 samples were requested but there were 333 rows in the data. 333 will be used."
59+
expect_snapshot(
60+
f_fit <- spec %>% fit(body_mass_g ~ ., data = penguins)
6261
)
63-
expect_warning(
64-
xy_fit <- spec %>% fit_xy(x = penguins[, -6], y = penguins$body_mass_g),
65-
"1000 samples were requested but there were 333 rows in the data. 333 will be used."
62+
expect_snapshot(
63+
xy_fit <- spec %>% fit_xy(x = penguins[, -6], y = penguins$body_mass_g)
6664
)
6765

6866
expect_equal(f_fit$fit$control$minsplit, nrow(penguins))

tests/testthat/test_failed_models.R

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ test_that('numeric model', {
2525
set_engine("lm") %>%
2626
fit(compounds ~ ., data = hpc_bad, control = ctrl)
2727

28-
expect_warning(num_res <- predict(lm_mod, hpc_bad[1:11, -1]))
28+
expect_snapshot(num_res <- predict(lm_mod, hpc_bad[1:11, -1]))
2929
expect_equal(num_res, NULL)
3030

31-
expect_warning(ci_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "conf_int"))
31+
expect_snapshot(ci_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "conf_int"))
3232
expect_equal(ci_res, NULL)
3333

34-
expect_warning(pi_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "pred_int"))
34+
expect_snapshot(pi_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "pred_int"))
3535
expect_equal(pi_res, NULL)
3636

3737
})
@@ -44,22 +44,16 @@ test_that('classification model', {
4444
set_engine("glm") %>%
4545
fit(Class ~ log(funded_amnt) + int_rate + big_num, data = lending_club, control = ctrl)
4646

47-
expect_warning(
48-
cls_res <-
49-
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class))
47+
expect_snapshot(
48+
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class))
5049
)
51-
expect_equal(cls_res, NULL)
5250

53-
expect_warning(
54-
prb_res <-
55-
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class), type = "prob")
51+
expect_snapshot(
52+
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class), type = "prob")
5653
)
57-
expect_equal(prb_res, NULL)
5854

59-
expect_warning(
60-
ci_res <-
61-
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class), type = "conf_int")
55+
expect_snapshot(
56+
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class), type = "conf_int")
6257
)
63-
expect_equal(ci_res, NULL)
6458
})
6559

tests/testthat/test_mlp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_that('updating', {
4040
test_that('bad input', {
4141
expect_error(mlp(mode = "time series"))
4242
expect_error(translate(mlp(mode = "classification") %>% set_engine("wat?")))
43-
expect_warning(translate(mlp(mode = "regression") %>% set_engine("nnet", formula = y ~ x)))
43+
expect_snapshot(translate(mlp(mode = "regression") %>% set_engine("nnet", formula = y ~ x)))
4444
expect_error(translate(mlp(mode = "classification", x = x, y = y) %>% set_engine("keras")))
4545
expect_error(translate(mlp(mode = "regression", formula = y ~ x) %>% set_engine()))
4646
})

tests/testthat/test_multinom_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ test_that('bad input', {
4242
expect_error(multinom_reg(mode = "regression"))
4343
expect_error(translate(multinom_reg(penalty = 0.1) %>% set_engine("wat?")))
4444
expect_error(multinom_reg(penalty = 0.1) %>% set_engine())
45-
expect_warning(translate(multinom_reg(penalty = 0.1) %>% set_engine("glmnet", x = hpc[,1:3], y = hpc$class)))
45+
expect_snapshot(translate(multinom_reg(penalty = 0.1) %>% set_engine("glmnet", x = hpc[,1:3], y = hpc$class)))
4646
})

tests/testthat/test_nearest_neighbor_kknn.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,12 @@ test_that('argument checks for data dimensions', {
199199
set_engine("kknn") %>%
200200
set_mode("regression")
201201

202-
expect_warning(
203-
f_fit <- spec %>% fit(body_mass_g ~ ., data = penguins),
204-
"1000 samples were requested but there were 333 rows in the data. 328 will be used."
202+
expect_snapshot(
203+
f_fit <- spec %>% fit(body_mass_g ~ ., data = penguins)
205204
)
206205

207-
expect_warning(
208-
xy_fit <- spec %>% fit_xy(x = penguins[, -6], y = penguins$body_mass_g),
209-
"1000 samples were requested but there were 333 rows in the data. 328 will be used."
206+
expect_snapshot(
207+
xy_fit <- spec %>% fit_xy(x = penguins[, -6], y = penguins$body_mass_g)
210208
)
211209

212210
expect_equal(f_fit$fit$best.parameters$k, nrow(penguins) - 5)

tests/testthat/test_nullmodel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_that('bad input', {
44
expect_error(translate(null_model(mode = "regression") %>% set_engine()))
55
expect_error(translate(null_model() %>% set_engine("wat?")))
66
expect_error(translate(null_model(formula = y ~ x)))
7-
expect_warning(
7+
expect_snapshot(
88
translate(
99
null_model(mode = "regression") %>% set_engine("parsnip", x = hpc[,1:3], y = hpc$class)
1010
)

tests/testthat/test_surv_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ test_that('bad input', {
2525

2626
test_that("deprecation warning", {
2727
rlang::local_options(lifecycle_verbosity = "warning")
28-
expect_warning(surv_reg())
28+
expect_snapshot(surv_reg())
2929
})

0 commit comments

Comments
 (0)