Skip to content

Commit efeafa4

Browse files
committed
split up test_that() chunks
1 parent e332d2b commit efeafa4

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

tests/testthat/_snaps/sparsevctrs.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
# sparse tibble can be passed to `fit()
1+
# sparse tibble can be passed to `fit() - supported
22

33
Code
44
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data)
55
Condition
66
Error in `.convert_form_to_xy_fit()`:
77
! Sparse data cannot be used with formula interface. Please use `fit_xy()` instead.
88

9-
---
9+
# sparse tibble can be passed to `fit() - unsupported
1010

1111
Code
1212
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data[1:100, ])
1313
Condition
1414
Warning:
1515
`data` is a sparse tibble, but `linear_reg()` with engine "lm" doesn't accept that. Converting to non-sparse.
1616

17-
# sparse matrix can be passed to `fit()
17+
# sparse matrix can be passed to `fit() - supported
1818

1919
Code
2020
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data)
2121
Condition
2222
Error in `.convert_form_to_xy_fit()`:
2323
! Sparse data cannot be used with formula interface. Please use `fit_xy()` instead.
2424

25-
---
25+
# sparse matrix can be passed to `fit() - unsupported
2626

2727
Code
2828
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data[1:100, ])
2929
Condition
3030
Warning:
3131
`data` is a sparse tibble, but `linear_reg()` with engine "lm" doesn't accept that. Converting to non-sparse.
3232

33-
# sparse tibble can be passed to `fit_xy()
33+
# sparse tibble can be passed to `fit_xy() - unsupported
3434

3535
Code
3636
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1])
3737
Condition
3838
Warning:
3939
`x` is a sparse tibble, but `linear_reg()` with engine "lm" doesn't accept that. Converting to non-sparse.
4040

41-
# sparse matrices can be passed to `fit_xy()
41+
# sparse matrices can be passed to `fit_xy() - unsupported
4242

4343
Code
4444
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1])
4545
Condition
4646
Error in `fit_xy()`:
4747
! `x` is a sparse matrix, but `linear_reg()` with engine "lm" doesn't accept that.
4848

49-
# sparse tibble can be passed to `predict()
49+
# sparse tibble can be passed to `predict() - unsupported
5050

5151
Code
5252
preds <- predict(lm_fit, sparse_mtcars)
5353
Condition
5454
Warning:
5555
`x` is a sparse tibble, but `linear_reg()` with engine "lm" doesn't accept that. Converting to non-sparse.
5656

57-
# sparse matrices can be passed to `predict()
57+
# sparse matrices can be passed to `predict() - unsupported
5858

5959
Code
6060
predict(lm_fit, sparse_mtcars)

tests/testthat/test-sparsevctrs.R

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("sparse tibble can be passed to `fit()", {
1+
test_that("sparse tibble can be passed to `fit() - supported", {
22
skip_if_not_installed("xgboost")
33
withr::local_options("sparsevctrs.verbose_materialize" = 3)
44

@@ -12,19 +12,21 @@ test_that("sparse tibble can be passed to `fit()", {
1212
error = TRUE,
1313
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data)
1414
)
15+
})
16+
17+
test_that("sparse tibble can be passed to `fit() - unsupported", {
18+
hotel_data <- sparse_hotel_rates(tibble = TRUE)
1519

1620
spec <- linear_reg() %>%
1721
set_mode("regression") %>%
1822
set_engine("lm")
1923

20-
withr::local_options("sparsevctrs.verbose_materialize" = NULL)
21-
2224
expect_snapshot(
2325
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data[1:100, ])
2426
)
2527
})
2628

27-
test_that("sparse matrix can be passed to `fit()", {
29+
test_that("sparse matrix can be passed to `fit() - supported", {
2830
skip_if_not_installed("xgboost")
2931
withr::local_options("sparsevctrs.verbose_materialize" = 3)
3032

@@ -39,7 +41,10 @@ test_that("sparse matrix can be passed to `fit()", {
3941
lm_fit <- fit(spec, avg_price_per_room ~ ., data = hotel_data)
4042
)
4143

42-
withr::local_options("sparsevctrs.verbose_materialize" = NULL)
44+
})
45+
46+
test_that("sparse matrix can be passed to `fit() - unsupported", {
47+
hotel_data <- sparse_hotel_rates()
4348

4449
spec <- linear_reg() %>%
4550
set_mode("regression") %>%
@@ -50,12 +55,11 @@ test_that("sparse matrix can be passed to `fit()", {
5055
)
5156
})
5257

53-
test_that("sparse tibble can be passed to `fit_xy()", {
58+
test_that("sparse tibble can be passed to `fit_xy() - supported", {
5459
skip_if_not_installed("xgboost")
60+
withr::local_options("sparsevctrs.verbose_materialize" = 3)
5561

5662
hotel_data <- sparse_hotel_rates(tibble = TRUE)
57-
58-
withr::local_options("sparsevctrs.verbose_materialize" = 3)
5963

6064
spec <- boost_tree() %>%
6165
set_mode("regression") %>%
@@ -64,8 +68,10 @@ test_that("sparse tibble can be passed to `fit_xy()", {
6468
expect_no_error(
6569
lm_fit <- fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
6670
)
71+
})
6772

68-
withr::local_options("sparsevctrs.verbose_materialize" = NULL)
73+
test_that("sparse tibble can be passed to `fit_xy() - unsupported", {
74+
hotel_data <- sparse_hotel_rates(tibble = TRUE)
6975

7076
spec <- linear_reg() %>%
7177
set_mode("regression") %>%
@@ -76,7 +82,7 @@ test_that("sparse tibble can be passed to `fit_xy()", {
7682
)
7783
})
7884

79-
test_that("sparse matrices can be passed to `fit_xy()", {
85+
test_that("sparse matrices can be passed to `fit_xy() - supported", {
8086
skip_if_not_installed("xgboost")
8187
withr::local_options("sparsevctrs.verbose_materialize" = 3)
8288

@@ -89,6 +95,10 @@ test_that("sparse matrices can be passed to `fit_xy()", {
8995
expect_no_error(
9096
lm_fit <- fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
9197
)
98+
})
99+
100+
test_that("sparse matrices can be passed to `fit_xy() - unsupported", {
101+
hotel_data <- sparse_hotel_rates()
92102

93103
spec <- linear_reg() %>%
94104
set_mode("regression") %>%
@@ -100,12 +110,11 @@ test_that("sparse matrices can be passed to `fit_xy()", {
100110
)
101111
})
102112

103-
test_that("sparse tibble can be passed to `predict()", {
113+
test_that("sparse tibble can be passed to `predict() - supported", {
104114
skip_if_not_installed("ranger")
115+
withr::local_options("sparsevctrs.verbose_materialize" = 3)
105116

106117
hotel_data <- sparse_hotel_rates(tibble = TRUE)
107-
108-
withr::local_options("sparsevctrs.verbose_materialize" = 3)
109118

110119
spec <- rand_forest(trees = 10) %>%
111120
set_mode("regression") %>%
@@ -116,8 +125,10 @@ test_that("sparse tibble can be passed to `predict()", {
116125
expect_no_error(
117126
predict(tree_fit, hotel_data)
118127
)
128+
})
119129

120-
withr::local_options("sparsevctrs.verbose_materialize" = NULL)
130+
test_that("sparse tibble can be passed to `predict() - unsupported", {
131+
hotel_data <- sparse_hotel_rates(tibble = TRUE)
121132

122133
spec <- linear_reg() %>%
123134
set_mode("regression") %>%
@@ -134,7 +145,7 @@ test_that("sparse tibble can be passed to `predict()", {
134145
)
135146
})
136147

137-
test_that("sparse matrices can be passed to `predict()", {
148+
test_that("sparse matrices can be passed to `predict() - supported", {
138149
skip_if_not_installed("ranger")
139150
withr::local_options("sparsevctrs.verbose_materialize" = 3)
140151

@@ -149,6 +160,10 @@ test_that("sparse matrices can be passed to `predict()", {
149160
expect_no_error(
150161
predict(tree_fit, hotel_data)
151162
)
163+
})
164+
165+
test_that("sparse matrices can be passed to `predict() - unsupported", {
166+
hotel_data <- sparse_hotel_rates()
152167

153168
spec <- linear_reg() %>%
154169
set_mode("regression") %>%

0 commit comments

Comments
 (0)