Skip to content

Commit

Permalink
transition to snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Oct 23, 2024
1 parent 1300c32 commit cd36203
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ check_empty_ellipses <- function(...) {
unlist()

cli_warn(
"The `...` are not used in this function but {?an/}{qty(length(dots))}
argument{?s} {.arg {names(dots)}} {?was/were} passed."
"The `...` are not used in this function but {?an/}
argument{?s} {.arg {names(dots)}} {?was/were} passed."
)
}
invisible(NULL)
Expand Down
22 changes: 17 additions & 5 deletions tests/testthat/_snaps/add_candidates.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,27 @@

# stacks can add candidates via workflow sets

! Some elements of the supplied workflow set failed to evaluate with resamples.
i The workflow with ID `reg_lr` will be excluded from the data stack.
Code
res <- stacks() %>% add_candidates(wf_set_trained_error)
Condition
Warning:
! Some elements of the supplied workflow set failed to evaluate with resamples.
i The workflow with ID `reg_lr` will be excluded from the data stack.

---

! Some elements of the supplied workflow set failed to evaluate with resamples.
i The workflows with ID `reg_lr` and `reg2_svm` will be excluded from the data stack.
Code
res <- stacks() %>% add_candidates(wf_set_trained_error)
Condition
Warning:
! Some elements of the supplied workflow set failed to evaluate with resamples.
i The workflows with ID `reg_lr` and `reg2_svm` will be excluded from the data stack.

---

The supplied workflow set must be fitted to resamples with `workflow_map()` (`?workflowsets::workflow_map()`) before being added to a data stack.
Code
stacks() %>% add_candidates(wf_set_trained_error)
Condition
Error in `add_candidates()`:
! The supplied workflow set must be fitted to resamples with `workflow_map()` (`?workflowsets::workflow_map()`) before being added to a data stack.

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
Error:
! Element "howdy" needs to inherit from `numeric`, but its class is `character`.

---

Code
res <- check_empty_ellipses(yall)
Condition
Warning:
The `...` are not used in this function but an argument `yall` was passed.

---

Code
res <- check_empty_ellipses(hey = yall, what = "is", going)
Condition
Warning:
The `...` are not used in this function but arguments `hey`, `what`, and `going` were passed.

17 changes: 10 additions & 7 deletions tests/testthat/test_add_candidates.R
Original file line number Diff line number Diff line change
Expand Up @@ -354,26 +354,29 @@ test_that("stacks can add candidates via workflow sets", {
class = "wf_set_partial_fit"
)

expect_snapshot_warning(
stacks() %>% add_candidates(wf_set_trained_error),
class = "wf_set_partial_fit"
expect_snapshot(
res <- stacks() %>% add_candidates(wf_set_trained_error)
)

wf_set_trained_error$result[[2]] <- "boop"

expect_snapshot_warning(
stacks() %>% add_candidates(wf_set_trained_error),
class = "wf_set_partial_fit"
expect_snapshot(
res <- stacks() %>% add_candidates(wf_set_trained_error)
)

# now, will all resampled fits failing, should error
wf_set_trained_error$result[[3]] <- "boop"

expect_snapshot_error(
expect_error(
stacks() %>% add_candidates(wf_set_trained_error),
class = "wf_set_unfitted"
)

expect_snapshot(
error = TRUE,
stacks() %>% add_candidates(wf_set_trained_error)
)

# check that add_candidate adds the candidates it said it would
wf_stack_2 <-
stacks() %>%
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_fit_members.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ test_that("fit_members checks for required packages", {
library(mockr)

# check pluralization of error
expect_snapshot_error(error_needs_install(letters[1], rep(FALSE, 1)))
expect_snapshot_error(error_needs_install(letters[1:2], rep(FALSE, 2)))
expect_snapshot_error(error_needs_install(letters[1:3], rep(FALSE, 3)))
expect_snapshot(error = TRUE, error_needs_install(letters[1], rep(FALSE, 1)))
expect_snapshot(error = TRUE, error_needs_install(letters[1:2], rep(FALSE, 2)))
expect_snapshot(error = TRUE, error_needs_install(letters[1:3], rep(FALSE, 3)))

# loads dependency when it's installed but not loaded
unloadNamespace("kernlab")
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ test_that("misc. utilities work", {

yall <- "y'all"

expect_warning(
check_empty_ellipses(yall),
"were passed: 'yall'"
expect_snapshot(
res <- check_empty_ellipses(yall)
)

going <- "on"

expect_warning(
check_empty_ellipses(hey = yall, what = "is", going),
"were passed: 'hey', 'what', 'going'"
expect_snapshot(
res <- check_empty_ellipses(hey = yall, what = "is", going)
)
})

0 comments on commit cd36203

Please sign in to comment.