Skip to content

Commit f2009d2

Browse files
Merge pull request #774 from dblodgett-usgs/nldi-tweak
don't assume order of nldi sources -- turn nldi tests back on but off in CI
2 parents 1777a19 + 98b6b70 commit f2009d2

File tree

2 files changed

+174
-162
lines changed

2 files changed

+174
-162
lines changed

R/findNLDI.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ valid_ask <- function(all, type) {
211211

212212
### WOW! This is hacky and will hopefully be unneeded latter on....
213213
type <- ifelse(type == "nwis", "nwissite", type)
214-
all <- rbind(all, c("flowlines", "NHDPlus comid", NA))
214+
all <- rbind(all,
215+
data.frame(source = "flowlines", sourceName = "NHDPlus comid", features = NA))
215216

216217
good <- grepl(
217218
paste0(tolower(type), collapse = "|"),

tests/testthat/tests_nldi.R

Lines changed: 172 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,172 @@
1-
# context("NLDI...")
2-
#
3-
# test_that("NLDI messageing NULL", {
4-
# skip_on_cran()
5-
# xx <- findNLDI(
6-
# wqp = "TCEQMAIN-10016",
7-
# nav = "UM",
8-
# find = "nwissite",
9-
# distance_km = 2,
10-
# warn = FALSE
11-
# )
12-
#
13-
# expect_warning(findNLDI(
14-
# wqp = "TCEQMAIN-10016",
15-
# nav = "UM",
16-
# find = "nwissite",
17-
# distance_km = 2,
18-
# warn = TRUE
19-
# ))
20-
#
21-
# expect_true(class(xx) == "list")
22-
# expect_true(nrow(xx[[1]]) == 1)
23-
# })
24-
#
25-
#
26-
# test_that("NLDI offerings...", {
27-
# skip_on_cran()
28-
# expect_true(nrow(get_nldi_sources()) > 1)
29-
# })
30-
#
31-
#
32-
#
33-
#
34-
#
35-
# test_that("NLDI starting sources...", {
36-
# skip_on_cran()
37-
#
38-
# # LINESTRING GEOMETERY
39-
# expect_equal(sum(names(findNLDI(comid = 101, warn = FALSE)$origin) %in%
40-
# c("sourceName", "identifier", "comid", "geometry")), 4)
41-
# # POINT GEOMETERY
42-
# expect_true(all(names(findNLDI(nwis = "11120000", warn = FALSE)$origin) %in%
43-
# c(
44-
# "sourceName", "identifier", "comid",
45-
# "name", "reachcode", "measure",
46-
# "X", "Y", "geometry"
47-
# )))
48-
# # COMID
49-
# expect_equal(findNLDI(comid = 101, warn = FALSE)$origin$sourceName, "NHDPlus comid")
50-
# # NWIS
51-
# expect_equal(findNLDI(nwis = "11120000", warn = FALSE)$origin$sourceName, "NWIS Surface Water Sites")
52-
# # WQP
53-
# expect_equal(findNLDI(wqp = "USGS-04024315", warn = FALSE)$origin$sourceName, "Water Quality Portal")
54-
# expect_equal(findNLDI(wqp = "CCU_EQL-2 H9", warn = FALSE)$origin$sourceName, "Water Quality Portal")
55-
# # LOCATION
56-
# expect_equal(findNLDI(location = c(-115, 40), warn = FALSE)$origin$sourceName, "NHDPlus comid")
57-
# # ERROR: LOCATION COORDINATES FLIPPED
58-
# expect_error(findNLDI(location = c(40, -115), warn = FALSE))
59-
# # GENERAL START: STABLE
60-
# expect_equal(findNLDI(origin = list("comid" = 101), warn = FALSE)$origin$sourceName, "NHDPlus comid")
61-
# # GENERAL START: NON-STABLE
62-
# expect_equal(findNLDI(origin = list("nwissite" = "USGS-05427850"), warn = FALSE)$origin$sourceName, "NWIS Surface Water Sites")
63-
# # ERROR: TWO STARTS
64-
# expect_error(findNLDI(nwis = 1000, comid = 101, warn = FALSE))
65-
# # NON EXISTING SITE
66-
# expect_error(findNLDI(comid = 1, warn = FALSE))
67-
# })
68-
#
69-
# test_that("NLDI navigation sources...", {
70-
# skip_on_cran()
71-
#
72-
# # UPPER TRIBUTARY
73-
# expect_equal(length(findNLDI(nwis = "11120000", nav = "UT", warn = FALSE)$UT_flowlines), 2)
74-
# # UPPER MAIN
75-
# expect_equal(length(findNLDI(nwis = "11120000", nav = "UM", warn = FALSE)$UM_flowlines), 2)
76-
# # DOWNSTREAM MAIN
77-
# expect_equal(length(findNLDI(nwis = "11120000", nav = "DM", warn = FALSE)$DM_flowlines), 2)
78-
# # MULTI-REQUEST
79-
# expect_equal(length(findNLDI(nwis = "11120000", nav = c("UT", "UM"), warn = FALSE)), 3)
80-
# # ERRORS: Bad NAV REQUEST
81-
# expect_error(findNLDI(nwis = "11120000", nav = c("DT"), warn = FALSE))
82-
# expect_error(findNLDI(nwis = "11120000", nav = c("DT", "UM"), warn = FALSE))
83-
# # WARNING: Data not found
84-
# expect_error(findNLDI(comid = 101, nav = "UM", find = "nwis", warn = TRUE))
85-
# })
86-
#
87-
# test_that("NLDI find sources...", {
88-
# skip_on_cran()
89-
#
90-
# expect_equal(length(findNLDI(nwis = "11120000", nav = "UT", find = "wade", warn = FALSE)), 2)
91-
# # expect_equal(length(findNLDI(nwis = "11120000", nav = c("UT", "UM"), find = c("nwis", "wade", "flowlines"), warn = FALSE)), 7)
92-
# })
93-
#
94-
# test_that("sf not installed...", {
95-
# skip_on_cran()
96-
#
97-
# expect_true(!"geometry" %in% findNLDI(nwis = "11120000", no_sf = TRUE, warn = FALSE)[[1]])
98-
# expect_equal(class(findNLDI(nwis = "11120000", nav = "UT", find = c("nwis"), no_sf = TRUE, warn = FALSE)[[2]]), "data.frame")
99-
# expect_true(c("X") %in% names(findNLDI(nwis = "11120000", nav = "UT", find = c("nwis"), no_sf = TRUE, warn = FALSE)[[2]]))
100-
# })
101-
#
102-
#
103-
# test_that("Distance...", {
104-
# skip_on_cran()
105-
#
106-
# full <- findNLDI(comid = 101, nav = "UT", find = "nwis", distance_km = 9999, warn = FALSE)
107-
# part <- findNLDI(comid = 101, nav = "UT", find = "nwis", warn = FALSE)
108-
# expect_true(nrow(full$UT_nwissite) > nrow(part$UT_nwissite))
109-
# })
110-
#
111-
# test_that("basin", {
112-
# skip_on_cran()
113-
#
114-
# xx <- findNLDI(comid = 101, nav = "UT", find = "basin", warn = FALSE)
115-
# xx2 <- findNLDI(comid = 101, nav = "UT", find = "basin", no_sf = TRUE , warn = FALSE)
116-
# expect_true(sf::st_geometry_type(xx$basin) == "POLYGON")
117-
# expect_equal(ncol(xx2$basin), 0)
118-
# })
119-
#
120-
#
121-
# test_that("ignore flowlines", {
122-
# skip_on_cran()
123-
#
124-
# xx <- findNLDI(comid = 101, nav = "DM", find = c("nwis", "flowlines"), warn = FALSE)
125-
# xx2 <- findNLDI(comid = 101, nav = "DM", find = "nwis", warn = FALSE)
126-
# expect_gt(length(xx), length(xx2))
127-
# expect_true("DM_flowlines" %in% names(xx))
128-
# expect_true(!"DM_flowlines" %in% names(xx2))
129-
# })
130-
#
131-
#
132-
# test_that("sf points", {
133-
# skip_on_cran()
134-
# library(sf)
135-
# p2 <- st_sfc(st_point(c(-119.8458, 34.4146)), crs = 4326)
136-
# expect_equal(findNLDI(location = p2, warn = FALSE), findNLDI(location = sf::st_as_sf(p2)))
137-
# expect_error(findNLDI(location = st_buffer(p2, .01), warn = FALSE))
138-
# })
139-
#
140-
#
141-
# test_that("warn_flag", {
142-
#
143-
# expect_warning(
144-
# findNLDI(wqp = "TCEQMAIN-10016",
145-
# nav = "UM",
146-
# find = "nwissite",
147-
# distance_km = 2,
148-
# no_sf = TRUE,
149-
# warn = FALSE),
150-
# regexp = NA
151-
# )
152-
#
153-
# expect_warning(
154-
# findNLDI(wqp = "TCEQMAIN-10016",
155-
# nav = "UM",
156-
# find = "nwissite",
157-
# distance_km = 2,
158-
# no_sf = TRUE,
159-
# warn = TRUE)
160-
# )
161-
# })
1+
context("NLDI...")
2+
3+
test_that("NLDI messageing NULL", {
4+
skip_on_cran()
5+
skip_on_ci()
6+
xx <- findNLDI(
7+
wqp = "TCEQMAIN-10016",
8+
nav = "UM",
9+
find = "nwissite",
10+
distance_km = 2,
11+
warn = FALSE
12+
)
13+
14+
expect_warning(findNLDI(
15+
wqp = "TCEQMAIN-10016",
16+
nav = "UM",
17+
find = "nwissite",
18+
distance_km = 2,
19+
warn = TRUE
20+
))
21+
22+
expect_true(class(xx) == "list")
23+
expect_true(nrow(xx[[1]]) == 1)
24+
})
25+
26+
27+
test_that("NLDI offerings...", {
28+
skip_on_cran()
29+
expect_true(nrow(get_nldi_sources()) > 1)
30+
})
31+
32+
33+
34+
35+
36+
test_that("NLDI starting sources...", {
37+
skip_on_cran()
38+
skip_on_ci()
39+
40+
# LINESTRING GEOMETERY
41+
expect_equal(sum(names(findNLDI(comid = 101, warn = FALSE)$origin) %in%
42+
c("sourceName", "identifier", "comid", "geometry")), 4)
43+
# POINT GEOMETERY
44+
expect_true(all(names(findNLDI(nwis = "11120000", warn = FALSE)$origin) %in%
45+
c(
46+
"sourceName", "identifier", "comid",
47+
"name", "reachcode", "measure",
48+
"X", "Y", "geometry"
49+
)))
50+
# COMID
51+
expect_equal(findNLDI(comid = 101, warn = FALSE)$origin$sourceName, "NHDPlus comid")
52+
# NWIS
53+
expect_equal(findNLDI(nwis = "11120000", warn = FALSE)$origin$sourceName, "NWIS Surface Water Sites")
54+
# WQP
55+
expect_equal(findNLDI(wqp = "USGS-04024315", warn = FALSE)$origin$sourceName, "Water Quality Portal")
56+
expect_equal(findNLDI(wqp = "CCU_EQL-2 H9", warn = FALSE)$origin$sourceName, "Water Quality Portal")
57+
# LOCATION
58+
expect_equal(findNLDI(location = c(-115, 40), warn = FALSE)$origin$sourceName, "NHDPlus comid")
59+
# ERROR: LOCATION COORDINATES FLIPPED
60+
expect_error(findNLDI(location = c(40, -115), warn = FALSE))
61+
# GENERAL START: STABLE
62+
expect_equal(findNLDI(origin = list("comid" = 101), warn = FALSE)$origin$sourceName, "NHDPlus comid")
63+
# GENERAL START: NON-STABLE
64+
expect_equal(findNLDI(origin = list("nwissite" = "USGS-05427850"), warn = FALSE)$origin$sourceName, "NWIS Surface Water Sites")
65+
# ERROR: TWO STARTS
66+
expect_error(findNLDI(nwis = 1000, comid = 101, warn = FALSE))
67+
# NON EXISTING SITE
68+
expect_message(findNLDI(comid = 1, warn = FALSE))
69+
})
70+
71+
test_that("NLDI navigation sources...", {
72+
skip_on_cran()
73+
skip_on_ci()
74+
75+
# UPPER TRIBUTARY
76+
expect_equal(length(findNLDI(nwis = "11120000", nav = "UT", warn = FALSE)$UT_flowlines), 2)
77+
# UPPER MAIN
78+
expect_equal(length(findNLDI(nwis = "11120000", nav = "UM", warn = FALSE)$UM_flowlines), 2)
79+
# DOWNSTREAM MAIN
80+
expect_equal(length(findNLDI(nwis = "11120000", nav = "DM", warn = FALSE)$DM_flowlines), 2)
81+
# MULTI-REQUEST
82+
expect_equal(length(findNLDI(nwis = "11120000", nav = c("UT", "UM"), warn = FALSE)), 3)
83+
# ERRORS: Bad NAV REQUEST
84+
expect_error(findNLDI(nwis = "11120000", nav = c("DT"), warn = FALSE))
85+
expect_error(findNLDI(nwis = "11120000", nav = c("DT", "UM"), warn = FALSE))
86+
# WARNING: Data not found
87+
expect_warning(findNLDI(comid = 101, nav = "UM", find = "nwis", warn = TRUE))
88+
})
89+
90+
test_that("NLDI find sources...", {
91+
skip_on_cran()
92+
skip_on_ci()
93+
94+
expect_equal(length(findNLDI(nwis = "11120000", nav = "UT", distance_km = 999, find = "nwis", warn = FALSE)), 2)
95+
# expect_equal(length(findNLDI(nwis = "11120000", nav = c("UT", "UM"), find = c("nwis", "wade", "flowlines"), warn = FALSE)), 7)
96+
})
97+
98+
test_that("sf not installed...", {
99+
skip_on_cran()
100+
skip_on_ci()
101+
102+
expect_true(!"geometry" %in% findNLDI(nwis = "11120000", no_sf = TRUE, warn = FALSE)[[1]])
103+
expect_equal(class(findNLDI(nwis = "11120000", nav = "UT", find = c("nwis"), no_sf = TRUE, warn = FALSE)[[2]]), "data.frame")
104+
expect_true(c("X") %in% names(findNLDI(nwis = "11120000", nav = "UT", find = c("nwis"), no_sf = TRUE, warn = FALSE)[[2]]))
105+
})
106+
107+
108+
test_that("Distance...", {
109+
skip_on_cran()
110+
skip_on_ci()
111+
112+
full <- findNLDI(comid = 17595429, nav = "UT", find = "nwis", distance_km = 999, warn = FALSE)
113+
part <- findNLDI(comid = 17595429, nav = "UT", find = "nwis", distance_km = 2, warn = FALSE)
114+
expect_true(nrow(full$UT_nwissite) > nrow(part$UT_nwissite))
115+
})
116+
117+
test_that("basin", {
118+
skip_on_cran()
119+
skip_on_ci()
120+
121+
xx <- findNLDI(comid = 101, nav = "UT", find = "basin", warn = FALSE)
122+
xx2 <- findNLDI(comid = 101, nav = "UT", find = "basin", no_sf = TRUE , warn = FALSE)
123+
expect_true(sf::st_geometry_type(xx$basin) == "POLYGON")
124+
expect_equal(ncol(xx2$basin), 0)
125+
})
126+
127+
128+
test_that("ignore flowlines", {
129+
skip_on_cran()
130+
skip_on_ci()
131+
132+
xx <- findNLDI(comid = 101, nav = "DM", find = c("nwis", "flowlines"), warn = FALSE)
133+
xx2 <- findNLDI(comid = 101, nav = "DM", find = "nwis", warn = FALSE)
134+
expect_gt(length(xx), length(xx2))
135+
expect_true("DM_flowlines" %in% names(xx))
136+
expect_true(!"DM_flowlines" %in% names(xx2))
137+
})
138+
139+
140+
test_that("sf points", {
141+
skip_on_cran()
142+
skip_on_ci()
143+
library(sf)
144+
p2 <- st_sfc(st_point(c(-119.8458, 34.4146)), crs = 4326)
145+
expect_equal(findNLDI(location = p2, warn = FALSE), findNLDI(location = sf::st_as_sf(p2)))
146+
expect_error(findNLDI(location = st_buffer(p2, .01), warn = FALSE))
147+
})
148+
149+
150+
test_that("warn_flag", {
151+
skip_on_ci()
152+
skip_on_cran()
153+
154+
expect_warning(
155+
findNLDI(wqp = "TCEQMAIN-10016",
156+
nav = "UM",
157+
find = "nwissite",
158+
distance_km = 2,
159+
no_sf = TRUE,
160+
warn = FALSE),
161+
regexp = NA
162+
)
163+
164+
expect_warning(
165+
findNLDI(wqp = "TCEQMAIN-10016",
166+
nav = "UM",
167+
find = "nwissite",
168+
distance_km = 2,
169+
no_sf = TRUE,
170+
warn = TRUE)
171+
)
172+
})

0 commit comments

Comments
 (0)