Skip to content

Commit

Permalink
Fixes #71; use snapshot tests for selection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
robe2037 committed Mar 11, 2024
1 parent 4669513 commit 8036f7e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -53,7 +53,7 @@ Suggests:
scales,
sf,
shiny,
testthat,
testthat (>= 3.0.0),
tidyr,
vcr (>= 0.6.0),
withr
Expand All @@ -63,3 +63,4 @@ Contact: ipums@umn.edu
Encoding: UTF-8
Roxygen: list(markdown = TRUE, r6 = FALSE)
RoxygenNote: 7.2.3
Config/testthat/edition: 2
10 changes: 9 additions & 1 deletion tests/testthat.R
@@ -1,4 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(ipumsr)

test_check("ipumsr", reporter = "location")
test_check("ipumsr")
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/nhgis.md
@@ -0,0 +1,13 @@
# We get informative error messages when reading NHGIS extracts

Code
read_nhgis(nhgis_multi_ds, file_select = 3, verbose = FALSE)
Condition
Error in `find_files_in()`:
! Can't select files past the end.
ℹ Location 3 doesn't exist.
ℹ There are only 2 files.
Available files:
• nhgis0731_csv/nhgis0731_ds239_20185_nation.csv
• nhgis0731_csv/nhgis0731_ts_nominal_state.csv

14 changes: 14 additions & 0 deletions tests/testthat/_snaps/shape_read.md
@@ -0,0 +1,14 @@
# We get informative errors when reading shapefiles

Code
read_ipums_sf(nhgis_multi_shp, file_select = 4)
Condition
Error in `find_files_in()`:
! Can't select files past the end.
ℹ Location 4 doesn't exist.
ℹ There are only 3 files.
Available files:
• nhgis0712_shape/nhgis0712_shapefile_cenpop2000_us_state_cenpop_2000.zip
• nhgis0712_shape/nhgis0712_shapefile_tl2000_us_pmsa_1990.zip
• nhgis0712_shape/nhgis0712_shapefile_tl2000_us_pmsa_2000.zip

6 changes: 3 additions & 3 deletions tests/testthat/test_nhgis.R
Expand Up @@ -315,6 +315,7 @@ test_that("We can specify available readr options in read_nhgis()", {
})

test_that("We get informative error messages when reading NHGIS extracts", {
testthat::local_edition(3)
expect_error(
read_nhgis("FAKE_FILE.zip", verbose = FALSE),
"Could not find file"
Expand Down Expand Up @@ -345,10 +346,9 @@ test_that("We get informative error messages when reading NHGIS extracts", {
),
"Multiple files found, please use the `file_select`"
)

expect_error(
expect_snapshot(
read_nhgis(nhgis_multi_ds, file_select = 3, verbose = FALSE),
"Can't subset files past the end.+Available files:"
error = TRUE
)
expect_error(
read_nhgis(
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test_shape_read.R
Expand Up @@ -87,6 +87,7 @@ test_that("Can read extract at multiple file levels", {

test_that("We get informative errors when reading shapefiles", {
skip_if_not_installed("sf")
testthat::local_edition(3)

nhgis_multi_shp <- ipums_example("nhgis0712_shape_small.zip")

Expand All @@ -96,9 +97,9 @@ test_that("We get informative errors when reading shapefiles", {
"Multiple files found.+To combine files"
)

expect_error(
expect_snapshot(
read_ipums_sf(nhgis_multi_shp, file_select = 4),
"Can't subset files past the end.+Available files:"
error = TRUE
)

expect_warning(
Expand Down

0 comments on commit 8036f7e

Please sign in to comment.