Skip to content

Commit

Permalink
bbox wasn't working right (again?). Adding some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Aug 23, 2024
1 parent 26b9265 commit 539e507
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/readWQPdots.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ readWQPdots <- function(..., legacy = FALSE) {

bbox <- "bBox" %in% names(matchReturn)
if(bbox){
values_bbox <- sapply(matchReturn["bBox"], function(x) as.character(paste0(eval(x), collapse = ";")))
values_bbox <- sapply(matchReturn["bBox"], function(x) as.character(paste0(eval(x), collapse = ",")))
matchReturn <- matchReturn[names(matchReturn) != "bBox"]
}

Expand Down
4 changes: 4 additions & 0 deletions R/whatWQPdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ whatWQPmetrics <- function(...,
#' siteType = "Lake, Reservoir, Impoundment",
#' countycode = "US:55:025", convertType = FALSE)
#' }
#'
#' bbox <- c(-86.9736, 34.4883, -86.6135, 34.6562)
#' what_bb <- whatWQPdata(bBox = bbox)
#'
whatWQPdata <- function(..., saveFile = tempfile(),
convertType = TRUE) {
values <- readWQPdots(..., legacy = TRUE)
Expand Down
3 changes: 3 additions & 0 deletions man/whatWQPdata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion tests/testthat/tests_general.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ test_that("readWQPdots working", {
# bbox vector turned into single string with coords separated by semicolons
formArgs_bbox <- dataRetrieval:::readWQPdots(bbox = c(-92.5, 45.4, -87, 47))
expect_true(length(formArgs_bbox) == 2)
expect_true(length(gregexpr(";", formArgs_bbox)[[1]]) == 3)
expect_true(length(gregexpr(",", formArgs_bbox)[[1]]) == 3)

# NWIS names (siteNumber) converted to WQP expected names (siteid)
formArgs_site <- dataRetrieval:::readWQPdots(siteNumber = "04010301")
Expand All @@ -368,6 +368,26 @@ test_that("readWQPdots working", {
expect_true(length(formArgs$values) == 2)
expect_true("statecode" %in% names(formArgs$values))
expect_false("stateCd" %in% names(formArgs$values))

bbox <- c(-86.97361, 34.48827, -86.61349, 34.65623)
what_bbox <- whatWQPdata(bBox = bbox)
expect_true(nrow(what_bbox) > 0)
x <- whatWQPsites(bBox = bbox)
expect_true(nrow(x) > 0)
df <- readWQPdata(bBox = bbox,
characteristicName = "Total Coliform",
startDateLo = "2023-01-01",
startDateHi = "2023-12-31",
service = "ResultWQX3",
dataProfile = "narrow")
expect_true(nrow(df) > 0)
df_legacy <- readWQPdata(bBox = bbox,
characteristicName = "Total Coliform",
startDateLo = "2023-01-01",
startDateHi = "2023-12-31",
service = "Result",
dataProfile = "narrowResult")
expect_true(nrow(df_legacy) > 0)
})


Expand Down

0 comments on commit 539e507

Please sign in to comment.