Skip to content

Commit

Permalink
Avoid iris in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Jan 23, 2022
1 parent 7007a47 commit 8d76122
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 97 deletions.
54 changes: 20 additions & 34 deletions tests/testthat/_snaps/ctl_colonnade.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,52 +62,38 @@
Code
ctl_colonnade(iris[1:5, ], width = 30)
ctl_colonnade(trees[1:5, ], width = 20)
Output
$body
Sepal.Length Sepal.Width
<dbl> <dbl>
1 5.1 3.5
2 4.9 3
3 4.7 3.2
4 4.6 3.1
5 5 3.6
Girth Height
<dbl> <dbl>
1 8.3 70
2 8.6 65
3 8.8 63
4 10.5 72
5 10.7 81
$extra_cols
$extra_cols$Petal.Length
[1] 1.4 1.4 1.3 1.5 1.4
$extra_cols$Petal.Width
[1] 0.2 0.2 0.2 0.2 0.2
$extra_cols$Species
[1] setosa setosa setosa setosa setosa
Levels: setosa versicolor virginica
$extra_cols$Volume
[1] 10.3 10.3 10.2 16.4 18.8
Code
ctl_colonnade(iris[1:3, ], width = 20)
ctl_colonnade(trees[1:3, ], width = 10)
Output
$body
Sepal.Length
<dbl>
1 5.1
2 4.9
3 4.7
Girth
<dbl>
1 8.3
2 8.6
3 8.8
$extra_cols
$extra_cols$Sepal.Width
[1] 3.5 3.0 3.2
$extra_cols$Petal.Length
[1] 1.4 1.4 1.3
$extra_cols$Petal.Width
[1] 0.2 0.2 0.2
$extra_cols$Height
[1] 70 65 63
$extra_cols$Species
[1] setosa setosa setosa
Levels: setosa versicolor virginica
$extra_cols$Volume
[1] 10.3 10.3 10.2
Code
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/format_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<int [3]>
<NULL>
Code
pillar(list(iris), width = 10)
pillar(list(trees), width = 10)
Output
<pillar>
<list>
Expand Down
28 changes: 14 additions & 14 deletions tests/testthat/_snaps/format_multi.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,23 +363,23 @@
7 14.3 8 360 245
8 24.4 4 147. 62
Code
colonnade(iris[1:5, ], width = 30)
colonnade(trees[1:5, ], width = 20)
Output
Sepal.Length Sepal.Width
<dbl> <dbl>
1 5.1 3.5
2 4.9 3
3 4.7 3.2
4 4.6 3.1
5 5 3.6
Girth Height
<dbl> <dbl>
1 8.3 70
2 8.6 65
3 8.8 63
4 10.5 72
5 10.7 81
Code
colonnade(iris[1:3, ], width = 20)
colonnade(trees[1:3, ], width = 10)
Output
Sepal.Length
<dbl>
1 5.1
2 4.9
3 4.7
Girth
<dbl>
1 8.3
2 8.6
3 8.8
Code
colonnade(df_all, width = 30)
Output
Expand Down
54 changes: 25 additions & 29 deletions tests/testthat/_snaps/glimpse.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,18 @@
$ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4~
$ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2~
Code
glimpse(as_tbl(iris), width = 70L)
glimpse(as_tbl(trees), width = 70L)
Output
Rows: 150
Columns: 5
$ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.~
$ Sepal.Width <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.~
$ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.~
$ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.~
$ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa,~
Rows: 31
Columns: 3
$ Girth <dbl> 8.3, 8.6, 8.8, 10.5, 10.7, 10.8, 11.0, 11.0, 11.1, 11~
$ Height <dbl> 70, 65, 63, 72, 81, 83, 66, 75, 80, 75, 79, 76, 76, 6~
$ Volume <dbl> 10.3, 10.3, 10.2, 16.4, 18.8, 19.7, 15.6, 18.2, 22.6,~
Code
# No columns
glimpse(as_tbl(iris[integer()]), width = 70L)
glimpse(as_tbl(trees[integer()]), width = 70L)
Output
Rows: 150
Rows: 31
Columns: 0
Code
# Non-syntactic names
Expand Down Expand Up @@ -190,33 +188,31 @@
Output
num 5
Code
iris2 <- as_unknown_rows(iris)
glimpse(iris2, width = 70L)
trees2 <- as_unknown_rows(trees)
glimpse(trees2, width = 70L)
Output
Rows: ??
Columns: 5
$ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.~
$ Sepal.Width <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.~
$ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.~
$ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.~
$ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa,~
Code
species <- unique(iris$Species)
data <- unname(split(iris, iris$Species))
nested_iris_df <- tibble::tibble(species, data)
glimpse(nested_iris_df, width = 70L)
Columns: 3
$ Girth <dbl> 8.3, 8.6, 8.8, 10.5, 10.7, 10.8, 11.0, 11.0, 11.1, 11~
$ Height <dbl> 70, 65, 63, 72, 81, 83, 66, 75, 80, 75, 79, 76, 76, 6~
$ Volume <dbl> 10.3, 10.3, 10.2, 16.4, 18.8, 19.7, 15.6, 18.2, 22.6,~
Code
cyl <- unique(mtcars$cyl)
data <- unname(split(mtcars, mtcars$cyl))
nested_mtcars_df <- tibble::tibble(cyl, data)
glimpse(nested_mtcars_df, width = 70L)
Output
Rows: 3
Columns: 2
$ species <fct> setosa, versicolor, virginica
$ data <list> [<data.frame[50 x 5]>], [<data.frame[50 x 5]>], [<da~
$ cyl <dbl> 6, 4, 8
$ data <list> [<data.frame[11 x 11]>], [<data.frame[7 x 11]>], [<data~
Code
data <- map(data, as_tbl)
nested_iris_tbl <- tibble::tibble(species, data)
glimpse(nested_iris_tbl, width = 70L)
nested_mtcars_tbl <- tibble::tibble(cyl, data)
glimpse(nested_mtcars_tbl, width = 70L)
Output
Rows: 3
Columns: 2
$ species <fct> setosa, versicolor, virginica
$ data <list> [<tbl[50 x 5]>], [<tbl[50 x 5]>], [<tbl[50 x 5]>]
$ cyl <dbl> 6, 4, 8
$ data <list> [<tbl[11 x 11]>], [<tbl[7 x 11]>], [<tbl[14 x 11]>]

6 changes: 3 additions & 3 deletions tests/testthat/test-ctl_colonnade.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test_that("tests from tibble", {

expect_snapshot({
ctl_colonnade(mtcars[1:8, ], has_row_id = "*", width = 30)
ctl_colonnade(iris[1:5, ], width = 30)
ctl_colonnade(iris[1:3, ], width = 20)
ctl_colonnade(trees[1:5, ], width = 20)
ctl_colonnade(trees[1:3, ], width = 10)
ctl_colonnade(df_all, width = 30)
ctl_colonnade(df_all, width = 300)
options(width = 70)
Expand Down Expand Up @@ -40,7 +40,7 @@ test_that("empty", {
character()
)
expect_equal(
format(ctl_colonnade(iris[1:5, character()], width = 30)$body),
format(ctl_colonnade(trees[1:5, character()], width = 30)$body),
character()
)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-format_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ test_that("output test", {
pillar(as.list(1:3))
pillar(list(1:3, NULL))
pillar(add_special(list(1:3)))
pillar(list(iris), width = 10)
pillar(list(trees), width = 10)
})
})
6 changes: 3 additions & 3 deletions tests/testthat/test-format_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ test_that("tests from tibble", {

expect_snapshot({
colonnade(mtcars[1:8, ], has_row_id = "*", width = 30)
colonnade(iris[1:5, ], width = 30)
colonnade(iris[1:3, ], width = 20)
colonnade(trees[1:5, ], width = 20)
colonnade(trees[1:3, ], width = 10)
colonnade(df_all, width = 30)
colonnade(df_all, width = 300)
options(width = 70)
Expand Down Expand Up @@ -128,7 +128,7 @@ test_that("empty", {
as_glue(character())
)
expect_equal(
format(colonnade(iris[1:5, character()], width = 30)),
format(colonnade(trees[1:5, character()], width = 30)),
as_glue(character())
)
})
Expand Down
24 changes: 12 additions & 12 deletions tests/testthat/test-glimpse.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ test_that("glimpse calls tbl_sum() (#550)", {

local_override_tbl_sum()

iris2 <- as_override_tbl_sum(iris)
trees2 <- as_override_tbl_sum(trees)

expect_output(
glimpse(iris2),
glimpse(trees2),
"Overridden: tbl_sum",
fixed = TRUE
)
Expand All @@ -61,10 +61,10 @@ test_that("output test for glimpse()", {
expect_snapshot({
glimpse(as_tbl(mtcars), width = 70L)

glimpse(as_tbl(iris), width = 70L)
glimpse(as_tbl(trees), width = 70L)

"No columns"
glimpse(as_tbl(iris[integer()]), width = 70L)
glimpse(as_tbl(trees[integer()]), width = 70L)

"Non-syntactic names"
df <- tibble::tibble(!!!set_names(c(5, 3), c("mean(x)", "var(x)")))
Expand All @@ -87,16 +87,16 @@ test_that("output test for glimpse()", {
"non-tibble"
glimpse(5)

iris2 <- as_unknown_rows(iris)
glimpse(iris2, width = 70L)
trees2 <- as_unknown_rows(trees)
glimpse(trees2, width = 70L)

species <- unique(iris$Species)
data <- unname(split(iris, iris$Species))
nested_iris_df <- tibble::tibble(species, data)
glimpse(nested_iris_df, width = 70L)
cyl <- unique(mtcars$cyl)
data <- unname(split(mtcars, mtcars$cyl))
nested_mtcars_df <- tibble::tibble(cyl, data)
glimpse(nested_mtcars_df, width = 70L)

data <- map(data, as_tbl)
nested_iris_tbl <- tibble::tibble(species, data)
glimpse(nested_iris_tbl, width = 70L)
nested_mtcars_tbl <- tibble::tibble(cyl, data)
glimpse(nested_mtcars_tbl, width = 70L)
})
})

0 comments on commit 8d76122

Please sign in to comment.