Skip to content

Commit cbe3345

Browse files
committed
Add an additional test of covidcast_signal
Fetching multiple days is important.
1 parent 50cc950 commit cbe3345

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
geo_value,signal,time_value,direction,issue,lag,value,stderr,sample_size
2+
01001,bar,20200110,,20200111,1,91.2,0.8,114.2
3+
01002,bar,20200110,,20200111,1,99.1,0.2,217.8

R-packages/covidcast/tests/testthat/api.covidcast.cmu.edu/epidata/api.php-b85d44.csv

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
geo_value,signal,time_value,direction,issue,lag,value,stderr,sample_size
2+
31001,bar,20200112,,20200113,1,81.2,0.8,314.2
3+
31002,bar,20200112,,20200113,1,89.1,0.2,417.8

R-packages/covidcast/tests/testthat/test-covidcast.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,49 @@ with_mock_api({
123123
)
124124
})
125125

126+
test_that("covidcast_signal works across multiple days with gaps", {
127+
# If we request 3 days, we'll get 3 API queries. If the middle day is
128+
# missing, we should get an appropriate warning, but still get the right
129+
# data frame.
130+
131+
# day 1: api.php-32641f.csv
132+
# day 2: api.php-b85d44.csv (empty)
133+
# day 3: api.php-f49e8f.csv
134+
expect_warning(covidcast_signal("foo", "bar", "2020-01-10", "2020-01-12",
135+
geo_type = "county"),
136+
class = "covidcast_fetch_failed")
137+
138+
res <- suppressWarnings(
139+
covidcast_signal("foo", "bar", "2020-01-10", "2020-01-12",
140+
geo_type = "county"))
141+
expect_equal(
142+
res,
143+
structure(data.frame(
144+
data_source = "foo",
145+
signal = "bar",
146+
geo_value = c("01001", "01002", "31001", "31002"),
147+
time_value = as.Date(c("2020-01-10", "2020-01-10",
148+
"2020-01-12", "2020-01-12")),
149+
issue = as.Date(c("2020-01-11", "2020-01-11",
150+
"2020-01-13", "2020-01-13")),
151+
lag = 1,
152+
value = c(91.2, 99.1, 81.2, 89.1),
153+
stderr = c(0.8, 0.2, 0.8, 0.2),
154+
sample_size = c(114.2, 217.8, 314.2, 417.8)),
155+
class = c("covidcast_signal", "data.frame"),
156+
metadata = structure(data.frame(
157+
data_source = "foo",
158+
signal = "bar",
159+
time_type = "day",
160+
geo_type = "county",
161+
min_time = as.Date("2020-01-01"),
162+
max_time = as.Date("2020-01-02"),
163+
min_value = 0,
164+
max_value = 10,
165+
max_issue = as.Date("2020-04-04")),
166+
class = c("covidcast_meta", "data.frame"))))
167+
})
168+
126169
test_that("covidcast_signal stops when end_day < start_day", {
127170
# reusing api.php-d2e163.json for metadata
128171
expect_error(covidcast_signal("foo", "bar", "2020-01-02", "2020-01-01"))

0 commit comments

Comments
 (0)