Skip to content

Commit 3769b66

Browse files
committed
use test data based on recent actual indicator run
1 parent 7a1d1b8 commit 3769b66

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

google_symptoms/tests/test_date_utils.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,44 @@ def test_generate_export_date_missing(self, params_w_no_date, logger, monkeypatc
6565
expected_num_export_days = (date.today() - FULL_BKFILL_START_DATE.date()).days + 1
6666
assert num_export_days == expected_num_export_days
6767

68+
def generate_expected_start_end_dates(self, params_, issue_date):
69+
dates_dict = {
70+
"2024-06-27": [ '2024-06-02', '2024-06-03', '2024-06-04', '2024-06-05', '2024-06-06', '2024-06-07', '2024-06-08', '2024-06-09', '2024-06-10', '2024-06-11', '2024-06-12', '2024-06-13', '2024-06-14', '2024-06-15', '2024-06-16', '2024-06-17', '2024-06-18', '2024-06-19', '2024-06-20', '2024-06-21', '2024-06-22'],
71+
"2024-06-28": ['2024-06-03', '2024-06-04', '2024-06-05', '2024-06-06', '2024-06-07', '2024-06-08', '2024-06-09', '2024-06-10', '2024-06-11', '2024-06-12', '2024-06-13', '2024-06-14', '2024-06-15', '2024-06-16', '2024-06-17', '2024-06-18', '2024-06-19', '2024-06-20', '2024-06-21', '2024-06-22', '2024-06-23'],
72+
"2024-06-29": ['2024-06-04', '2024-06-05', '2024-06-06','2024-06-07', '2024-06-08', '2024-06-09', '2024-06-10', '2024-06-11', '2024-06-12', '2024-06-13', '2024-06-14', '2024-06-15', '2024-06-16', '2024-06-17', '2024-06-18', '2024-06-19', '2024-06-20', '2024-06-21', '2024-06-22', '2024-06-23', '2024-06-24'],
73+
}
74+
75+
dates_dict = {
76+
datetime.strptime(key, "%Y-%m-%d"): [datetime.strptime(lvalue, "%Y-%m-%d") for lvalue in value]
77+
for key, value in dates_dict.items()
78+
}
79+
80+
dates = dates_dict[issue_date]
81+
82+
return {
83+
"export_start_date": min(dates[6:21]),
84+
"export_end_date": max(dates[6:21])
85+
}
86+
6887
def test_generate_patch_dates(self, params_w_patch, logger, monkeypatch):
6988
import covidcast
7089
metadata_df = pd.read_csv(f"{TEST_DIR}/test_data/covid_metadata_missing.csv")
7190
monkeypatch.setattr(covidcast, "metadata", lambda: metadata_df)
72-
max_expected_lag = lag_converter(params_w_patch["validation"]["common"].get("max_expected_lag", {"all": 4}))
91+
max_expected_lag = lag_converter(params_w_patch["validation"]["common"]["max_expected_lag"])
7392
global_max_expected_lag = max(list(max_expected_lag.values()))
74-
expected_num_export_days = params_w_patch["validation"]["common"].get("span_length", 14) + global_max_expected_lag
93+
num_export_days = params_w_patch["validation"]["common"]["span_length"]
7594

7695
issue_date = datetime.strptime(params_w_patch["patch"]["start_issue"], "%Y-%m-%d")
7796
end_issue = datetime.strptime(params_w_patch["patch"]["end_issue"], "%Y-%m-%d")
7897

7998
patch_date_dict = generate_patch_dates(params_w_patch)
8099

81100
while issue_date <= end_issue:
82-
expected_daterange = generate_query_dates(
83-
FULL_BKFILL_START_DATE,
84-
issue_date,
85-
expected_num_export_days,
86-
False
87-
)
88101
# in the patch script the date generated by generate_patch_dates becomes the export_start_date and export_end_date
89-
export_start_date, export_end_date = patch_date_dict[issue_date]
90-
actual_daterange = generate_query_dates(export_start_date, export_end_date, expected_num_export_days, True)
91-
assert set(actual_daterange) == set(expected_daterange)
92-
issue_date += timedelta(days=1)
102+
patch_settings = patch_date_dict[issue_date]
103+
expected_dict = self.generate_expected_start_end_dates(params_w_patch, issue_date)
104+
expected_dict["num_export_days"] = num_export_days # unmodified
105+
106+
assert patch_settings == expected_dict
107+
108+
issue_date += timedelta(days=1)

google_symptoms/tests/test_patch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ def side_effect(*args, **kwargs):
5555
df = state_data_gap
5656
pattern = re.compile(r'\d{4}-\d{2}-\d{2}')
5757
start_date, end_date = re.findall(pattern, args[0])
58-
end_date_w_lag = (datetime.strptime(end_date, "%Y-%m-%d") - timedelta(days=4)).strftime("%Y-%m-%d")
59-
return df[(df["date"] >= start_date) & \
60-
(df["date"] <= end_date_w_lag)]
58+
return df[(df["date"] >= start_date) & (df["date"] <= end_date)]
6159
else:
6260
return pd.DataFrame()
6361

0 commit comments

Comments
 (0)