Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use expect_snapshot() more #1375

Merged
merged 12 commits into from
Sep 24, 2024
Merged

Use expect_snapshot() more #1375

merged 12 commits into from
Sep 24, 2024

Conversation

EmilHvitfeldt
Copy link
Member

to close #1363

This PR:

  • switched from expect_warning() and expect_message() to expect_snapshot()
  • removed classed expect_error() and switched to expect_snapshot(error = TRUE)
  • Switched from expect_error(..., NA) to expect_no_error(). Can't do expect_no_condition() due to dplyr_regroup signal
  • Switched rest of expect_error() to expect_snapshot(error = TRUE)

No bad snapshots were found in the switch 🙌

R/misc.R Show resolved Hide resolved
Copy link
Member

@hfrick hfrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one overall but I have questions/opinions on classed errors 🤓

R/misc.R Outdated Show resolved Hide resolved
@@ -859,9 +859,8 @@ check_new_data <- function(req, object, new_data) {
step_cls <- class(object)[1]
step_id <- object$id
cli::cli_abort(
"The following required {cli::qty(col_diff)} column{?s} {?is/are} \
missing from `new_data` in step '{step_id}': {col_diff}.",
class = "new_data_missing_column",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for classing this error previously?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was from before expect_snapshot() so they were tested with expect_error(). Classed errors were used to make sure the correct error bubbled up. Instead of relying on regex matching.

However it is the only place we use it and only for testing purposes, and for that reason I think we are better off using the unclassed errors with expect_snapshot()

also, since we were matching on class, we never checked that the {cli} syntax was correct as we didn't see the error

i'm not opposed to classed errors. And they might even be useful if cases where {tune} could match on them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with removing the error class if we are not using it. I see tests in the recipes extension packages that test for that error, but you probably know without checking if they test that a recipe step from that extension package is the one throwing the classed error. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran a revdepcheck. it is only an issue for package i maintain so i think it is fine :) thanks for pointing it out

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good principle to rely on, i.e. I would suggest not doing the change below and similar. If you want a more thorough test than "just make sure there is a error" you could see if it's a classed error and check for that error class here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unresolving this because it seems like you might have hit "resolved" by accident?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! have reverted it now

tests/testthat/test-rename_at.R Outdated Show resolved Hide resolved
tests/testthat/test-window.R Outdated Show resolved Hide resolved
R/mutate_at.R Show resolved Hide resolved
@EmilHvitfeldt EmilHvitfeldt merged commit 3b12331 into main Sep 24, 2024
11 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the more-expect_snapshot branch September 24, 2024 21:20
Copy link

github-actions bot commented Oct 9, 2024

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move away from expect_error()
2 participants