Skip to content

Commit

Permalink
transition expect_error() calls
Browse files Browse the repository at this point in the history
* ...to snapshot when testing the error message
* ...to classed error when testing an error from another package or an error thrown from a widely-used helper
* ...to `expect_no_error()` (or no test) when `regex = NA`
* analogous story for `expect_warning()` and `expect_message()`.
  • Loading branch information
simonpcouch committed Oct 21, 2024
1 parent f4b0d26 commit 1548526
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions tests/testthat/test-broom.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ test_that("augment fails if it can't preprocess `new_data`", {

wf <- fit(wf, df)

# vctrs type error
expect_error(augment(wf, new_data))
expect_error(augment(wf, new_data), class = "vctrs_error_cast")
})

test_that("augment works with matrix compositions (#148)", {
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-pre-action-case-weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ test_that("case weights `col` must exist in `data`", {
wf <- add_formula(wf, mpg ~ .)
wf <- add_case_weights(wf, foo)

# Tidyselect error
expect_error(fit(wf, mtcars))
expect_error(fit(wf, mtcars), class = "vctrs_error_subscript_oob")
})

test_that("case weights `col` can't select >1 columns in `data`", {
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-pre-action-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ test_that("`outcomes` are removed from set of possible `predictors` (#72)", {

workflow2 <- add_variables(workflow, mpg, mpg)

# vctrs subscript error
expect_error(.fit_pre(workflow2, mtcars))
expect_error(.fit_pre(workflow2, mtcars), class = "vctrs_error_subscript_oob")
})

test_that("selecting no `outcomes` doesn't break selection of `predictors`", {
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ test_that("blueprint will get passed on to hardhat::forge()", {
mod1 <- fit(workflow1, train)
mod2 <- fit(workflow2, train)

# Warning from hardhat, so we don't snapshot it
expect_warning(pred1 <- predict(mod1, test))
expect_warning(pred2 <- predict(mod2, test), NA)
expect_no_warning(pred2 <- predict(mod2, test))

expect_identical(
pred1[[".pred"]],
Expand Down

0 comments on commit 1548526

Please sign in to comment.