From 15485263e52ef8c6b492093680f96cab5cedf411 Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Mon, 21 Oct 2024 08:10:17 -0700 Subject: [PATCH] transition `expect_error()` calls * ...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()`. --- tests/testthat/test-broom.R | 3 +-- tests/testthat/test-pre-action-case-weights.R | 3 +-- tests/testthat/test-pre-action-variables.R | 3 +-- tests/testthat/test-predict.R | 3 ++- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-broom.R b/tests/testthat/test-broom.R index 3f29c95f..fe98bc23 100644 --- a/tests/testthat/test-broom.R +++ b/tests/testthat/test-broom.R @@ -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)", { diff --git a/tests/testthat/test-pre-action-case-weights.R b/tests/testthat/test-pre-action-case-weights.R index 04e5615c..3b88f8f5 100644 --- a/tests/testthat/test-pre-action-case-weights.R +++ b/tests/testthat/test-pre-action-case-weights.R @@ -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`", { diff --git a/tests/testthat/test-pre-action-variables.R b/tests/testthat/test-pre-action-variables.R index 18cec549..495f6a26 100644 --- a/tests/testthat/test-pre-action-variables.R +++ b/tests/testthat/test-pre-action-variables.R @@ -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`", { diff --git a/tests/testthat/test-predict.R b/tests/testthat/test-predict.R index c2160405..f548d8a5 100644 --- a/tests/testthat/test-predict.R +++ b/tests/testthat/test-predict.R @@ -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"]],