Skip to content

Commit 37dfa55

Browse files
nmdefriesaysim319
authored andcommitted
test patch check if num_export_days is set or not
1 parent c695d97 commit 37dfa55

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

google_symptoms/tests/test_patch.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ def parse_csv_file(self, file_list: List[str]) -> Tuple[List[datetime]]:
2424
raw_list = list(set([datetime.strptime(f.name.split('_')[0],"%Y%m%d") for f in file_list if "raw" in f.name]))
2525
return sorted(smoothed_list), sorted(raw_list)
2626

27-
def generate_expected_dates(self, params_w_patch, smoother, issue_date):
28-
max_expected_lag = lag_converter(params_w_patch["validation"]["common"].get("max_expected_lag", {"all": 4}))
27+
def generate_expected_dates(self, params_, smoother, issue_date):
28+
max_expected_lag = lag_converter(params_["validation"]["common"].get("max_expected_lag", {"all": 4}))
2929
global_max_expected_lag = max(list(max_expected_lag.values()))
30-
num_export_days = params_w_patch["validation"]["common"].get("span_length", 14) + global_max_expected_lag
30+
31+
if params_["indicator"].get("num_export_days"):
32+
num_export_days = params_["indicator"]["num_export_days"]
33+
else:
34+
num_export_days = params_["validation"]["common"].get("span_length", 14) + global_max_expected_lag
3135

3236
# mimic date generate as if the issue date was "today"
3337
query_start_date, query_end_date = generate_query_dates(
@@ -42,8 +46,9 @@ def generate_expected_dates(self, params_w_patch, smoother, issue_date):
4246
num_export_days = (export_end_date - export_start_date).days + 1
4347

4448
return sorted([export_start_date + timedelta(days=x) for x in range(num_export_days)])
45-
def test_patch(self, params_w_patch, monkeypatch):
46-
with mock_patch("delphi_google_symptoms.patch.read_params", return_value=params_w_patch), \
49+
def mocked_patch(self, params_):
50+
51+
with mock_patch("delphi_google_symptoms.patch.read_params", return_value=params_), \
4752
mock_patch("delphi_google_symptoms.pull.pandas_gbq.read_gbq") as mock_read_gbq, \
4853
mock_patch("delphi_google_symptoms.pull.initialize_credentials", return_value=None), \
4954
mock_patch("delphi_google_symptoms.date_utils.covidcast.metadata", return_value=covidcast_metadata), \
@@ -60,23 +65,28 @@ def side_effect(*args, **kwargs):
6065
return pd.DataFrame()
6166

6267
mock_read_gbq.side_effect = side_effect
63-
start_date = datetime.strptime(params_w_patch["patch"]["start_issue"], "%Y-%m-%d")
68+
start_date = datetime.strptime(params_["patch"]["start_issue"], "%Y-%m-%d")
6469

6570
patch()
6671

67-
patch_path = Path(f"{TEST_DIR}/{params_w_patch['patch']['patch_dir']}")
72+
patch_path = Path(f"{TEST_DIR}/{params_['patch']['patch_dir']}")
6873

6974
for issue_dir in sorted(list(patch_path.iterdir())):
7075
assert f'issue_{datetime.strftime(start_date, "%Y%m%d")}' == issue_dir.name
7176

7277
smoothed_dates, raw_dates = self.parse_csv_file(list(Path(issue_dir, "google-symptom").glob("*.csv")))
73-
expected_smoothed_dates = self.generate_expected_dates(params_w_patch, "smoothed", start_date)
74-
expected_raw_dates = self.generate_expected_dates(params_w_patch, "raw", start_date)
78+
expected_smoothed_dates = self.generate_expected_dates(params_, "smoothed", start_date)
79+
expected_raw_dates = self.generate_expected_dates(params_, "raw", start_date)
7580

7681
assert smoothed_dates == expected_smoothed_dates
7782
assert raw_dates == expected_raw_dates
7883
shutil.rmtree(issue_dir)
7984
start_date += timedelta(days=1)
85+
def test_patch_default(self, params_w_patch):
86+
params_w_patch["indicator"]["num_export_days"] = None
87+
self.mocked_patch(params_w_patch)
88+
def test_patch_date_set(self, params_w_patch):
89+
self.mocked_patch(params_w_patch)
8090

8191

8292
if __name__ == '__main__':

0 commit comments

Comments
 (0)