@@ -24,10 +24,14 @@ def parse_csv_file(self, file_list: List[str]) -> Tuple[List[datetime]]:
24
24
raw_list = list (set ([datetime .strptime (f .name .split ('_' )[0 ],"%Y%m%d" ) for f in file_list if "raw" in f .name ]))
25
25
return sorted (smoothed_list ), sorted (raw_list )
26
26
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 }))
29
29
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
31
35
32
36
# mimic date generate as if the issue date was "today"
33
37
query_start_date , query_end_date = generate_query_dates (
@@ -42,8 +46,9 @@ def generate_expected_dates(self, params_w_patch, smoother, issue_date):
42
46
num_export_days = (export_end_date - export_start_date ).days + 1
43
47
44
48
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_ ), \
47
52
mock_patch ("delphi_google_symptoms.pull.pandas_gbq.read_gbq" ) as mock_read_gbq , \
48
53
mock_patch ("delphi_google_symptoms.pull.initialize_credentials" , return_value = None ), \
49
54
mock_patch ("delphi_google_symptoms.date_utils.covidcast.metadata" , return_value = covidcast_metadata ), \
@@ -60,23 +65,28 @@ def side_effect(*args, **kwargs):
60
65
return pd .DataFrame ()
61
66
62
67
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" )
64
69
65
70
patch ()
66
71
67
- patch_path = Path (f"{ TEST_DIR } /{ params_w_patch ['patch' ]['patch_dir' ]} " )
72
+ patch_path = Path (f"{ TEST_DIR } /{ params_ ['patch' ]['patch_dir' ]} " )
68
73
69
74
for issue_dir in sorted (list (patch_path .iterdir ())):
70
75
assert f'issue_{ datetime .strftime (start_date , "%Y%m%d" )} ' == issue_dir .name
71
76
72
77
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 )
75
80
76
81
assert smoothed_dates == expected_smoothed_dates
77
82
assert raw_dates == expected_raw_dates
78
83
shutil .rmtree (issue_dir )
79
84
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 )
80
90
81
91
82
92
if __name__ == '__main__' :
0 commit comments