Skip to content

Commit

Permalink
Merge pull request #83 from tidymodels/cli-check_args
Browse files Browse the repository at this point in the history
test {cli} changes to `check_args()`
  • Loading branch information
EmilHvitfeldt authored Apr 11, 2024
2 parents 1b32f41 + 5833424 commit 218a679
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/testthat/_snaps/poisson_reg.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@
[1] "poisson"

# check_args() works

Code
spec <- poisson_reg(mixture = -1) %>% set_engine("glm") %>% set_mode(
"regression")
fit(spec, gear ~ ., data = mtcars)
Condition
Error in `fit()`:
! `mixture` must be a number between 0 and 1 or `NULL`, not the number -1.

---

Code
spec <- poisson_reg(penalty = -1) %>% set_engine("glm") %>% set_mode(
"regression")
fit(spec, gear ~ ., data = mtcars)
Condition
Error in `fit()`:
! `penalty` must be a number larger than or equal to 0 or `NULL`, not the number -1.

25 changes: 25 additions & 0 deletions tests/testthat/test-poisson_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ test_that("arguments", {
expect_snapshot(translate_args(mixture %>% set_engine("glmnet")))
expect_snapshot(translate_args(mixture_tune %>% set_engine("glmnet")))
})


test_that('check_args() works', {
skip_if_not_installed("parsnip", "1.2.1.9001")

expect_snapshot(
error = TRUE,
{
spec <- poisson_reg(mixture = -1) %>%
set_engine("glm") %>%
set_mode("regression")
fit(spec, gear ~ ., data = mtcars)
}
)

expect_snapshot(
error = TRUE,
{
spec <- poisson_reg(penalty = -1) %>%
set_engine("glm") %>%
set_mode("regression")
fit(spec, gear ~ ., data = mtcars)
}
)
})

0 comments on commit 218a679

Please sign in to comment.