Skip to content

Commit 4d11aa9

Browse files
committed
Fix tests
1 parent a28e025 commit 4d11aa9

File tree

5 files changed

+27
-71
lines changed

5 files changed

+27
-71
lines changed

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Whitespace-only changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
data_source,signal,time_type,geo_type,min_time,max_time,min_value,max_value,max_issue
2-
foo,bar,day,county,20200101,20200102,0,10,20200404
3-
foo,bar,day,state,20201002,20201003,0,10,20201101
1+
data_source,signal,time_type,geo_type,min_time,max_time,min_value,max_value,num_locations,max_issue
2+
foo,bar,day,county,20200101,20200102,0,10,100,20200404
3+
foo,bar2,day,county,20201002,20201003,0,10,100,20201101

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ with_mock_api({
4646
data.frame(
4747
data_source = "foo",
4848
signal = c("bar", "bar2"),
49+
time_type = "day",
50+
geo_type = "county",
4951
min_time = as.Date(c("2020-01-01", "2020-10-02")),
5052
max_time = as.Date(c("2020-01-02", "2020-10-03")),
5153
min_value = 0,
5254
max_value = 10,
5355
num_locations = 100,
54-
time_type = "day",
55-
geo_type = c("county", "state"),
5656
max_issue = as.Date(c("2020-04-04", "2020-11-01"))
5757
),
5858
class = c("covidcast_meta", "data.frame")
@@ -123,49 +123,6 @@ 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-
169126
test_that("covidcast_signal stops when end_day < start_day", {
170127
# reusing api.php-dd024f.csv for metadata
171128
expect_error(covidcast_signal("foo", "bar", "2020-01-02", "2020-01-01"))
@@ -183,7 +140,7 @@ with_mock_api({
183140

184141
test_that("covidcast_days does not treat \"*\" as a missing geo_value", {
185142
stub(covidcast_days, "covidcast",
186-
list(message = "success", epidata = data.frame(
143+
data.frame(
187144
geo_value = c("geoa", "geob"),
188145
signal = "signal",
189146
time_value = c(20201030, 20201031),
@@ -193,7 +150,8 @@ test_that("covidcast_days does not treat \"*\" as a missing geo_value", {
193150
value = 3,
194151
stderr = NA,
195152
sample_size = NA
196-
), result = 1))
153+
))
154+
197155
# Expect no warning
198156
expect_warning(
199157
covidcast_days(
@@ -212,7 +170,7 @@ test_that("covidcast_days does not treat \"*\" as a missing geo_value", {
212170

213171
test_that("covidcast_days does not raise warnings for full response", {
214172
stub(covidcast_days, "covidcast",
215-
list(message = "success", epidata = data.frame(
173+
data.frame(
216174
geo_value = c("geoa"),
217175
signal = "signal",
218176
time_value = c(20201030, 20201031),
@@ -222,7 +180,8 @@ test_that("covidcast_days does not raise warnings for full response", {
222180
value = 3,
223181
stderr = NA,
224182
sample_size = NA
225-
), result = 1))
183+
))
184+
226185
# Expect no warning
227186
expect_warning(
228187
covidcast_days(
@@ -240,19 +199,22 @@ test_that("covidcast_days does not raise warnings for full response", {
240199
})
241200

242201
test_that("covidcast_days batches calls to covidcast", {
243-
covidcast_returns <- rep(list(list(message = "success", epidata = data.frame(
244-
geo_value = c("geoa"),
245-
signal = "signal",
246-
time_value = rep(NA, 3),
247-
direction = NA,
248-
issue = as.Date("2020-11-04"),
249-
lag = 2,
250-
value = 3,
251-
stderr = NA,
252-
sample_size = NA
253-
), result = 1)), 10)
254-
covidcast_returns[[1]]$epidata$time_value <- 20101001:20101003
255-
covidcast_returns[[2]]$epidata$time_value <- 20101004:20101006
202+
covidcast_returns <- rep(
203+
list(
204+
data.frame(
205+
geo_value = c("geoa"),
206+
signal = "signal",
207+
time_value = rep(NA, 3),
208+
direction = NA,
209+
issue = as.Date("2020-11-04"),
210+
lag = 2,
211+
value = 3,
212+
stderr = NA,
213+
sample_size = NA
214+
)),
215+
10)
216+
covidcast_returns[[1]]$time_value <- 20101001:20101003
217+
covidcast_returns[[2]]$time_value <- 20101004:20101006
256218

257219
m <- mock(covidcast_returns[[1]], covidcast_returns[[2]])
258220
stub(covidcast_days, "covidcast", m)

0 commit comments

Comments
 (0)