|
1 | 1 | """Tests for running combo cases and deaths indicator."""
|
2 | 2 | from datetime import date
|
3 | 3 | from itertools import product
|
| 4 | +import os |
4 | 5 | import unittest
|
5 | 6 | from unittest.mock import patch, call
|
6 | 7 | import pandas as pd
|
7 | 8 | import numpy as np
|
8 | 9 |
|
9 | 10 | from delphi_combo_cases_and_deaths.run import (
|
10 |
| - extend_raw_date_range, get_updated_dates, |
| 11 | + run_module, |
| 12 | + extend_raw_date_range, |
| 13 | + get_updated_dates, |
11 | 14 | sensor_signal,
|
12 | 15 | combine_usafacts_and_jhu,
|
13 | 16 | compute_special_geo_dfs,
|
@@ -244,6 +247,50 @@ def test_no_nation_jhu(mock_covidcast_signal):
|
244 | 247 | "sample_size": [None]},)
|
245 | 248 | )
|
246 | 249 |
|
| 250 | +@patch("delphi_combo_cases_and_deaths.run.combine_usafacts_and_jhu") |
| 251 | +def test_output_files(mock_combine): |
| 252 | + params = { |
| 253 | + "common": { |
| 254 | + "export_dir": "./receiving" |
| 255 | + }, |
| 256 | + "indicator": { |
| 257 | + "export_start_date": [2020, 4, 1], |
| 258 | + "source":"indicator-combination", |
| 259 | + "wip_signal": "" |
| 260 | + } |
| 261 | + } |
| 262 | + mock_combine.return_value = pd.DataFrame( |
| 263 | + { |
| 264 | + "geo_id": ["01000"], |
| 265 | + "val": [10], |
| 266 | + "timestamp": [pd.to_datetime("2021-01-04")], |
| 267 | + "issue": [pd.to_datetime("2021-01-04")], |
| 268 | + "se": 0, |
| 269 | + "sample_size": 0 |
| 270 | + }, |
| 271 | + index=[1] |
| 272 | + ) |
| 273 | + run_module(params) |
| 274 | + csv_files = [f for f in os.listdir("receiving") if f.endswith(".csv")] |
| 275 | + dates = ["20210104"] |
| 276 | + geos = ["county", "hrr", "msa", "state", "hhs", "nation"] |
| 277 | + |
| 278 | + # enumerate metric names. |
| 279 | + metrics = [] |
| 280 | + for event, span, stat in product(["deaths", "confirmed"], |
| 281 | + ["cumulative", "incidence"], |
| 282 | + ["num", "prop"]): |
| 283 | + metrics.append("_".join([event, span, stat])) |
| 284 | + metrics.append("_".join([event, "7dav", span, stat])) |
| 285 | + |
| 286 | + expected_files = [] |
| 287 | + for date in dates: |
| 288 | + for geo in geos: |
| 289 | + for metric in metrics: |
| 290 | + if "7dav" in metric and "cumulative" in metric: |
| 291 | + continue |
| 292 | + expected_files += [date + "_" + geo + "_" + metric + ".csv"] |
| 293 | + assert set(csv_files) == set(expected_files) |
247 | 294 |
|
248 | 295 | if __name__ == '__main__':
|
249 | 296 | unittest.main()
|
0 commit comments