Skip to content

Commit d4782f7

Browse files
committed
patch fn takes params as an arg, like run_module
1 parent 37dfa55 commit d4782f7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

google_symptoms/delphi_google_symptoms/patch.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,28 @@
3131
from .run import run_module
3232

3333

34-
def patch():
34+
def patch(params):
3535
"""
3636
Run the google symptoms indicator for a range of issue dates.
3737
38-
The range of issue dates is specified in params.json using the following keys:
38+
Parameters
39+
----------
40+
params
41+
Dictionary containing indicator configuration. Expected to have the following structure:
42+
- "common":
43+
- "export_dir": str, directory to write output
44+
- "log_exceptions" (optional): bool, whether to log exceptions to file
45+
- "log_filename" (optional): str, name of file to write logs
46+
- "indicator":
47+
- "export_start_date": str, YYYY-MM-DD format, date from which to export data
48+
- "num_export_days": int, number of days before end date (today) to export
49+
- "path_to_bigquery_credentials": str, path to BigQuery API key and service account
50+
JSON file
3951
- "patch": Only used for patching data
4052
- "start_date": str, YYYY-MM-DD format, first issue date
4153
- "end_date": str, YYYY-MM-DD format, last issue date
4254
- "patch_dir": str, directory to write all issues output
4355
"""
44-
params = read_params()
4556
logger = get_structured_logger("delphi_google_symptom.patch", filename=params["common"]["log_filename"])
4657

4758
issue_date = datetime.strptime(params["patch"]["start_issue"], "%Y-%m-%d")
@@ -71,4 +82,4 @@ def patch():
7182

7283

7384
if __name__ == "__main__":
74-
patch()
85+
patch(read_params())

google_symptoms/tests/test_patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def generate_expected_dates(self, params_, smoother, issue_date):
4646
num_export_days = (export_end_date - export_start_date).days + 1
4747

4848
return sorted([export_start_date + timedelta(days=x) for x in range(num_export_days)])
49-
def mocked_patch(self, params_):
5049

50+
def mocked_patch(self, params_):
5151
with mock_patch("delphi_google_symptoms.patch.read_params", return_value=params_), \
5252
mock_patch("delphi_google_symptoms.pull.pandas_gbq.read_gbq") as mock_read_gbq, \
5353
mock_patch("delphi_google_symptoms.pull.initialize_credentials", return_value=None), \
@@ -67,7 +67,7 @@ def side_effect(*args, **kwargs):
6767
mock_read_gbq.side_effect = side_effect
6868
start_date = datetime.strptime(params_["patch"]["start_issue"], "%Y-%m-%d")
6969

70-
patch()
70+
patch(params_)
7171

7272
patch_path = Path(f"{TEST_DIR}/{params_['patch']['patch_dir']}")
7373

0 commit comments

Comments
 (0)