Skip to content

update to testthat 3e + consolidate translate() tests #699

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

Merged
merged 31 commits into from
Apr 20, 2022
Merged

update to testthat 3e + consolidate translate() tests #699

merged 31 commits into from
Apr 20, 2022

Conversation

simonpcouch
Copy link
Contributor

A few things worth mentioning:

  • I haven’t been able to track down a slick/concise way to share the hpc <- hpc_data[1:150, c(2:5, 8)] object among all tests. A line in testthat/setup.R seems like it would do the trick, except it makes interactively debugging tests a bit more clunky.
  • I didn’t find as many tests that I perceived as redundant as I had anticipated, so this PR doesn’t cut down on overall testing much at all. The new helpers cut down on total lines a good bit, though, and should read a good bit more expressively than the previous expect_equal(…, list(…) idiom.
  • The primary and engine arguments now live in the same test_that call, as 1) they share the same inputs and 2) with the new expect_snapshot(translate_args()) idiom, the difference between the two is more visually apparent.
  • update() and bad input tests are mostly untouched. Both of those are relevant here, I think, but this PR is quite large already.
  • Is load(test_path("mars_model.RData")) in test_mars more discouraged in 3e? Idioms like this seem to live elsewhere in the tidymodels, so I just ran with it.

if `context()` wasn't redundant with file name, convert to comment
mostly just switching to `expect_equal` and updating attributes as needed. it also seems that `expect_warning()` (and other prompt friends) return the prompt rather than output--changed one of these that was related to `expect_equivalent, but will need to do a more thorough sweep when switching to `expect_snapshot`
`quo` does the trick in most of these situations, and any exceptions ought to be transitioned to `expect_snapshot`. still a good few errors related to function environment.
I think that it helps to standardize indentation + simplify figuring out what a snapshot is capturing, and it cuts down on lines quite a bit, but I could also see the argument that it obscures a bit too much. Implemented primary argument checks for three models, dropping the rest.
it looks like just about every model type has associated changes to translation of primary arguments, so pulling back from the "selected methods" approach to testing each.
also transitioned on output of `translate`
given how large this PR will be already, and the brittleness of `expect_snapshot` as compared to `expect_warning` (and `expect_error`), reverting the change `expect_warning` <- `expect_snapshot`.
following Hannah's lead--we just want to make sure we get a model object back, and `expect_snapshot` will pick up differences in fit time etc
a good bit of `expect_warning` output changes affecting assignments. some namespacing, some environment variable tomfoolery as well.
ended up running into issues with `expect_snapshot` call environments—not worth the loss in interpretability of errors to wrap `expect_snapshot` itself.

still trying to figure out the best way to ignore function environments here.
wipe the environment from quosures in the translation helper so that `expect_snapshot` is reproducible!
@simonpcouch simonpcouch requested a review from topepo April 8, 2022 12:56
for whatever reason, `oldrel-2` can't find `lung` inside of the tests here. thinking this might be some kind of scoping issue—from what i can tell on the `survival` repo, this shouldn't be due to changes in that package, though it's hard to trace source history from there.
for `oldrel-2` and older, pak uses survival 3.1-8 via R 3.6.3. in these versions of survival, loading the lung data with `data(lung` seems to have worked (though was not preferred? ¯\_(ツ)_/¯)
@simonpcouch

This comment was marked as resolved.

Copy link
Member

@topepo topepo left a comment

Choose a reason for hiding this comment

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

I think that we should use snapshots more for all of the updating tests.

I also asked about in slack about a better patter than expect_error({code}, regexp = NA). We'll see what happens there.

exceptions:
* when assigning (i.e. no `extract_fit_*<-()`)
* when subsetted into `$method`
* when testing `NULL`
@simonpcouch simonpcouch requested a review from topepo April 15, 2022 14:24
@topepo topepo merged commit 5716803 into main Apr 20, 2022
@topepo topepo deleted the 3e branch April 20, 2022 14:17
@github-actions
Copy link

github-actions bot commented May 5, 2022

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 May 5, 2022
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.

2 participants