|
1 | 1 | """Tests for exporting CSV files.""" |
2 | 2 | from datetime import datetime |
| 3 | +import logging |
3 | 4 | from os import listdir |
4 | 5 | from os.path import join |
5 | | -from typing import Any, Dict, List |
| 6 | +from typing import Any, Dict |
6 | 7 |
|
7 | 8 | import mock |
8 | 9 | import numpy as np |
9 | 10 | import pandas as pd |
10 | 11 | from pandas.testing import assert_frame_equal |
11 | 12 |
|
12 | | -from delphi_utils import create_export_csv, Nans |
| 13 | +from delphi_utils import create_export_csv, Nans, create_backup_csv, get_structured_logger |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def _set_df_dtypes(df: pd.DataFrame, dtypes: Dict[str, Any]) -> pd.DataFrame: |
@@ -386,3 +387,18 @@ def test_export_sort(self, tmp_path): |
386 | 387 | }) |
387 | 388 | sorted_csv = _set_df_dtypes(pd.read_csv(join(tmp_path, "20200215_county_test.csv")), dtypes={"geo_id": str}) |
388 | 389 | assert_frame_equal(sorted_csv,expected_df) |
| 390 | + |
| 391 | + def test_create_backup_regular(self, caplog, tmp_path): |
| 392 | + caplog.set_level(logging.INFO) |
| 393 | + logger = get_structured_logger() |
| 394 | + today = datetime.strftime(datetime.today(), "%Y%m%d") |
| 395 | + dtypes = self.DF.dtypes.to_dict() |
| 396 | + del dtypes["timestamp"] |
| 397 | + geo_res = "county" |
| 398 | + metric = "test" |
| 399 | + sensor = "deaths" |
| 400 | + create_backup_csv(df=self.DF, backup_dir=tmp_path, custom_run=False, issue=None, geo_res=geo_res, metric=metric, sensor=sensor, logger=logger) |
| 401 | + assert "Backup file created" in caplog.text |
| 402 | + |
| 403 | + actual = pd.read_csv(join(tmp_path, f"{today}_{geo_res}_{metric}_{sensor}.csv.gz"), dtype=dtypes, parse_dates=["timestamp"]) |
| 404 | + assert self.DF.equals(actual) |
0 commit comments