Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update standalone files + standardize snapshot tests #1579

Merged
merged 11 commits into from
Oct 25, 2024
5 changes: 2 additions & 3 deletions tests/testthat/_snaps/append.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# after must be integer or character

Code
(expect_error(df_append(df1, df2, after = 1.5)))
Output
<error/rlang_error>
df_append(df1, df2, after = 1.5)
Condition <rlang_error>
Error in `df_append()`:
! `after` must be a whole number, not the number 1.5.
i This is an internal error that was detected in the tidyr package.
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/_snaps/chop.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@
# incompatible sizes are caught

Code
(expect_error(unchop(df, c(x, y))))
Output
<error/rlang_error>
unchop(df, c(x, y))
Condition <rlang_error>
Error in `unchop()`:
! In row 1, can't recycle input of size 2 to size 3.

# empty typed inputs are considered in common size, but NULLs aren't

Code
(expect_error(unchop(df, c(x, y))))
Output
<error/rlang_error>
unchop(df, c(x, y))
Condition <rlang_error>
Error in `unchop()`:
! In row 1, can't recycle input of size 0 to size 2.

Expand Down
13 changes: 4 additions & 9 deletions tests/testthat/_snaps/drop-na.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# errors are raised

Code
(expect_error(drop_na(df, list())))
Output
<error/vctrs_error_subscript_type>
drop_na(df, list())
Condition <vctrs_error_subscript_type>
Error in `drop_na()`:
! Can't select columns with `list()`.
x `list()` must be numeric or character, not an empty list.

---

Code
(expect_error(drop_na(df, "z")))
Output
<error/vctrs_error_subscript_oob>
drop_na(df, "z")
Condition <vctrs_error_subscript_oob>
Error in `drop_na()`:
! Can't select columns that don't exist.
x Column `z` doesn't exist.
Expand Down
15 changes: 6 additions & 9 deletions tests/testthat/_snaps/expand.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# crossing checks for bad inputs

Code
(expect_error(crossing(x = 1:10, y = quote(a))))
Output
<error/vctrs_error_scalar_type>
crossing(x = 1:10, y = quote(a))
Condition <vctrs_error_scalar_type>
Error in `crossing()`:
! `..2` must be a vector, not a symbol.

Expand Down Expand Up @@ -37,9 +36,8 @@
# expand_grid() can control name_repair

Code
(expect_error(expand_grid(x = x, x = x)))
Output
<error/vctrs_error_names_must_be_unique>
expand_grid(x = x, x = x)
Condition <vctrs_error_names_must_be_unique>
Error in `expand_grid()`:
! Names must be unique.
x These names are duplicated:
Expand All @@ -66,9 +64,8 @@
# grid_dots() reject non-vector input

Code
(expect_error(grid_dots(lm(1 ~ 1))))
Output
<error/vctrs_error_scalar_type>
grid_dots(lm(1 ~ 1))
Condition <vctrs_error_scalar_type>
Error:
! `..1` must be a vector, not a <lm> object.

15 changes: 6 additions & 9 deletions tests/testthat/_snaps/extract.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
# informative error message if wrong number of groups

Code
(expect_error(extract(df, x, "y", ".")))
Output
<error/rlang_error>
extract(df, x, "y", ".")
Condition <rlang_error>
Error in `extract()`:
! `regex` should define 1 groups; 0 found.
Code
(expect_error(extract(df, x, c("y", "z"), ".")))
Output
<error/rlang_error>
extract(df, x, c("y", "z"), ".")
Condition <rlang_error>
Error in `extract()`:
! `regex` should define 2 groups; 0 found.

# informative error if using stringr modifier functions (#693)

Code
(expect_error(extract(df, x, "x", regex = regex)))
Output
<error/rlang_error>
extract(df, x, "x", regex = regex)
Condition <rlang_error>
Error in `extract()`:
! `regex` can't use modifiers from stringr.

Expand Down
42 changes: 24 additions & 18 deletions tests/testthat/_snaps/gather.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
# gather throws error for POSIXlt

Code
(expect_error(gather(df, key, val, -x)))
Output
<simpleError: 'x' is a POSIXlt. Please convert to POSIXct.>
gather(df, key, val, -x)
Condition <simpleError>
Error:
! 'x' is a POSIXlt. Please convert to POSIXct.
Code
(expect_error(gather(df, key, val, -y)))
Output
<simpleError: Column 1 is a POSIXlt. Please convert to POSIXct.>
gather(df, key, val, -y)
Condition <simpleError>
Error:
! Column 1 is a POSIXlt. Please convert to POSIXct.

# gather throws error for weird objects

Code
(expect_error(gather(df, key, val, -x)))
Output
<simpleError: All columns must be atomic vectors or lists. Problem with 'x'>
gather(d, key, val, -x)
Condition <simpleError>
Error:
! object 'd' not found
Code
(expect_error(gather(df, key, val, -y)))
Output
<simpleError: All columns be atomic vectors or lists (not expression)>
gather(df, key, val, -y)
Condition <simpleError>
Error:
! All columns be atomic vectors or lists (not expression)

---

Code
(expect_error(gather(df, key, val, -x)))
Output
<simpleError: All columns must be atomic vectors or lists. Problem with 'x'>
gather(df, key, val, -x)
Condition <simpleError>
Error:
! All columns must be atomic vectors or lists. Problem with 'x'
Code
(expect_error(gather(df, key, val, -y)))
Output
<simpleError: All columns must be atomic vectors or lists. Problem with column 2.>
gather(df, key, val, -y)
Condition <simpleError>
Error:
! All columns must be atomic vectors or lists. Problem with column 2.

# factors coerced to characters, not integers

Expand Down
25 changes: 10 additions & 15 deletions tests/testthat/_snaps/hoist.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
# nested lists generate a cast error if they can't be cast to the ptype

Code
(expect_error(hoist(df, x, "b", .ptype = list(b = double()))))
Output
<error/vctrs_error_cast>
hoist(df, x, "b", .ptype = list(b = double()))
Condition <vctrs_error_cast>
Error in `hoist()`:
! Can't convert `..1` <list> to <double>.

# non-vectors generate a cast error if a ptype is supplied

Code
(expect_error(hoist(df, x, "b", .ptype = list(b = integer()))))
Output
<error/vctrs_error_scalar_type>
hoist(df, x, "b", .ptype = list(b = integer()))
Condition <vctrs_error_scalar_type>
Error in `hoist()`:
! `..1` must be a vector, not a symbol.

# input validation catches problems

Code
(expect_error(df %>% hoist(y)))
Output
<error/rlang_error>
df %>% hoist(y)
Condition <rlang_error>
Error in `hoist()`:
! `.data[[.col]]` must be a list, not the number 1.
Code
(expect_error(df %>% hoist(x, 1)))
Output
<error/rlang_error>
df %>% hoist(x, 1)
Condition <rlang_error>
Error in `hoist()`:
! All elements of `...` must be named.
Code
(expect_error(df %>% hoist(x, a = "a", a = "b")))
Output
<error/rlang_error>
df %>% hoist(x, a = "a", a = "b")
Condition <rlang_error>
Error in `hoist()`:
! The names of `...` must be unique.

Expand Down
15 changes: 6 additions & 9 deletions tests/testthat/_snaps/nest-legacy.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# can't combine vectors and data frames

Code
(expect_error(unnest_legacy(df)))
Output
<error/rlang_error>
unnest_legacy(df)
Condition <rlang_error>
Error in `unnest_legacy()`:
! Each column must either be a list of vectors or a list of data frames.
i Problems in: `x`

# multiple columns must be same length

Code
(expect_error(unnest_legacy(df)))
Output
<error/rlang_error>
unnest_legacy(df)
Condition <rlang_error>
Error in `unnest_legacy()`:
! All nested columns must have the same number of elements.

---

Code
(expect_error(unnest_legacy(df)))
Output
<error/rlang_error>
unnest_legacy(df)
Condition <rlang_error>
Error in `unnest_legacy()`:
! All nested columns must have the same number of elements.

66 changes: 26 additions & 40 deletions tests/testthat/_snaps/unnest-helper.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,77 @@
# `simplify` is validated

Code
(expect_error(df_simplify(data.frame(), simplify = 1)))
Output
<error/rlang_error>
df_simplify(data.frame(), simplify = 1)
Condition <rlang_error>
Error:
! `simplify` must be a list or a single `TRUE` or `FALSE`.
Code
(expect_error(df_simplify(data.frame(), simplify = NA)))
Output
<error/rlang_error>
df_simplify(data.frame(), simplify = NA)
Condition <rlang_error>
Error:
! `simplify` must be a list or a single `TRUE` or `FALSE`.
Code
(expect_error(df_simplify(data.frame(), simplify = c(TRUE, FALSE))))
Output
<error/rlang_error>
df_simplify(data.frame(), simplify = c(TRUE, FALSE))
Condition <rlang_error>
Error:
! `simplify` must be a list or a single `TRUE` or `FALSE`.
Code
(expect_error(df_simplify(data.frame(), simplify = list(1))))
Output
<error/rlang_error>
df_simplify(data.frame(), simplify = list(1))
Condition <rlang_error>
Error:
! All elements of `simplify` must be named.
Code
(expect_error(df_simplify(data.frame(), simplify = list(x = 1, x = 1))))
Output
<error/rlang_error>
df_simplify(data.frame(), simplify = list(x = 1, x = 1))
Condition <rlang_error>
Error:
! The names of `simplify` must be unique.

# `ptype` is validated

Code
(expect_error(df_simplify(data.frame(), ptype = 1)))
Output
<error/rlang_error>
df_simplify(data.frame(), ptype = 1)
Condition <rlang_error>
Error:
! `ptype` must be `NULL`, an empty ptype, or a named list of ptypes.
Code
(expect_error(df_simplify(data.frame(), ptype = list(1))))
Output
<error/rlang_error>
df_simplify(data.frame(), ptype = list(1))
Condition <rlang_error>
Error:
! All elements of `ptype` must be named.
Code
(expect_error(df_simplify(data.frame(), ptype = list(x = 1, x = 1))))
Output
<error/rlang_error>
df_simplify(data.frame(), ptype = list(x = 1, x = 1))
Condition <rlang_error>
Error:
! The names of `ptype` must be unique.

# `transform` is validated

Code
(expect_error(df_simplify(data.frame(), transform = list(~.x))))
Output
<error/rlang_error>
df_simplify(data.frame(), transform = list(~.x))
Condition <rlang_error>
Error:
! All elements of `transform` must be named.
Code
(expect_error(df_simplify(data.frame(x = 1), transform = 1)))
Output
<error/rlang_error>
df_simplify(data.frame(x = 1), transform = 1)
Condition <rlang_error>
Error:
! `transform` must be `NULL`, a function, or a named list of functions.
Code
(expect_error(df_simplify(data.frame(), transform = list(x = 1))))
Output
<error/rlang_error>
df_simplify(data.frame(), transform = list(x = 1))
Condition <rlang_error>
Error:
! Can't convert `transform$x`, a double vector, to a function.
Code
(expect_error(df_simplify(data.frame(), transform = list(x = 1, x = 1))))
Output
<error/rlang_error>
df_simplify(data.frame(), transform = list(x = 1, x = 1))
Condition <rlang_error>
Error:
! The names of `transform` must be unique.

# ptype is applied after transform

Code
(expect_error(col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x +
1.5)))
Output
<error/vctrs_error_cast_lossy>
col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + 1.5)
Condition <vctrs_error_cast_lossy>
Error:
! Can't convert from `..1` <double> to <integer> due to loss of precision.
* Locations: 1
Expand Down
Loading