Skip to content

Commit

Permalink
updated testthat report format to match latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
alberthat committed Feb 27, 2024
1 parent 93ae66e commit 00042d6
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 74 deletions.
32 changes: 26 additions & 6 deletions tests/testthat/_snaps/coercion.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,78 @@
Code
df <- read_excel(test_sheet("types.xls"), sheet = "logical_coercion",
col_types = c("logical", "text"))
Warning <simpleWarning>
Condition
Warning:
Expecting logical in A14 / R14C1: got 'cabbage'
Warning:
Expecting logical in A18 / R18C1: got a date

---

Code
df <- read_excel(test_sheet("types.xlsx"), sheet = "logical_coercion",
col_types = c("logical", "text"))
Warning <simpleWarning>
Condition
Warning:
Expecting logical in A14 / R14C1: got 'cabbage'
Warning:
Expecting logical in A18 / R18C1: got a date

# contaminated, explicit date is read as date

Code
df <- read_excel(test_sheet("types.xls"), sheet = "date_coercion", col_types = "date")
Warning <simpleWarning>
Condition
Warning:
Expecting date in A4 / R4C1: got boolean
Warning:
Expecting date in A5 / R5C1: got 'cabbage'
Warning:
Coercing numeric to date in A6 / R6C1
Warning:
Coercing numeric to date in A7 / R7C1

---

Code
df <- read_excel(test_sheet("types.xlsx"), sheet = "date_coercion", col_types = "date")
Warning <simpleWarning>
Condition
Warning:
Expecting date in A4 / R4C1: got boolean
Warning:
Expecting date in A5 / R5C1: got 'cabbage'
Warning:
Coercing numeric to date in A6 / R6C1
Warning:
Coercing numeric to date in A7 / R7C1

# contaminated, explicit numeric is read as numeric

Code
df <- read_excel(test_sheet("types.xls"), sheet = "numeric_coercion",
col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Coercing text to numeric in A3 / R3C1: '72'
Warning:
Coercing boolean to numeric in A5 / R5C1
Warning:
Expecting numeric in A6 / R6C1: got a date
Warning:
Expecting numeric in A7 / R7C1: got 'cabbage'

---

Code
df <- read_excel(test_sheet("types.xlsx"), sheet = "numeric_coercion",
col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Coercing text to numeric in A3 / R3C1: '72'
Warning:
Coercing boolean to numeric in A5 / R5C1
Warning:
Expecting numeric in A6 / R6C1: got a date
Warning:
Expecting numeric in A7 / R7C1: got 'cabbage'

10 changes: 6 additions & 4 deletions tests/testthat/_snaps/col-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

Code
read_excel(test_sheet("iris-excel-xlsx.xlsx"), col_names = LETTERS[1:3])
Error <simpleError>
Sheet 1 has 5 columns (5 unskipped), but `col_names` has length 3.
Condition
Error:
! Sheet 1 has 5 columns (5 unskipped), but `col_names` has length 3.

---

Code
read_excel(test_sheet("iris-excel-xls.xls"), col_names = LETTERS[1:3])
Error <simpleError>
Sheet 1 has 5 columns (5 unskipped), but `col_names` has length 3.
Condition
Error:
! Sheet 1 has 5 columns (5 unskipped), but `col_names` has length 3.

46 changes: 29 additions & 17 deletions tests/testthat/_snaps/col-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
Code
read_excel(test_sheet("types.xlsx"), col_types = c("foo", "numeric", "text",
"bar"))
Error <simpleError>
Illegal column type: 'foo' [1], 'bar' [4]
Condition
Error:
! Illegal column type: 'foo' [1], 'bar' [4]

# request for 'blank' col type gets deprecation message and fix

Code
read_excel(test_sheet("types.xlsx"), col_types = rep_len(c("blank", "text"),
length.out = 5))
Message <simpleMessage>
Message
`col_type = "blank"` deprecated. Use "skip" instead.
Output
# A tibble: 5 x 2
Expand All @@ -27,64 +28,75 @@

Code
read_excel(test_sheet("types.xlsx"), col_types = character())
Error <simpleError>
length(col_types) > 0 is not TRUE
Condition
Error in `check_col_types()`:
! length(col_types) > 0 is not TRUE

---

Code
read_excel(test_sheet("types.xlsx"), col_types = 1:3)
Error <simpleError>
is.character(col_types) is not TRUE
Condition
Error in `check_col_types()`:
! is.character(col_types) is not TRUE

---

Code
read_excel(test_sheet("types.xlsx"), col_types = c(NA, "text", "numeric"))
Error <simpleError>
!anyNA(col_types) is not TRUE
Condition
Error in `check_col_types()`:
! !anyNA(col_types) is not TRUE

# guess_max is honored for col_types

Code
types <- read_excel(test_sheet("types.xlsx"), sheet = "guess_max", guess_max = 2)
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in A4 / R4C1: got 'ab'

---

Code
types <- read_excel(test_sheet("types.xls"), sheet = "guess_max", guess_max = 2)
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in A4 / R4C1: got 'ab'

# wrong length col types generates error

Code
read_excel(test_sheet("iris-excel-xlsx.xlsx"), col_types = c("numeric", "text"))
Error <simpleError>
Sheet 1 has 5 columns, but `col_types` has length 2.
Condition
Error:
! Sheet 1 has 5 columns, but `col_types` has length 2.

---

Code
read_excel(test_sheet("iris-excel-xls.xls"), col_types = c("numeric", "text"))
Error <simpleError>
Sheet 1 has 5 columns, but `col_types` has length 2.
Condition
Error:
! Sheet 1 has 5 columns, but `col_types` has length 2.

# numeric is correctly coerced to logical [xlsx]

Code
df <- read_xlsx(test_sheet("missing-values-xlsx.xlsx"), guess_max = 0)
Warning <simpleWarning>
Condition
Warning:
Expecting logical in A2 / R2C1: got 'NA'
Warning:
Expecting logical in B2 / R2C2: got 'NA'

# numeric is correctly coerced to logical [xls]

Code
df <- read_xls(test_sheet("missing-values-xls.xls"), guess_max = 0)
Warning <simpleWarning>
Condition
Warning:
Expecting logical in A2 / R2C1: got 'NA'
Warning:
Expecting logical in B2 / R2C2: got 'NA'

6 changes: 4 additions & 2 deletions tests/testthat/_snaps/dates.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
Code
df <- read_excel(test_sheet("dates-leap-year-1900-xlsx.xlsx"), col_types = c(
"date", "text", "logical"))
Warning <simpleWarning>
Condition
Warning in `read_fun()`:
NA inserted for impossible 1900-02-29 datetime

# we get correct dates prior to March 1, 1900, in 1900 date system [xls]

Code
df <- read_excel(test_sheet("dates-leap-year-1900-xls.xls"), col_types = c(
"date", "text", "logical"))
Warning <simpleWarning>
Condition
Warning in `read_fun()`:
NA inserted for impossible 1900-02-29 datetime

15 changes: 10 additions & 5 deletions tests/testthat/_snaps/problems.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Code
read_excel(test_sheet("geometry.xlsx"), sheet = "warning_B6", col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in B6 / R6C2: got 'wtf'
Output
# A tibble: 3 x 1
Expand All @@ -16,7 +17,8 @@

Code
read_excel(test_sheet("geometry.xlsx"), sheet = "warning_AT6", col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in AT6 / R6C46: got 'wtf'
Output
# A tibble: 3 x 1
Expand All @@ -30,7 +32,8 @@

Code
read_excel(test_sheet("geometry.xlsx"), sheet = "warning_AKE6", col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in AKE6 / R6C967: got 'wtf'
Output
# A tibble: 3 x 1
Expand All @@ -44,7 +47,8 @@

Code
read_excel(test_sheet("geometry.xls"), sheet = "warning_B6", col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in B6 / R6C2: got 'wtf'
Output
# A tibble: 3 x 1
Expand All @@ -58,7 +62,8 @@

Code
read_excel(test_sheet("geometry.xls"), sheet = "warning_AT6", col_types = "numeric")
Warning <simpleWarning>
Condition
Warning:
Expecting numeric in AT6 / R6C46: got 'wtf'
Output
# A tibble: 3 x 1
Expand Down

0 comments on commit 00042d6

Please sign in to comment.