Skip to content

Commit

Permalink
Merge pull request #67 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 committed Apr 10, 2024
2 parents d33df62 + 9d800e4 commit 41fdc0b
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/testthat/_snaps/flexible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# check_args() works

Code
spec <- discrim_flexible(prod_degree = 0) %>% set_engine("earth") %>% set_mode(
"classification")
fit(spec, factor ~ ., glass_tr)
Condition
Error in `fit()`:
! `prod_degree` must be a whole number larger than or equal to 1 or `NULL`, not the number 0.

---

Code
spec <- discrim_flexible(num_terms = 0) %>% set_engine("earth") %>% set_mode(
"classification")
fit(spec, factor ~ ., glass_tr)
Condition
Error in `fit()`:
! `num_terms` must be a whole number larger than or equal to 1 or `NULL`, not the number 0.

---

Code
spec <- discrim_flexible(prune_method = 2) %>% set_engine("earth") %>% set_mode(
"classification")
fit(spec, factor ~ ., glass_tr)
Condition
Error in `fit()`:
! `prune_method` must be a single string or `NULL`, not the number 2.

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/linear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# check_args() works

Code
spec <- discrim_linear(penalty = -1) %>% set_engine("MASS") %>% set_mode(
"classification")
fit(spec, factor ~ ., glass_tr)
Condition
Error in `fit()`:
! `penalty` must be a number larger than or equal to 0 or `NULL`, not the number -1.

20 changes: 20 additions & 0 deletions tests/testthat/_snaps/regularized.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# check_args() works

Code
spec <- discrim_regularized(frac_common_cov = -1) %>% set_engine("klaR") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
Condition
Error in `fit()`:
! `frac_common_cov` must be a number between 0 and 1 or `NULL`, not the number -1.

---

Code
spec <- discrim_regularized(frac_identity = -1) %>% set_engine("klaR") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
Condition
Error in `fit()`:
! `frac_identity` must be a number between 0 and 1 or `NULL`, not the number -1.

34 changes: 34 additions & 0 deletions tests/testthat/test-flexible.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,37 @@ test_that("updating", {
fda_spec_3 <- update(fda_spec, num_terms = 6)
expect_equal(fda_spec_2, fda_spec_3)
})

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

expect_snapshot(
error = TRUE,
{
spec <- discrim_flexible(prod_degree = 0) %>%
set_engine("earth") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
}
)
expect_snapshot(
error = TRUE,
{
spec <- discrim_flexible(num_terms = 0) %>%
set_engine("earth") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
}
)

expect_snapshot(
error = TRUE,
{
spec <- discrim_flexible(prune_method = 2) %>%
set_engine("earth") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
}
)
})
13 changes: 13 additions & 0 deletions tests/testthat/test-linear.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_that('check_args() works', {
skip_if_not_installed("parsnip", "1.2.1.9001")

expect_snapshot(
error = TRUE,
{
spec <- discrim_linear(penalty = -1) %>%
set_engine("MASS") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
}
)
})
6 changes: 6 additions & 0 deletions tests/testthat/test-naive-Bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,9 @@ test_that("updating", {
ignore_formula_env = TRUE
)
})

test_that("check_args() works", {
skip_if_not_installed("parsnip", "1.2.1.9001")
# Here for completeness, no checking is done
expect_true(TRUE)
})
4 changes: 4 additions & 0 deletions tests/testthat/test-quad.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("check_args() works", {
# Here for completeness, no checking is done
expect_true(TRUE)
})
23 changes: 23 additions & 0 deletions tests/testthat/test-regularized.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that('check_args() works', {
skip_if_not_installed("parsnip", "1.2.1.9001")

expect_snapshot(
error = TRUE,
{
spec <- discrim_regularized(frac_common_cov = -1) %>%
set_engine("klaR") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
}
)

expect_snapshot(
error = TRUE,
{
spec <- discrim_regularized(frac_identity = -1) %>%
set_engine("klaR") %>%
set_mode("classification")
fit(spec, factor ~ ., glass_tr)
}
)
})

0 comments on commit 41fdc0b

Please sign in to comment.