Skip to content

Commit

Permalink
Merge pull request #157 from tidymodels/expect_snapshot-linting
Browse files Browse the repository at this point in the history
lint expect_snapshot()
  • Loading branch information
EmilHvitfeldt authored Nov 9, 2024
2 parents 575663c + a913d6b commit 95e578b
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 61 deletions.
15 changes: 10 additions & 5 deletions tests/testthat/test-adasyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test_that("errors if there isn't enough data", {
credit_data0$Status[1] <- "dummy"
credit_data0$Status <- as.factor(credit_data0$Status)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Status ~ Age, data = credit_data0) %>%
step_adasyn(Status) %>%
prep()
Expand All @@ -32,13 +33,15 @@ test_that("basic usage", {
test_that("bad data", {
rec <- recipe(~., data = circle_example)
# numeric check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_adasyn(x) %>%
prep()
)
# Multiple variable check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_adasyn(class, id) %>%
prep()
Expand All @@ -52,7 +55,8 @@ test_that("errors if character are present", {
stringsAsFactors = FALSE
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(~., data = df_char) %>%
step_adasyn(x) %>%
prep()
Expand All @@ -64,7 +68,8 @@ test_that("NA in response", {

data("credit_data", package = "modeldata")

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Job ~ Age, data = credit_data) %>%
step_adasyn(Job) %>%
prep()
Expand Down
21 changes: 14 additions & 7 deletions tests/testthat/test-adasyn_impl.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,41 @@ circle_example_num <- circle_example[, c("x", "y", "class")]
test_that("adasyn() interfaces correctly", {
expect_no_error(adasyn(circle_example_num, var = "class"))

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example_num, var = "Class")
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example_num, var = c("class", "x"))
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example_num, var = "x")
)

circle_example0 <- circle_example_num
circle_example0[1, 1] <- NA

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example0, var = "class")
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example_num, var = "class", k = 0)
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example_num, var = "class", k = -1)
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
adasyn(circle_example_num, var = "class", k = c(5, 10))
)
})
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-bsmote.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ test_that("basic usage", {
test_that("bad data", {
rec <- recipe(~., data = circle_example)
# numeric check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_bsmote(x) %>%
prep()
)
# Multiple variable check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_bsmote(class, id) %>%
prep()
Expand All @@ -64,7 +66,8 @@ test_that("errors if character are present", {
stringsAsFactors = FALSE
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(~., data = df_char) %>%
step_bsmote(x) %>%
prep()
Expand All @@ -76,7 +79,8 @@ test_that("NA in response", {

data("credit_data", package = "modeldata")

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Job ~ Age, data = credit_data) %>%
step_bsmote(Job) %>%
prep()
Expand Down
21 changes: 14 additions & 7 deletions tests/testthat/test-bsmote_impl.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,41 @@ circle_example_num <- circle_example[, c("x", "y", "class")]
test_that("bsmote() interfaces correctly", {
expect_no_error(bsmote(circle_example_num, var = "class"))

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example_num, var = "Class")
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example_num, var = c("class", "x"))
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example_num, var = "x")
)

circle_example0 <- circle_example_num
circle_example0[1, 1] <- NA

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example0, var = "class")
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example_num, var = "class", k = 0)
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example_num, var = "class", k = -1)
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
bsmote(circle_example_num, var = "class", k = c(5, 10))
)
})
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-downsample.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_that("ratio deprecation", {
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
new_rec <- recipe(~., data = circle_example) %>%
step_downsample(class, ratio = 2)
)
Expand All @@ -22,13 +23,15 @@ test_that("basic usage", {
test_that("bad data", {
rec <- recipe(~., data = circle_example)
# numeric check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_downsample(x) %>%
prep()
)
# Multiple variable check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_downsample(class, id) %>%
prep()
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-nearmiss.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ test_that("basic usage", {
test_that("bad data", {
rec <- recipe(~., data = circle_example)
# numeric check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_nearmiss(x) %>%
prep()
)
# Multiple variable check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_nearmiss(class, id) %>%
prep()
Expand All @@ -35,7 +37,8 @@ test_that("errors if character are present", {
stringsAsFactors = FALSE
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(~., data = df_char) %>%
step_nearmiss(x) %>%
prep()
Expand All @@ -47,7 +50,8 @@ test_that("NA in response", {

data("credit_data", package = "modeldata")

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Job ~ Age, data = credit_data) %>%
step_nearmiss(Job) %>%
prep()
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-rose.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ test_that("basic usage", {
test_that("bad data", {
rec <- recipe(~., data = circle_example)
# numeric check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_rose(x) %>%
prep()
)
# Multiple variable check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_rose(class, id) %>%
prep()
Expand All @@ -74,7 +76,8 @@ test_that("NA in response", {
credit_data0 <- credit_data
credit_data0[1, 1] <- NA

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Status ~ Age, data = credit_data0) %>%
step_rose(Status) %>%
prep()
Expand Down Expand Up @@ -124,7 +127,8 @@ test_that("only except 2 classes", {
stringsAsFactors = FALSE
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(~., data = df_char) %>%
step_rose(x) %>%
prep()
Expand Down
15 changes: 10 additions & 5 deletions tests/testthat/test-smote.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test_that("errors if there isn't enough data", {
credit_data0$Status[1] <- "dummy"
credit_data0$Status <- as.factor(credit_data0$Status)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Status ~ Age, data = credit_data0) %>%
step_smote(Status) %>%
prep()
Expand All @@ -32,13 +33,15 @@ test_that("basic usage", {
test_that("bad data", {
rec <- recipe(~., data = circle_example)
# numeric check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_smote(x) %>%
prep()
)
# Multiple variable check
expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
rec %>%
step_smote(class, id) %>%
prep()
Expand All @@ -52,7 +55,8 @@ test_that("errors if character are present", {
stringsAsFactors = FALSE
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(~., data = df_char) %>%
step_smote(x) %>%
prep()
Expand All @@ -64,7 +68,8 @@ test_that("NA in response", {

data("credit_data", package = "modeldata")

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
recipe(Job ~ Age, data = credit_data) %>%
step_smote(Job) %>%
prep()
Expand Down
21 changes: 14 additions & 7 deletions tests/testthat/test-smote_impl.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,41 @@ test_that("smote() interfaces correctly", {

expect_no_error(smote(circle_example_num, var = "class"))

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example_num, var = "Class")
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example_num, var = c("class", "x"))
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example_num, var = "x")
)

circle_example0 <- circle_example_num
circle_example0[1, 1] <- NA

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example0, var = "class")
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example_num, var = "class", k = 0)
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example_num, var = "class", k = -1)
)

expect_snapshot(error = TRUE,
expect_snapshot(
error = TRUE,
smote(circle_example_num, var = "class", k = c(5, 10))
)
})
Expand Down
Loading

0 comments on commit 95e578b

Please sign in to comment.