Skip to content

Commit b10569f

Browse files
committed
Add an additional test of covidcast_signal
Fetching multiple days is important.
1 parent 60f6cc7 commit b10569f

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
@@ -105,6 +105,49 @@ with_mock_api({
105105
)
106106
})
107107

108+
test_that("covidcast_signal works across multiple days with gaps", {
109+
# If we request 3 days, we'll get 3 API queries. If the middle day is
110+
# missing, we should get an appropriate warning, but still get the right
111+
# data frame.
112+
113+
# day 1: api.php-32641f.csv
114+
# day 2: api.php-b85d44.csv (empty)
115+
# day 3: api.php-f49e8f.csv
116+
expect_warning(covidcast_signal("foo", "bar", "2020-01-10", "2020-01-12",
117+
geo_type = "county"),
118+
class = "covidcast_fetch_failed")
119+
120+
res <- suppressWarnings(
121+
covidcast_signal("foo", "bar", "2020-01-10", "2020-01-12",
122+
geo_type = "county"))
123+
expect_equal(
124+
res,
125+
structure(data.frame(
126+
data_source = "foo",
127+
signal = "bar",
128+
geo_value = c("01001", "01002", "31001", "31002"),
129+
time_value = as.Date(c("2020-01-10", "2020-01-10",
130+
"2020-01-12", "2020-01-12")),
131+
issue = as.Date(c("2020-01-11", "2020-01-11",
132+
"2020-01-13", "2020-01-13")),
133+
lag = 1,
134+
value = c(91.2, 99.1, 81.2, 89.1),
135+
stderr = c(0.8, 0.2, 0.8, 0.2),
136+
sample_size = c(114.2, 217.8, 314.2, 417.8)),
137+
class = c("covidcast_signal", "data.frame"),
138+
metadata = structure(data.frame(
139+
data_source = "foo",
140+
signal = "bar",
141+
time_type = "day",
142+
geo_type = "county",
143+
min_time = as.Date("2020-01-01"),
144+
max_time = as.Date("2020-01-02"),
145+
min_value = 0,
146+
max_value = 10,
147+
max_issue = as.Date("2020-04-04")),
148+
class = c("covidcast_meta", "data.frame"))))
149+
})
150+
108151
test_that("covidcast_signal stops when end_day < start_day", {
109152
# reusing api.php-d2e163.json for metadata
110153
expect_error(covidcast_signal("foo", "bar", "2020-01-02", "2020-01-01"))

0 commit comments

Comments
 (0)