Skip to content

Commit 0d300ba

Browse files
committed
add backup test
1 parent 10d8a77 commit 0d300ba

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

nchs_mortality/delphi_nchs_mortality/pull.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ def pull_nchs_mortality_data(
7373
results = client.get("r8kw-7aab", limit=10**10)
7474
df = pd.DataFrame.from_records(results)
7575

76-
create_backup_csv(df, backup_dir, custom_run=custom_run, logger=logger)
76+
create_backup_csv(df, backup_dir, custom_run=custom_run, logger=logger)
7777

78+
if not test_file:
7879
# drop "By Total" rows
7980
df = df[df["group"].transform(str.lower) == "by week"]
8081

nchs_mortality/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
PARAMS = {
1616
"common": {
17+
"custom_run": True,
1718
"daily_export_dir": "./daily_receiving",
1819
"weekly_export_dir": "./receiving",
1920
"backup_dir": "./raw_data_backups"

nchs_mortality/tests/test_pull.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import pytest
23

34
import pandas as pd
@@ -96,3 +97,14 @@ def test_bad_file_with_inconsistent_time_col(self):
9697
def test_bad_file_with_missing_cols(self):
9798
with pytest.raises(ValueError):
9899
pull_nchs_mortality_data(SOCRATA_TOKEN, backup_dir = "", custom_run = True, test_file = "bad_data_with_missing_cols.csv")
100+
101+
def test_backup_today_data(self):
102+
today = pd.Timestamp.today().strftime("%Y%m%d")
103+
backup_dir = "./raw_data_backups"
104+
pull_nchs_mortality_data(SOCRATA_TOKEN, backup_dir = backup_dir, custom_run = False, test_file = "test_data.csv")
105+
backup_file = f"{backup_dir}/{today}.csv.gz"
106+
backup_df = pd.read_csv(backup_file)
107+
source_df = pd.read_csv("test_data/test_data.csv")
108+
pd.testing.assert_frame_equal(source_df, backup_df)
109+
if os.path.exists(backup_file):
110+
os.remove(backup_file)

0 commit comments

Comments
 (0)