11# -*- coding: utf-8 -*-
22import logging
33from pathlib import Path
4+ import re
45
56import copy
67import pytest
2728# end as open_covid_region_code,
2829# *
2930# from `bigquery-public-data.covid19_symptom_search.states_daily_2020` # States by day
30- # where timestamp(date) between timestamp("2020-07-26 ") and timestamp("2020-08-11 ")
31+ # where timestamp(date) between timestamp("2020-07-15 ") and timestamp("2020-08-22 ")
3132
3233# County data is created by running the following query in the BigQuery
3334# browser console:
3839# end as open_covid_region_code,
3940# *
4041# from `bigquery-public-data.covid19_symptom_search.counties_daily_2020` # Counties by day; includes state and county name, + FIPS code
41- # where timestamp(date) between timestamp("2020-07-26") and timestamp("2020-08-11")
42+ # where timestamp(date) between timestamp("2020-07-15") and timestamp("2020-08-22")
43+
4244
4345good_input = {
44- "state" : f"{ TEST_DIR } /test_data/small_states_daily .csv" ,
45- "county" : f"{ TEST_DIR } /test_data/small_counties_daily .csv"
46+ "state" : f"{ TEST_DIR } /test_data/small_states_2020_07_15_2020_08_22 .csv" ,
47+ "county" : f"{ TEST_DIR } /test_data/small_counties_2020_07_15_2020_08_22 .csv"
4648}
4749
4850patch_input = {
4951 "state" : f"{ TEST_DIR } /test_data/state_2024-05-16_2024-07-18.csv" ,
50- "county" : f"{ TEST_DIR } /test_data/county_2024-05-16_2024-07-18.csv"
51-
5252}
5353
5454symptom_names = ["symptom_" +
@@ -79,9 +79,9 @@ def params():
7979 "log_filename" : f"{ TEST_DIR } /test.log" ,
8080 },
8181 "indicator" : {
82- "export_start_date" : "2020-02-20" ,
8382 "bigquery_credentials" : {},
8483 "num_export_days" : 14 ,
84+ "custom_run" : False ,
8585 "static_file_dir" : "../static" ,
8686 "api_credentials" : "fakesecret"
8787 },
@@ -124,7 +124,22 @@ def run_as_module(params):
124124
125125 with mock .patch ("delphi_google_symptoms.pull.initialize_credentials" ,
126126 return_value = None ), \
127- mock .patch ("pandas_gbq.read_gbq" , side_effect = [ state_data , county_data ]) , \
127+ mock .patch ("pandas_gbq.read_gbq" ) as mock_read_gbq , \
128128 mock .patch ("delphi_google_symptoms.pull.initialize_credentials" , return_value = None ), \
129129 mock .patch ("delphi_google_symptoms.date_utils.covidcast.metadata" , return_value = covidcast_metadata ):
130- delphi_google_symptoms .run .run_module (params )
130+ def side_effect (* args , ** kwargs ):
131+ if "symptom_search_sub_region_1_daily" in args [0 ]:
132+ df = state_data
133+ pattern = re .compile (r'\d{4}-\d{2}-\d{2}' )
134+ start_date , end_date = re .findall (pattern , args [0 ])
135+ return df [(df ["date" ] >= start_date ) & (df ["date" ] <= end_date )]
136+ elif "symptom_search_sub_region_2_daily" in args [0 ]:
137+ df = county_data
138+ pattern = re .compile (r'\d{4}-\d{2}-\d{2}' )
139+ start_date , end_date = re .findall (pattern , args [0 ])
140+ return df [(df ["date" ] >= start_date ) & (df ["date" ] <= end_date )]
141+ else :
142+ return pd .DataFrame ()
143+
144+ mock_read_gbq .side_effect = side_effect
145+ delphi_google_symptoms .run .run_module (params )
0 commit comments