diff --git a/tests/testthat/_snaps/classdist.md b/tests/testthat/_snaps/classdist.md index 654dfea76..8165b3c3e 100644 --- a/tests/testthat/_snaps/classdist.md +++ b/tests/testthat/_snaps/classdist.md @@ -10,6 +10,30 @@ # case weights + Code + recipes:::get_center(mtcars, wts = wts, mfun = median) + Condition + Error in `recipes:::get_center()`: + ! The centering function requested cannot be used with case weights. + +--- + + Code + recipes:::get_both(mtcars, wts = wts, mfun = median) + Condition + Error in `recipes:::get_both()`: + ! The centering function requested cannot be used with case weights. + +--- + + Code + recipes:::get_both(mtcars, wts = wts, cfun = mad) + Condition + Error in `recipes:::get_both()`: + ! The variance function requested cannot be used with case weights. + +--- + Code rec_prep Message diff --git a/tests/testthat/_snaps/colcheck.md b/tests/testthat/_snaps/colcheck.md index b0b6c6870..f604ddf2e 100644 --- a/tests/testthat/_snaps/colcheck.md +++ b/tests/testthat/_snaps/colcheck.md @@ -16,6 +16,38 @@ x The following required columns are missing from `new_data`: `mpg`. i These columns have one of the following roles, which are required at `bake()` time: `predictor`. +# non-standard roles during bake/predict + + Code + predict(role_fit, Chicago %>% select(-date)) + Condition + Error in `validate_column_names()`: + ! The following required columns are missing: 'date'. + +--- + + Code + predict(role_wts_fit, head(Chicago) %>% select(-date)) + Condition + Error in `validate_column_names()`: + ! The following required columns are missing: 'date'. + +--- + + Code + predict(rm_fit, Chicago %>% select(-date)) + Condition + Error in `validate_column_names()`: + ! The following required columns are missing: 'date'. + +--- + + Code + predict(rm_fit, Chicago %>% select(-date)) + Condition + Error in `validate_column_names()`: + ! The following required columns are missing: 'date'. + # empty printing Code diff --git a/tests/testthat/_snaps/mutate_at.md b/tests/testthat/_snaps/mutate_at.md index 8bd222f5d..9778a5264 100644 --- a/tests/testthat/_snaps/mutate_at.md +++ b/tests/testthat/_snaps/mutate_at.md @@ -1,3 +1,12 @@ +# no input + + Code + iris_rec %>% step_mutate_at() %>% prep(training = iris) %>% bake(new_data = NULL, + composition = "data.frame") + Condition + Error in `step_mutate_at()`: + ! argument "fn" is missing, with no default + # empty printing Code diff --git a/tests/testthat/_snaps/rename_at.md b/tests/testthat/_snaps/rename_at.md index 6edcf2797..92c8167d4 100644 --- a/tests/testthat/_snaps/rename_at.md +++ b/tests/testthat/_snaps/rename_at.md @@ -7,6 +7,15 @@ Caused by error in `dplyr::rename_at()`: ! `.funs` must contain one renaming function, not 2. +# no input + + Code + iris_rec %>% step_rename_at() %>% prep(training = iris) %>% bake(new_data = NULL, + composition = "data.frame") + Condition + Error in `step_rename_at()`: + ! argument "fn" is missing, with no default + # empty printing Code diff --git a/tests/testthat/_snaps/update-role-requirements.md b/tests/testthat/_snaps/update-role-requirements.md index 132c1f50f..46bc2a4d0 100644 --- a/tests/testthat/_snaps/update-role-requirements.md +++ b/tests/testthat/_snaps/update-role-requirements.md @@ -49,6 +49,14 @@ Warning: Column `x` returned NaN, because variance cannot be calculated and scaling cannot be used. Consider avoiding `Inf` or `-Inf` values and/or setting `na_rm = TRUE` before normalizing. +--- + + Code + bake(rec, df) + Condition + Error in `step_scale()`: + ! The following required column is missing from `new_data`: x. + # can update `bake` requirements after prepping Code diff --git a/tests/testthat/_snaps/window.md b/tests/testthat/_snaps/window.md index 653593168..1eb0b6d37 100644 --- a/tests/testthat/_snaps/window.md +++ b/tests/testthat/_snaps/window.md @@ -14,6 +14,14 @@ Error in `step_window()`: ! `size` must be a number, not `NA`. +--- + + Code + rec %>% step_window(y1, size = NULL) + Condition + Error in `step_window()`: + ! `size` must be a number, not `NULL`. + --- Code diff --git a/tests/testthat/test-classdist.R b/tests/testthat/test-classdist.R index a535b9758..75bd58da6 100644 --- a/tests/testthat/test-classdist.R +++ b/tests/testthat/test-classdist.R @@ -113,9 +113,9 @@ test_that("case weights", { expect_equal(means_wts, means_wts_exp) expect_equal(means_no, means_exp) - expect_error( - recipes:::get_center(mtcars, wts = wts, mfun = median), - "The centering function requested cannot be used with case weights" + expect_snapshot( + error = TRUE, + recipes:::get_center(mtcars, wts = wts, mfun = median) ) # ------------------------------------------------------------------------------ @@ -128,13 +128,13 @@ test_that("case weights", { expect_equal(cov_no$scale, cov_exp) expect_equal(cov_wts$center, means_wts_exp) expect_equal(cov_no$center, means_exp) - expect_error( - recipes:::get_both(mtcars, wts = wts, mfun = median), - "The centering function requested cannot be used with case weights" + expect_snapshot( + error = TRUE, + recipes:::get_both(mtcars, wts = wts, mfun = median) ) - expect_error( - recipes:::get_both(mtcars, wts = wts, cfun = mad), - "The variance function requested cannot be used with case weights" + expect_snapshot( + error = TRUE, + recipes:::get_both(mtcars, wts = wts, cfun = mad) ) # ------------------------------------------------------------------------------ diff --git a/tests/testthat/test-colcheck.R b/tests/testthat/test-colcheck.R index 299e73fb5..f5d93ac02 100644 --- a/tests/testthat/test-colcheck.R +++ b/tests/testthat/test-colcheck.R @@ -95,7 +95,10 @@ test_that("non-standard roles during bake/predict", { # This should require 'date' to predict. # The error comes from hardhat, so we don't snapshot it because we don't own it. - expect_error(predict(role_fit, Chicago %>% select(-date))) + expect_snapshot( + error = TRUE, + predict(role_fit, Chicago %>% select(-date)) + ) # ---------------------------------------------------------------------------- # non-standard role used in a step and case weights @@ -115,7 +118,10 @@ test_that("non-standard roles during bake/predict", { # This should require 'date' but not 'wts' to predict expect_no_error(predict(role_wts_fit, head(Chicago))) expect_no_error(predict(role_wts_fit, head(Chicago) %>% select(-wts))) - expect_error(predict(role_wts_fit, head(Chicago) %>% select(-date))) + expect_snapshot( + error = TRUE, + predict(role_wts_fit, head(Chicago) %>% select(-date)) + ) # ---------------------------------------------------------------------------- # Removing variable after use @@ -131,7 +137,10 @@ test_that("non-standard roles during bake/predict", { rm_fit <- fit(rm_wflow, data = Chicago) # This should require 'date' to predict - expect_error(predict(rm_fit, Chicago %>% select(-date))) + expect_snapshot( + error = TRUE, + predict(rm_fit, Chicago %>% select(-date)) + ) # ---------------------------------------------------------------------------- # Removing variable after use, with case weights @@ -149,7 +158,10 @@ test_that("non-standard roles during bake/predict", { # This should require 'date' but not 'wts' to predict expect_no_error(predict(rm_fit, Chicago %>% select(-wts))) - expect_error(predict(rm_fit, Chicago %>% select(-date))) + expect_snapshot( + error = TRUE, + predict(rm_fit, Chicago %>% select(-date)) + ) }) # Infrastructure --------------------------------------------------------------- diff --git a/tests/testthat/test-mutate_at.R b/tests/testthat/test-mutate_at.R index 82516f172..86f34ad21 100644 --- a/tests/testthat/test-mutate_at.R +++ b/tests/testthat/test-mutate_at.R @@ -71,7 +71,8 @@ test_that("mulitple functions", { test_that("no input", { # Wait for call pass through - expect_error( + expect_snapshot( + error = TRUE, iris_rec %>% step_mutate_at() %>% prep(training = iris) %>% diff --git a/tests/testthat/test-rename_at.R b/tests/testthat/test-rename_at.R index fb521ba11..7520ec68c 100644 --- a/tests/testthat/test-rename_at.R +++ b/tests/testthat/test-rename_at.R @@ -40,7 +40,8 @@ test_that("mulitple functions", { test_that("no input", { # Wait for call pass through - expect_error( + expect_snapshot( + error = TRUE, iris_rec %>% step_rename_at() %>% prep(training = iris) %>% diff --git a/tests/testthat/test-update-role-requirements.R b/tests/testthat/test-update-role-requirements.R index 68f05b473..878c71c4b 100644 --- a/tests/testthat/test-update-role-requirements.R +++ b/tests/testthat/test-update-role-requirements.R @@ -80,7 +80,10 @@ test_that("will still error if a step actually used a role that set `bake = FALS df$x <- NULL # Error is specific to details of `step_scale()` - expect_error(bake(rec, df)) + expect_snapshot( + error = TRUE, + bake(rec, df) + ) }) test_that("can `bake()` without roles that set `bake = FALSE`", { diff --git a/tests/testthat/test-window.R b/tests/testthat/test-window.R index 3e8485467..c9f0788e6 100644 --- a/tests/testthat/test-window.R +++ b/tests/testthat/test-window.R @@ -20,7 +20,8 @@ test_that("error checks", { rec %>% step_window(y1, size = NA) ) # Wait for call pass through - expect_error( + expect_snapshot( + error = TRUE, rec %>% step_window(y1, size = NULL) ) expect_snapshot(error = TRUE,