Skip to content

Commit

Permalink
Merge pull request #105 from Public-Health-Scotland/tests/fix_file_size
Browse files Browse the repository at this point in the history
Fix the file size test
  • Loading branch information
Tina815 authored Sep 12, 2023
2 parents 9c36397 + 6bf3701 commit fd51540
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Imports:
utils
Suggests:
covr,
here,
spelling,
testthat (>= 3.0.0)
RdMacros:
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions tests/testthat/_snaps/windows/file_size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Output is identical over time

Code
file_size(test_path("files"))
Output
# A tibble: 8 x 2
name size
<chr> <chr>
1 airquality.xls Excel 26 kB
2 bod.xlsx Excel 5 kB
3 iris.csv CSV 4 kB
4 mtcars.sav SPSS 4 kB
5 plant-growth.rds RDS 316 B
6 puromycin.txt Text 442 B
7 stackloss.fst FST 897 B
8 swiss.tsv TSV 1 kB

---

Code
file_size(test_path("files"), "xlsx?")
Output
# A tibble: 2 x 2
name size
<chr> <chr>
1 airquality.xls Excel 26 kB
2 bod.xlsx Excel 5 kB

13 changes: 10 additions & 3 deletions tests/testthat/test-file_size.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ test_that("Returns sizes in alphabetical order", {
})

test_that("Output is identical over time", {
expect_snapshot(file_size(test_path("files")))
expect_snapshot(file_size(test_path("files"), "xlsx?"))
# Text files report as larger on Windows so snapshot per OS
os <- ifelse(
"windows" %in% tolower(Sys.info()[["sysname"]]),
"windows",
"UNIX"
)

expect_snapshot(file_size(test_path("files")), variant = os)
expect_snapshot(file_size(test_path("files"), "xlsx?"), variant = os)
})

test_that("Errors if supplied with invalid filepath", {
expect_error(file_size(here::here("reference_files")))
expect_error(file_size(test_path("reference_files")))
expect_error(file_size(NA))
expect_error(file_size(NULL))
})
Expand Down

0 comments on commit fd51540

Please sign in to comment.