Skip to content

Commit 1f48072

Browse files
committed
expect_error() -> expect_snapshot(error = TRUE)
1 parent eba5762 commit 1f48072

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1415
-181
lines changed

tests/testthat/_snaps/adds.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# adding row indicies
2+
3+
Code
4+
as.matrix(mtcars) %>% add_rowindex()
5+
Condition
6+
Error in `add_rowindex()`:
7+
! `x` should be a data frame.
8+

tests/testthat/_snaps/args_and_modes.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
# pipe arguments
2+
3+
Code
4+
rand_forest() %>% set_args()
5+
Condition
6+
Error in `set_args()`:
7+
! Please pass at least one named argument.
8+
9+
# pipe engine
10+
11+
Code
12+
rand_forest() %>% set_mode()
13+
Condition
14+
Error in `set_mode()`:
15+
! Available modes for model type rand_forest are: "unknown", "classification", "regression", and "censored regression".
16+
17+
---
18+
19+
Code
20+
rand_forest() %>% set_mode(2)
21+
Condition
22+
Error in `set_mode()`:
23+
! 2 is not a known mode for model `rand_forest()`.
24+
25+
---
26+
27+
Code
28+
rand_forest() %>% set_mode("haberdashery")
29+
Condition
30+
Error in `set_mode()`:
31+
! "haberdashery" is not a known mode for model `rand_forest()`.
32+
133
# can't set a mode that isn't allowed by the model spec
234

335
Code

tests/testthat/_snaps/boost_tree.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
Error in `boost_tree()`:
2424
! "bogus" is not a known mode for model `boost_tree()`.
2525

26+
---
27+
28+
Code
29+
translate(boost_tree(formula = y ~ x))
30+
Condition
31+
Error in `boost_tree()`:
32+
! unused argument (formula = y ~ x)
33+
2634
# check_args() works
2735

2836
Code

tests/testthat/_snaps/boost_tree_C5.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# C5.0 execution
2+
3+
Code
4+
res <- fit(lc_basic, funded_amnt ~ term, data = lending_club, engine = "C5.0",
5+
control = ctrl)
6+
Condition
7+
Error in `glue()`:
8+
! Expecting '}'
9+
110
# submodel prediction
211

312
Code

tests/testthat/_snaps/boost_tree_xgboost.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# xgboost execution, classification
2+
3+
Code
4+
res <- parsnip::fit(hpc_xgboost, class ~ novar, data = hpc, control = ctrl)
5+
Condition
6+
Error:
7+
! object 'novar' not found
8+
9+
# xgboost execution, regression
10+
11+
Code
12+
res <- parsnip::fit_xy(car_basic, x = mtcars[, num_pred], y = factor(mtcars$vs),
13+
control = ctrl)
14+
Condition
15+
Error in `check_outcome()`:
16+
! For a regression model, the outcome should be `numeric`, not a `factor`.
17+
118
# submodel prediction
219

320
Code
@@ -6,6 +23,25 @@
623
Error in `multi_predict()`:
724
! Please use `new_data` instead of `newdata`.
825

26+
# validation sets
27+
28+
Code
29+
reg_fit <- boost_tree(trees = 20, mode = "regression") %>% set_engine("xgboost",
30+
validation = 3) %>% fit(mpg ~ ., data = mtcars[-(1:4), ])
31+
Condition
32+
Error in `parsnip::xgb_train()`:
33+
! `validation` should be on [0, 1).
34+
35+
# early stopping
36+
37+
Code
38+
reg_fit <- boost_tree(trees = 20, stop_iter = 0, mode = "regression") %>%
39+
set_engine("xgboost", validation = 0.1) %>% fit(mpg ~ ., data = mtcars[-(1:4),
40+
])
41+
Condition
42+
Error in `parsnip::xgb_train()`:
43+
! `early_stop` should be on [2, 20).
44+
945
# xgboost data conversion
1046

1147
Code
@@ -14,6 +50,16 @@
1450
Warning:
1551
`event_level` can only be set for binary outcomes.
1652

53+
# count/proportion parameters
54+
55+
Code
56+
boost_tree(mtry = 0.9, trees = 4) %>% set_engine("xgboost") %>% set_mode(
57+
"regression") %>% fit(mpg ~ ., data = mtcars)
58+
Condition
59+
Error in `recalc_param()`:
60+
! The option `counts = TRUE` was used but `colsample_bynode` was given as 0.9.
61+
i Please use a value >= 1 or use `counts = FALSE`.
62+
1763
# interface to param arguments
1864

1965
! Please supply elements of the `params` list argument as main arguments to `set_engine()` rather than as part of `params`.

tests/testthat/_snaps/convert_data.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
# numeric y and mixed x, fail missing data
2+
3+
Code
4+
.convert_form_to_xy_fit(rate ~ ., data = Puromycin_miss, na.action = na.fail,
5+
indicators = "traditional", remove_intercept = TRUE)
6+
Condition
7+
Error in `na.fail.default()`:
8+
! missing values in object
9+
10+
# bad args
11+
12+
Code
13+
.convert_form_to_xy_fit(mpg ~ ., data = mtcars, composition = "tibble",
14+
indicators = "traditional", remove_intercept = TRUE)
15+
Condition
16+
Error in `.convert_form_to_xy_fit()`:
17+
! `composition` should be either "data.frame", "matrix", or "dgCMatrix".
18+
19+
---
20+
21+
Code
22+
.convert_form_to_xy_fit(mpg ~ ., data = mtcars, weights = letters[1:nrow(mtcars)],
23+
indicators = "traditional", remove_intercept = TRUE)
24+
Condition
25+
Error in `.convert_form_to_xy_fit()`:
26+
! `weights` must be a numeric vector.
27+
28+
---
29+
30+
Code
31+
.convert_xy_to_form_fit(mtcars$disp, mtcars$mpg, remove_intercept = TRUE)
32+
Condition
33+
Error in `.convert_xy_to_form_fit()`:
34+
! `x` cannot be a vector.
35+
36+
---
37+
38+
Code
39+
.convert_xy_to_form_fit(mtcars[, 1:3], mtcars[, 2:5], remove_intercept = TRUE)
40+
Condition
41+
Error in `.convert_xy_to_form_fit()`:
42+
! `x` and `y` have the names "cyl" and "disp" in common.
43+
i Please ensure that `x` and `y` don't share any column names.
44+
145
# convert to matrix
246

347
Code

tests/testthat/_snaps/descriptors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# can be temporarily overriden at evaluation time
2+
3+
Code
4+
.cols()
5+
Condition
6+
Error in `descr_env$.cols()`:
7+
! Descriptor context not set
8+

tests/testthat/_snaps/extract.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
i The parsnip extension package baguette implements support for this specification.
3939
i Please install (if needed) and load to continue.
4040

41+
# extract single parameter from model with no parameters
42+
43+
Code
44+
extract_parameter_dials(lm_model, parameter = "none there")
45+
Condition
46+
Error in `extract_parameter_dials()`:
47+
! No parameter exists with id "none there".
48+
4149
# extract_fit_time() works
4250

4351
Code

tests/testthat/_snaps/fit_interfaces.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# wrong args
2+
3+
Code
4+
tester_xy(NULL, x = sprk, y = hpc, model = rmod)
5+
Condition
6+
Error in `tester_xy()`:
7+
! `x` should be a <data.frame/matrix>, not an <integer> object.
8+
9+
---
10+
11+
Code
12+
tester(NULL, f, data = as.matrix(hpc[, 1:4]))
13+
Condition
14+
Error in `tester()`:
15+
! `data` should be a <data.frame/dgCMatrix/tbl_spark>, not a double matrix.
16+
17+
# unknown modes
18+
19+
Code
20+
fit(mars_spec, am ~ ., data = mtcars)
21+
Condition
22+
Error in `fit()`:
23+
! Please set the mode in the model specification.
24+
25+
---
26+
27+
Code
28+
fit_xy(mars_spec, x = mtcars[, -1], y = mtcars[, 1])
29+
Condition
30+
Error in `fit_xy()`:
31+
! Please set the mode in the model specification.
32+
33+
---
34+
35+
Code
36+
fit_xy(mars_spec, x = lending_club[, 1:2], y = lending_club$Class)
37+
Condition
38+
Error in `fit_xy()`:
39+
! Please set the mode in the model specification.
40+
141
# misspecified formula argument
242

343
Code
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# regression
2+
3+
Code
4+
xy_res <- fit_xy(reg_mod, x = mtcars[, 1:5], y = mtcars$mpg, control = ctrl)
5+
Condition
6+
Error in `fit_xy()`:
7+
! Please use `fit()` rather than `fit_xy()` to train generalized additive models with the "mgcv" engine.
8+
i See `?model_formula()` to learn more.
9+
10+
# classification
11+
12+
Code
13+
xy_res <- fit_xy(cls_mod, x = two_class_dat[, 2:3], y = two_class_dat$Class,
14+
control = ctrl)
15+
Condition
16+
Error in `fit_xy()`:
17+
! Please use `fit()` rather than `fit_xy()` to train generalized additive models with the "mgcv" engine.
18+
i See `?model_formula()` to learn more.
19+

0 commit comments

Comments
 (0)