Skip to content

Commit

Permalink
Merge pull request #282 from inbo/inherit-parsing-issues
Browse files Browse the repository at this point in the history
Inherit parsing issues
  • Loading branch information
PietrH authored Nov 10, 2023
2 parents cee8f65 + 5c4b0da commit 545f72f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion R/read_camtrap_dp.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ read_camtrap_dp <- function(file = NULL,
if (lifecycle::is_present(path) | (!is.null(file) && dir.exists(file))) {
lifecycle::deprecate_warn(
when = "0.6.0",
what = "read_camtrap_dp(path)",
what = "camtraptor::read_camtrap_dp(path)",
details = warning_detail
)
}
Expand Down Expand Up @@ -165,7 +165,11 @@ read_camtrap_dp <- function(file = NULL,
check_package(package, media = media)

# Inherit parsing issues from reading
attr(package$data$deployments, which = "problems") <- issues_deployments
attr(package$data$observations, which = "problems") <- issues_observations
if (media) {
attr(package$data$media, which = "problems") <- issues_media
}

return(package)
}
28 changes: 24 additions & 4 deletions tests/testthat/test-read_camtrap_dp.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,58 @@ test_that("test warnings while reading files with parsing issues", {
"datapackage_for_parsing_issues.json",
package = "camtraptor"
)
w <- capture_warnings(
captured_warnings <- capture_warnings(
dp_issues <- camtraptor::read_camtrap_dp(file = camtrap_dp_file_with_issues)
)

# check number of warnings
expect_length(captured_warnings, 6)

# warning on deployments
expect_identical(
w[2], # w[1] is returned by readr via frictionless
captured_warnings[2], # captured_warnings[1] is returned by readr via frictionless
paste0(
"One or more parsing issues occurred while reading `deployments`. ",
"Check `?read_camtrap_dp()` for examples on how to use ",
"`readr::problems()`."
)
)

problems_deploys <- readr::problems(dp_issues$data$deployments)
expect_identical(nrow(problems_deploys), 2L)
expect_identical(problems_deploys$row, c(1L,2L))
expect_identical(problems_deploys$col, c(7L,7L))
expect_identical(problems_deploys$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2))

# warning on observations
expect_identical(
w[4], # w[3] is returned by readr via frictionless
captured_warnings[4], # captured_warnings[3] is returned by readr via frictionless
paste0(
"One or more parsing issues occurred while reading `observations`. ",
"Check `?read_camtrap_dp()` for examples on how to use ",
"`readr::problems()`."
)
)
problems_obs <- readr::problems(dp_issues$data$observations)
expect_identical(nrow(problems_obs), 2L)
expect_identical(problems_obs$row, c(1L,2L))
expect_identical(problems_obs$col, c(5L,5L))
expect_identical(problems_obs$expected, rep("date like %Y-%m-%dT%H:%M:%S%z", 2))

# warning on media
expect_identical(
w[6], # w[5] is returned by readr via frictionless
captured_warnings[6], # captured_warnings[5] is returned by readr via frictionless
paste0(
"One or more parsing issues occurred while reading `media`. ",
"Check `?read_camtrap_dp()` for examples on how to use ",
"`readr::problems()`."
)
)
problems_media <- readr::problems(dp_issues$data$media)
expect_identical(nrow(problems_media), 1L)
expect_identical(problems_media$row, 2L)
expect_identical(problems_media$col, 5L)
expect_identical(problems_media$expected, "date like %Y-%m-%dT%H:%M:%S%z")
})

test_that("media is checked properly", {
Expand Down

0 comments on commit 545f72f

Please sign in to comment.