From 41c8b8052237076847c2912e70a2bc19c16dc48b Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 10 Mar 2023 08:09:56 -0800 Subject: [PATCH] Scrub a filepath from this snapshot --- tests/testthat/_snaps/read-excel.new.md | 100 ++++++++++++++++++++++++ tests/testthat/test-read-excel.R | 7 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/read-excel.new.md diff --git a/tests/testthat/_snaps/read-excel.new.md b/tests/testthat/_snaps/read-excel.new.md new file mode 100644 index 00000000..da76fde7 --- /dev/null +++ b/tests/testthat/_snaps/read-excel.new.md @@ -0,0 +1,100 @@ +# xlsx is not read as xls and vice versa + + Code + read_xls(test_sheet("iris-excel-xlsx.xlsx")) + Error + + filepath: /Users/jenny/rrr/readxl/tests/testthat/sheets/iris-excel-xlsx.xlsx + libxls error: Unable to open file + +--- + + Code + read_xlsx(test_sheet("iris-excel-xls.xls")) + Error + zip file 'VOLATILE_FILEPATH' cannot be opened + +# non-existent file throws error + + Code + read_excel("foo") + Error + `path` does not exist: 'foo' + +# read_excel catches invalid guess_max + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), guess_max = NA) + Error + `guess_max` must be a positive integer + +--- + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), guess_max = -1) + Error + `guess_max` must be a positive integer + +--- + + Code + out <- read_excel(test_sheet("iris-excel-xlsx.xlsx"), guess_max = Inf) + Warning + `guess_max` is a very large value, setting to `21474836` to avoid exhausting memory + +--- + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), guess_max = NULL) + Error + `guess_max` must be a positive integer + +--- + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), guess_max = 1:2) + Error + `guess_max` must be a positive integer + +# read_excel catches invalid n_max + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), n_max = NA) + Error + `n_max` must be a positive integer + +--- + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), n_max = -1) + Error + `n_max` must be a positive integer + +--- + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), n_max = NULL) + Error + `n_max` must be a positive integer + +--- + + Code + read_excel(test_sheet("iris-excel-xlsx.xlsx"), n_max = 1:2) + Error + `n_max` must be a positive integer + +# sheet must be integer or string + + Code + read_excel(test_sheet("mtcars.xls"), sheet = TRUE) + Error + `sheet` must be either an integer or a string. + +# trim_ws must be a logical + + Code + read_excel(test_sheet("mtcars.xls"), trim_ws = "yes") + Error + `trim_ws` must be either TRUE or FALSE + diff --git a/tests/testthat/test-read-excel.R b/tests/testthat/test-read-excel.R index b8b9ca96..47ab2781 100644 --- a/tests/testthat/test-read-excel.R +++ b/tests/testthat/test-read-excel.R @@ -16,13 +16,18 @@ test_that("can read files with and without extension [xls]", { }) test_that("xlsx is not read as xls and vice versa", { + scrubfun <- function(x) { + sub("'.*iris-excel-xlsx?.xlsx?'", "'VOLATILE_FILEPATH'", x) + } expect_snapshot( error = TRUE, - read_xls(test_sheet("iris-excel-xlsx.xlsx")) + read_xls(test_sheet("iris-excel-xlsx.xlsx")), + transform = scrubfun ) expect_snapshot( error = TRUE, read_xlsx(test_sheet("iris-excel-xls.xls")), + transform = scrubfun ) })