Skip to content

Commit

Permalink
update tests to no use everything()
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed May 24, 2024
1 parent 0ef891a commit 3eac33a
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
predictor: 10
-- Operations
* Checking the class(es) for: everything()
* Checking the class(es) for: all_predictors()

---

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/colcheck.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# check_col works in the bake stage

Code
rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars[-1])
rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars[-1])
Condition
Error in `bake()`:
x The following required columns are missing from `new_data`: `mpg`.
Expand Down Expand Up @@ -65,7 +65,7 @@
predictor: 10
-- Operations
* Check if the following columns are present:: everything()
* Check if the following columns are present:: all_predictors()

---

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/cut.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
---

Code
recipe(x) %>% step_cut(everything(), breaks = 2) %>% prep()
recipe(~., x) %>% step_cut(all_predictors(), breaks = 2) %>% prep()
Condition
Error in `step_cut()`:
Caused by error in `prep()`:
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/missing.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
---

Code
tst(everything())
tst(all_predictors())
Condition
Error in `check_missing()`:
Caused by error in `bake()`:
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/_snaps/profile.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# bad values

Code
sacr_rec %>% step_profile(everything(), profile = vars(sqft)) %>% prep(data = Sacramento)
sacr_rec %>% step_profile(all_predictors(), profile = vars(sqft)) %>% prep(
data = Sacramento)
Condition
Error in `step_profile()`:
Caused by error in `prep()`:
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/shuffle.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# bake a single row

Code
dat4 <- bake(rec4, dat[1, ], everything())
dat4 <- bake(rec4, dat[1, ])
Condition
Warning:
`new_data` contains a single row; unable to shuffle.
Expand Down Expand Up @@ -55,7 +55,7 @@
predictor: 4
-- Operations
* Shuffled: everything()
* Shuffled: all_predictors()

---

Expand All @@ -74,5 +74,5 @@
Training data contained 50 data points and no incomplete rows.
-- Operations
* Shuffled: x1, x2, x3, x4, y | Trained
* Shuffled: x1, x2, x3, x4 | Trained

10 changes: 5 additions & 5 deletions tests/testthat/test-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test_that("bake_check_class helper function gives expected output", {
})

test_that("check_class works when class is learned", {
rec1 <- recipe(x) %>%
check_class(everything()) %>%
rec1 <- recipe(~ ., x) %>%
check_class(all_predictors()) %>%
prep()

expect_error(bake(rec1, x), NA)
Expand Down Expand Up @@ -76,7 +76,7 @@ test_that("check_class works when class is provided", {
# recipes has internal coercion to character >> factor
test_that("characters are handled correctly", {
rec5_NULL <- recipe(Sacramento[1:10, ], sqft ~ .) %>%
check_class(everything()) %>%
check_class(all_predictors()) %>%
prep(Sacramento[1:10, ], strings_as_factors = FALSE)

expect_error(bake(rec5_NULL, Sacramento[11:20, ]), NA)
Expand All @@ -96,7 +96,7 @@ test_that("characters are handled correctly", {
)

rec6_NULL <- recipe(sacr_fac[1:10, ], sqft ~ .) %>%
check_class(everything()) %>%
check_class(all_predictors()) %>%
prep(sacr_fac[1:10, ], strings_as_factors = TRUE)

expect_snapshot(error = TRUE,
Expand Down Expand Up @@ -165,7 +165,7 @@ test_that("empty selection tidy method works", {

test_that("printing", {
rec7 <- recipe(mpg ~ ., mtcars) %>%
check_class(everything())
check_class(all_predictors())

expect_snapshot(print(rec7))
expect_snapshot(prep(rec7))
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-colcheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ rp1 <- recipe(mtcars, cyl ~ .)
rp2 <- recipe(mtcars, cyl ~ mpg + drat)

test_that("check_col works in the prep stage", {
expect_error(rp1 %>% check_cols(everything()) %>% prep(), NA)
expect_error(rp2 %>% check_cols(everything()) %>% prep(), NA)
expect_error(rp1 %>% check_cols(all_predictors()) %>% prep(), NA)
expect_error(rp2 %>% check_cols(all_predictors()) %>% prep(), NA)
expect_error(rp2 %>% check_cols(cyl, mpg, drat) %>% prep(), NA)
expect_error(rp2 %>% check_cols(cyl, mpg) %>% prep(), NA)
})


test_that("check_col works in the bake stage", {

expect_error(rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars),
expect_error(rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars),
NA)
expect_equal(rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars),
expect_equal(rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars),
tibble(mtcars[ ,c(1, 3:11, 2)]))
expect_error(rp2 %>% check_cols(cyl, mpg, drat) %>% prep %>% bake(mtcars), NA)
expect_equal(rp2 %>% check_cols(cyl, mpg, drat) %>% prep %>% bake(mtcars),
tibble(mtcars[ ,c(1, 5, 2)]))

expect_error(
rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars),
rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars),
NA
)
expect_equal(
rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars),
rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars),
tibble(mtcars[, c(1, 3:11, 2)])
)
expect_error(rp2 %>% check_cols(cyl, mpg, drat) %>% prep() %>% bake(mtcars), NA)
Expand All @@ -36,7 +36,7 @@ test_that("check_col works in the bake stage", {
tibble(mtcars[, c(1, 5, 2)])
)
expect_snapshot(error = TRUE,
rp1 %>% check_cols(everything()) %>% prep() %>% bake(mtcars[-1])
rp1 %>% check_cols(all_predictors()) %>% prep() %>% bake(mtcars[-1])
)
expect_snapshot(error = TRUE,
rp2 %>% check_cols(cyl, mpg, drat) %>% prep() %>%
Expand Down Expand Up @@ -195,7 +195,7 @@ test_that("empty selection tidy method works", {

test_that("printing", {
rec <- recipe(mpg ~ ., mtcars) %>%
check_cols(everything())
check_cols(all_predictors())

expect_snapshot(print(rec))
expect_snapshot(prep(rec))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cut.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("step_cut throws error on non-numerics", {
recipe(x) %>% step_cut(cat_var, breaks = 2) %>% prep()
)
expect_snapshot(error = TRUE,
recipe(x) %>% step_cut(everything(), breaks = 2) %>% prep()
recipe(~., x) %>% step_cut(all_predictors(), breaks = 2) %>% prep()
)
})

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-indicate_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("step_indicate_na populates binaries correctly", {

test_that("step_indicate_na on all columns", {
baked <- recipe(Ozone ~ ., data = airquality) %>%
step_indicate_na(everything()) %>%
step_indicate_na(all_predictors()) %>%
prep(airquality, verbose = FALSE, retain = TRUE) %>%
bake(new_data = NULL)

Expand All @@ -52,7 +52,7 @@ test_that("step_indicate_na on all columns", {
c(
"Solar.R", "Wind", "Temp", "Month", "Day", "Ozone",
"na_ind_Solar.R", "na_ind_Wind", "na_ind_Temp",
"na_ind_Month", "na_ind_Day", "na_ind_Ozone"
"na_ind_Month", "na_ind_Day"
)
)
})
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-missing.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set_with_na <- tibble(

tst <- function(...) {
cols <- quos(...)
recipe(set_with_na) %>%
recipe(~ ., set_with_na) %>%
check_missing(!!!cols) %>%
prep() %>%
bake(set_with_na)
Expand All @@ -33,7 +33,7 @@ test_that("check_missing throws error on all types", {

test_that("check_missing works on multiple columns simultaneously", {
expect_snapshot(error = TRUE, tst(a, e))
expect_snapshot(error = TRUE, tst(everything()))
expect_snapshot(error = TRUE, tst(all_predictors()))
})

test_that("check_missing on a new set", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-naomit.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ library(testthat)
library(recipes)

test_that("step_naomit on all columns", {
baked <- recipe(Ozone ~ ., data = airquality) %>%
step_naomit(everything()) %>%
baked <- recipe(~ ., data = airquality) %>%
step_naomit(all_predictors()) %>%
prep(airquality, verbose = FALSE) %>%
bake(new_data = NULL)

na_res <- tibble(na.omit(airquality))
attributes(na_res)$na.action <- NULL

expect_equal(baked, na_res[, c(2:6, 1)])
expect_equal(baked, na_res)
})

test_that("step_naomit on subset of columns", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ordinalscore.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test_that("nonlinear scores", {

test_that("bad spec", {
rec3 <- recipe(~., data = ex_dat) %>%
step_ordinalscore(everything())
step_ordinalscore(all_predictors())
expect_snapshot(error = TRUE,
prep(rec3, training = ex_dat, verbose = FALSE)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test_that("character profile", {
test_that("bad values", {
expect_snapshot(error = TRUE,
sacr_rec %>%
step_profile(everything(), profile = vars(sqft)) %>%
step_profile(all_predictors(), profile = vars(sqft)) %>%
prep(data = Sacramento)
)
expect_snapshot(error = TRUE,
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-shuffle.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test_that("nominal data", {

test_that("all data", {
rec3 <- recipe(y ~ ., data = dat) %>%
step_shuffle(everything())
step_shuffle(all_predictors())

rec3 <- prep(rec3, training = dat, verbose = FALSE)
set.seed(2516)
Expand All @@ -62,10 +62,10 @@ test_that("all data", {

test_that("bake a single row", {
rec4 <- recipe(y ~ ., data = dat) %>%
step_shuffle(everything())
step_shuffle(all_predictors())

rec4 <- prep(rec4, training = dat, verbose = FALSE)
expect_snapshot(dat4 <- bake(rec4, dat[1, ], everything()))
expect_snapshot(dat4 <- bake(rec4, dat[1, ]))
expect_equal(dat4, tibble(dat[1, ]))
})

Expand Down Expand Up @@ -122,7 +122,7 @@ test_that("empty selection tidy method works", {

test_that("printing", {
rec <- recipe(y ~ ., data = dat) %>%
step_shuffle(everything())
step_shuffle(all_predictors())

expect_snapshot(print(rec))
expect_snapshot(prep(rec))
Expand Down

0 comments on commit 3eac33a

Please sign in to comment.