Skip to content

Commit 95e578b

Browse files
authoredNov 9, 2024··
Merge pull request #157 from tidymodels/expect_snapshot-linting
lint expect_snapshot()
2 parents 575663c + a913d6b commit 95e578b

12 files changed

+118
-61
lines changed
 

‎tests/testthat/test-adasyn.R

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ test_that("errors if there isn't enough data", {
88
credit_data0$Status[1] <- "dummy"
99
credit_data0$Status <- as.factor(credit_data0$Status)
1010

11-
expect_snapshot(error = TRUE,
11+
expect_snapshot(
12+
error = TRUE,
1213
recipe(Status ~ Age, data = credit_data0) %>%
1314
step_adasyn(Status) %>%
1415
prep()
@@ -32,13 +33,15 @@ test_that("basic usage", {
3233
test_that("bad data", {
3334
rec <- recipe(~., data = circle_example)
3435
# numeric check
35-
expect_snapshot(error = TRUE,
36+
expect_snapshot(
37+
error = TRUE,
3638
rec %>%
3739
step_adasyn(x) %>%
3840
prep()
3941
)
4042
# Multiple variable check
41-
expect_snapshot(error = TRUE,
43+
expect_snapshot(
44+
error = TRUE,
4245
rec %>%
4346
step_adasyn(class, id) %>%
4447
prep()
@@ -52,7 +55,8 @@ test_that("errors if character are present", {
5255
stringsAsFactors = FALSE
5356
)
5457

55-
expect_snapshot(error = TRUE,
58+
expect_snapshot(
59+
error = TRUE,
5660
recipe(~., data = df_char) %>%
5761
step_adasyn(x) %>%
5862
prep()
@@ -64,7 +68,8 @@ test_that("NA in response", {
6468

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

67-
expect_snapshot(error = TRUE,
71+
expect_snapshot(
72+
error = TRUE,
6873
recipe(Job ~ Age, data = credit_data) %>%
6974
step_adasyn(Job) %>%
7075
prep()

‎tests/testthat/test-adasyn_impl.R

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,41 @@ circle_example_num <- circle_example[, c("x", "y", "class")]
33
test_that("adasyn() interfaces correctly", {
44
expect_no_error(adasyn(circle_example_num, var = "class"))
55

6-
expect_snapshot(error = TRUE,
6+
expect_snapshot(
7+
error = TRUE,
78
adasyn(circle_example_num, var = "Class")
89
)
910

10-
expect_snapshot(error = TRUE,
11+
expect_snapshot(
12+
error = TRUE,
1113
adasyn(circle_example_num, var = c("class", "x"))
1214
)
1315

14-
expect_snapshot(error = TRUE,
16+
expect_snapshot(
17+
error = TRUE,
1518
adasyn(circle_example_num, var = "x")
1619
)
1720

1821
circle_example0 <- circle_example_num
1922
circle_example0[1, 1] <- NA
2023

21-
expect_snapshot(error = TRUE,
24+
expect_snapshot(
25+
error = TRUE,
2226
adasyn(circle_example0, var = "class")
2327
)
2428

25-
expect_snapshot(error = TRUE,
29+
expect_snapshot(
30+
error = TRUE,
2631
adasyn(circle_example_num, var = "class", k = 0)
2732
)
2833

29-
expect_snapshot(error = TRUE,
34+
expect_snapshot(
35+
error = TRUE,
3036
adasyn(circle_example_num, var = "class", k = -1)
3137
)
3238

33-
expect_snapshot(error = TRUE,
39+
expect_snapshot(
40+
error = TRUE,
3441
adasyn(circle_example_num, var = "class", k = c(5, 10))
3542
)
3643
})

‎tests/testthat/test-bsmote.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ test_that("basic usage", {
4444
test_that("bad data", {
4545
rec <- recipe(~., data = circle_example)
4646
# numeric check
47-
expect_snapshot(error = TRUE,
47+
expect_snapshot(
48+
error = TRUE,
4849
rec %>%
4950
step_bsmote(x) %>%
5051
prep()
5152
)
5253
# Multiple variable check
53-
expect_snapshot(error = TRUE,
54+
expect_snapshot(
55+
error = TRUE,
5456
rec %>%
5557
step_bsmote(class, id) %>%
5658
prep()
@@ -64,7 +66,8 @@ test_that("errors if character are present", {
6466
stringsAsFactors = FALSE
6567
)
6668

67-
expect_snapshot(error = TRUE,
69+
expect_snapshot(
70+
error = TRUE,
6871
recipe(~., data = df_char) %>%
6972
step_bsmote(x) %>%
7073
prep()
@@ -76,7 +79,8 @@ test_that("NA in response", {
7679

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

79-
expect_snapshot(error = TRUE,
82+
expect_snapshot(
83+
error = TRUE,
8084
recipe(Job ~ Age, data = credit_data) %>%
8185
step_bsmote(Job) %>%
8286
prep()

‎tests/testthat/test-bsmote_impl.R

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,41 @@ circle_example_num <- circle_example[, c("x", "y", "class")]
33
test_that("bsmote() interfaces correctly", {
44
expect_no_error(bsmote(circle_example_num, var = "class"))
55

6-
expect_snapshot(error = TRUE,
6+
expect_snapshot(
7+
error = TRUE,
78
bsmote(circle_example_num, var = "Class")
89
)
910

10-
expect_snapshot(error = TRUE,
11+
expect_snapshot(
12+
error = TRUE,
1113
bsmote(circle_example_num, var = c("class", "x"))
1214
)
1315

14-
expect_snapshot(error = TRUE,
16+
expect_snapshot(
17+
error = TRUE,
1518
bsmote(circle_example_num, var = "x")
1619
)
1720

1821
circle_example0 <- circle_example_num
1922
circle_example0[1, 1] <- NA
2023

21-
expect_snapshot(error = TRUE,
24+
expect_snapshot(
25+
error = TRUE,
2226
bsmote(circle_example0, var = "class")
2327
)
2428

25-
expect_snapshot(error = TRUE,
29+
expect_snapshot(
30+
error = TRUE,
2631
bsmote(circle_example_num, var = "class", k = 0)
2732
)
2833

29-
expect_snapshot(error = TRUE,
34+
expect_snapshot(
35+
error = TRUE,
3036
bsmote(circle_example_num, var = "class", k = -1)
3137
)
3238

33-
expect_snapshot(error = TRUE,
39+
expect_snapshot(
40+
error = TRUE,
3441
bsmote(circle_example_num, var = "class", k = c(5, 10))
3542
)
3643
})

‎tests/testthat/test-downsample.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test_that("ratio deprecation", {
2-
expect_snapshot(error = TRUE,
2+
expect_snapshot(
3+
error = TRUE,
34
new_rec <- recipe(~., data = circle_example) %>%
45
step_downsample(class, ratio = 2)
56
)
@@ -22,13 +23,15 @@ test_that("basic usage", {
2223
test_that("bad data", {
2324
rec <- recipe(~., data = circle_example)
2425
# numeric check
25-
expect_snapshot(error = TRUE,
26+
expect_snapshot(
27+
error = TRUE,
2628
rec %>%
2729
step_downsample(x) %>%
2830
prep()
2931
)
3032
# Multiple variable check
31-
expect_snapshot(error = TRUE,
33+
expect_snapshot(
34+
error = TRUE,
3235
rec %>%
3336
step_downsample(class, id) %>%
3437
prep()

‎tests/testthat/test-nearmiss.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ test_that("basic usage", {
1515
test_that("bad data", {
1616
rec <- recipe(~., data = circle_example)
1717
# numeric check
18-
expect_snapshot(error = TRUE,
18+
expect_snapshot(
19+
error = TRUE,
1920
rec %>%
2021
step_nearmiss(x) %>%
2122
prep()
2223
)
2324
# Multiple variable check
24-
expect_snapshot(error = TRUE,
25+
expect_snapshot(
26+
error = TRUE,
2527
rec %>%
2628
step_nearmiss(class, id) %>%
2729
prep()
@@ -35,7 +37,8 @@ test_that("errors if character are present", {
3537
stringsAsFactors = FALSE
3638
)
3739

38-
expect_snapshot(error = TRUE,
40+
expect_snapshot(
41+
error = TRUE,
3942
recipe(~., data = df_char) %>%
4043
step_nearmiss(x) %>%
4144
prep()
@@ -47,7 +50,8 @@ test_that("NA in response", {
4750

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

50-
expect_snapshot(error = TRUE,
53+
expect_snapshot(
54+
error = TRUE,
5155
recipe(Job ~ Age, data = credit_data) %>%
5256
step_nearmiss(Job) %>%
5357
prep()

‎tests/testthat/test-rose.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ test_that("basic usage", {
5454
test_that("bad data", {
5555
rec <- recipe(~., data = circle_example)
5656
# numeric check
57-
expect_snapshot(error = TRUE,
57+
expect_snapshot(
58+
error = TRUE,
5859
rec %>%
5960
step_rose(x) %>%
6061
prep()
6162
)
6263
# Multiple variable check
63-
expect_snapshot(error = TRUE,
64+
expect_snapshot(
65+
error = TRUE,
6466
rec %>%
6567
step_rose(class, id) %>%
6668
prep()
@@ -74,7 +76,8 @@ test_that("NA in response", {
7476
credit_data0 <- credit_data
7577
credit_data0[1, 1] <- NA
7678

77-
expect_snapshot(error = TRUE,
79+
expect_snapshot(
80+
error = TRUE,
7881
recipe(Status ~ Age, data = credit_data0) %>%
7982
step_rose(Status) %>%
8083
prep()
@@ -124,7 +127,8 @@ test_that("only except 2 classes", {
124127
stringsAsFactors = FALSE
125128
)
126129

127-
expect_snapshot(error = TRUE,
130+
expect_snapshot(
131+
error = TRUE,
128132
recipe(~., data = df_char) %>%
129133
step_rose(x) %>%
130134
prep()

‎tests/testthat/test-smote.R

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ test_that("errors if there isn't enough data", {
88
credit_data0$Status[1] <- "dummy"
99
credit_data0$Status <- as.factor(credit_data0$Status)
1010

11-
expect_snapshot(error = TRUE,
11+
expect_snapshot(
12+
error = TRUE,
1213
recipe(Status ~ Age, data = credit_data0) %>%
1314
step_smote(Status) %>%
1415
prep()
@@ -32,13 +33,15 @@ test_that("basic usage", {
3233
test_that("bad data", {
3334
rec <- recipe(~., data = circle_example)
3435
# numeric check
35-
expect_snapshot(error = TRUE,
36+
expect_snapshot(
37+
error = TRUE,
3638
rec %>%
3739
step_smote(x) %>%
3840
prep()
3941
)
4042
# Multiple variable check
41-
expect_snapshot(error = TRUE,
43+
expect_snapshot(
44+
error = TRUE,
4245
rec %>%
4346
step_smote(class, id) %>%
4447
prep()
@@ -52,7 +55,8 @@ test_that("errors if character are present", {
5255
stringsAsFactors = FALSE
5356
)
5457

55-
expect_snapshot(error = TRUE,
58+
expect_snapshot(
59+
error = TRUE,
5660
recipe(~., data = df_char) %>%
5761
step_smote(x) %>%
5862
prep()
@@ -64,7 +68,8 @@ test_that("NA in response", {
6468

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

67-
expect_snapshot(error = TRUE,
71+
expect_snapshot(
72+
error = TRUE,
6873
recipe(Job ~ Age, data = credit_data) %>%
6974
step_smote(Job) %>%
7075
prep()

‎tests/testthat/test-smote_impl.R

+14-7
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,41 @@ test_that("smote() interfaces correctly", {
2424

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

27-
expect_snapshot(error = TRUE,
27+
expect_snapshot(
28+
error = TRUE,
2829
smote(circle_example_num, var = "Class")
2930
)
3031

31-
expect_snapshot(error = TRUE,
32+
expect_snapshot(
33+
error = TRUE,
3234
smote(circle_example_num, var = c("class", "x"))
3335
)
3436

35-
expect_snapshot(error = TRUE,
37+
expect_snapshot(
38+
error = TRUE,
3639
smote(circle_example_num, var = "x")
3740
)
3841

3942
circle_example0 <- circle_example_num
4043
circle_example0[1, 1] <- NA
4144

42-
expect_snapshot(error = TRUE,
45+
expect_snapshot(
46+
error = TRUE,
4347
smote(circle_example0, var = "class")
4448
)
4549

46-
expect_snapshot(error = TRUE,
50+
expect_snapshot(
51+
error = TRUE,
4752
smote(circle_example_num, var = "class", k = 0)
4853
)
4954

50-
expect_snapshot(error = TRUE,
55+
expect_snapshot(
56+
error = TRUE,
5157
smote(circle_example_num, var = "class", k = -1)
5258
)
5359

54-
expect_snapshot(error = TRUE,
60+
expect_snapshot(
61+
error = TRUE,
5562
smote(circle_example_num, var = "class", k = c(5, 10))
5663
)
5764
})

‎tests/testthat/test-tomek.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ test_that("basic usage", {
1515
test_that("bad data", {
1616
rec <- recipe(~., data = circle_example)
1717
# numeric check
18-
expect_snapshot(error = TRUE,
18+
expect_snapshot(
19+
error = TRUE,
1920
rec %>%
2021
step_smote(x) %>%
2122
prep()
2223
)
2324
# Multiple variable check
24-
expect_snapshot(error = TRUE,
25+
expect_snapshot(
26+
error = TRUE,
2527
rec %>%
2628
step_smote(class, id) %>%
2729
prep()
@@ -35,7 +37,8 @@ test_that("errors if character are present", {
3537
stringsAsFactors = FALSE
3638
)
3739

38-
expect_snapshot(error = TRUE,
40+
expect_snapshot(
41+
error = TRUE,
3942
recipe(~., data = df_char) %>%
4043
step_tomek(x) %>%
4144
prep()
@@ -49,7 +52,8 @@ test_that("NA in response", {
4952
credit_data0 <- credit_data
5053
credit_data0[1, 1] <- NA
5154

52-
expect_snapshot(error = TRUE,
55+
expect_snapshot(
56+
error = TRUE,
5357
recipe(Status ~ Age, data = credit_data0) %>%
5458
step_tomek(Status) %>%
5559
prep()

‎tests/testthat/test-tomek_impl.R

+12-8
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ test_that("tomek() interfaces correctly", {
1919

2020
expect_no_error(tomek(circle_example_num, var = "class"))
2121

22-
expect_snapshot(error = TRUE,
23-
tomek(circle_example_num, var = "Class")
22+
expect_snapshot(
23+
error = TRUE,
24+
tomek(circle_example_num, var = "Class")
2425
)
2526

26-
expect_snapshot(error = TRUE,
27-
tomek(circle_example_num, var = c("class", "x"))
27+
expect_snapshot(
28+
error = TRUE,
29+
tomek(circle_example_num, var = c("class", "x"))
2830
)
2931

30-
expect_snapshot(error = TRUE,
31-
tomek(circle_example_num, var = "x")
32+
expect_snapshot(
33+
error = TRUE,
34+
tomek(circle_example_num, var = "x")
3235
)
3336

3437
circle_example0 <- circle_example_num
3538
circle_example0[1, 1] <- NA
3639

37-
expect_snapshot(error = TRUE,
38-
tomek(circle_example0, var = "class")
40+
expect_snapshot(
41+
error = TRUE,
42+
tomek(circle_example0, var = "class")
3943
)
4044
})
4145

‎tests/testthat/test-upsample.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test_that("ratio deprecation", {
2-
expect_snapshot(error = TRUE,
2+
expect_snapshot(
3+
error = TRUE,
34
new_rec <- recipe(~., data = circle_example) %>%
45
step_upsample(class, ratio = 2)
56
)
@@ -22,13 +23,15 @@ test_that("basic usage", {
2223
test_that("bad data", {
2324
rec <- recipe(~., data = circle_example)
2425
# numeric check
25-
expect_snapshot(error = TRUE,
26+
expect_snapshot(
27+
error = TRUE,
2628
rec %>%
2729
step_upsample(x) %>%
2830
prep()
2931
)
3032
# Multiple variable check
31-
expect_snapshot(error = TRUE,
33+
expect_snapshot(
34+
error = TRUE,
3235
rec %>%
3336
step_upsample(class, id) %>%
3437
prep()

0 commit comments

Comments
 (0)
Please sign in to comment.