Skip to content

Commit d78ee3a

Browse files
Jingjing TangJingjing Tang
authored andcommitted
added unit tests for bad test files
1 parent ade3feb commit d78ee3a

File tree

5 files changed

+13
-131
lines changed

5 files changed

+13
-131
lines changed

nchs_mortality/delphi_nchs_mortality/pull.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def pull_nchs_mortality_data(token: str, map_df: pd.DataFrame, test_mode: str):
3939
TYPE_DICT = {key: float for key in KEEP_COLUMNS}
4040
TYPE_DICT["timestamp"] = 'datetime64[ns]'
4141

42-
if test_mode:
43-
df = pd.read_csv("./test_data/test_data.csv")
44-
else:
42+
if test_mode == "":
4543
# Pull data from Socrata API
4644
client = Socrata("data.cdc.gov", token)
4745
results = client.get("r8kw-7aab", limit=10**10)
4846
df = pd.DataFrame.from_records(results).rename(
4947
{"start_week": "timestamp"}, axis=1)
48+
else:
49+
df = pd.read_csv("./test_data/%s"%test_mode)
5050

5151
# Check missing start_week == end_week
5252
try:

nchs_mortality/delphi_nchs_mortality/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def run_module():
4343
daily_cache_dir = params["daily_cache_dir"]
4444
static_file_dir = params["static_file_dir"]
4545
token = params["token"]
46-
test_mode = (params["mode"] == "test")
46+
test_mode = params["mode"]
4747

4848
daily_arch_diff = S3ArchiveDiffer(
4949
daily_cache_dir, daily_export_dir,

nchs_mortality/tests/params.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"daily_export_dir": "./daily_receiving",
77
"daily_cache_dir": "./daily_cache",
88
"token": "",
9-
"mode":"test",
9+
"mode":"test_data.csv",
1010
"aws_credentials": {
1111
"aws_access_key_id": "FAKE_TEST_ACCESS_KEY_ID",
1212
"aws_secret_access_key": "FAKE_TEST_SECRET_ACCESS_KEY"
Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1 @@
1-
# You should hard commit a prototype for this file, but we
2-
# want to avoid accidental adding of API tokens and other
3-
# private data parameters
4-
params.json
5-
6-
# Do not commit output files
7-
receiving/*.csv
8-
9-
# Do not commit test files
10-
tests/receiving/*.csv
11-
12-
# Remove macOS files
13-
.DS_Store
14-
15-
# virtual environment
16-
dview/
17-
18-
# Byte-compiled / optimized / DLL files
19-
__pycache__/
20-
*.py[cod]
21-
*$py.class
22-
23-
# C extensions
24-
*.so
25-
26-
# Distribution / packaging
27-
coverage.xml
28-
.Python
29-
build/
30-
develop-eggs/
31-
dist/
32-
downloads/
33-
eggs/
34-
.eggs/
35-
lib/
36-
lib64/
37-
parts/
38-
sdist/
39-
var/
40-
wheels/
41-
*.egg-info/
42-
.installed.cfg
43-
*.egg
44-
MANIFEST
45-
46-
# PyInstaller
47-
# Usually these files are written by a python script from a template
48-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
49-
*.manifest
50-
*.spec
51-
52-
# Installer logs
53-
pip-log.txt
54-
pip-delete-this-directory.txt
55-
56-
# Unit test / coverage reports
57-
htmlcov/
58-
.tox/
59-
.coverage
60-
.coverage.*
61-
.cache
62-
nosetests.xml
63-
coverage.xml
64-
*.cover
65-
.hypothesis/
66-
.pytest_cache/
67-
68-
# Translations
69-
*.mo
70-
*.pot
71-
72-
# Django stuff:
73-
*.log
74-
.static_storage/
75-
.media/
76-
local_settings.py
77-
78-
# Flask stuff:
79-
instance/
80-
.webassets-cache
81-
82-
# Scrapy stuff:
83-
.scrapy
84-
85-
# Sphinx documentation
86-
docs/_build/
87-
88-
# PyBuilder
89-
target/
90-
91-
# Jupyter Notebook
92-
.ipynb_checkpoints
93-
94-
# pyenv
95-
.python-version
96-
97-
# celery beat schedule file
98-
celerybeat-schedule
99-
100-
# SageMath parsed files
101-
*.sage.py
102-
103-
# Environments
104-
.env
105-
.venv
106-
env/
107-
venv/
108-
ENV/
109-
env.bak/
110-
venv.bak/
111-
112-
# Spyder project settings
113-
.spyderproject
114-
.spyproject
115-
116-
# Rope project settings
117-
.ropeproject
118-
119-
# mkdocs documentation
120-
/site
121-
122-
# mypy
123-
.mypy_cache/
1+
*.csv

nchs_mortality/tests/test_pull.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
export_dir = params["export_dir"]
1313
static_file_dir = params["static_file_dir"]
1414
token = params["token"]
15-
test_mode = (params["mode"] == "test")
1615

1716
map_df = pd.read_csv(
1817
join(static_file_dir, "state_pop.csv"), dtype={"fips": int}
1918
)
2019

2120
class TestPullUSAFacts:
2221
def test_good_file(self):
23-
df = pull_nchs_mortality_data(token, map_df, test_mode)
22+
df = pull_nchs_mortality_data(token, map_df, "test_data.csv")
2423

2524
assert (df.columns.values == [
2625
'covid_deaths', 'total_deaths', 'percent_of_expected_deaths',
2726
'pneumonia_deaths', 'pneumonia_and_covid_deaths',
2827
'influenza_deaths', 'pneumonia_influenza_or_covid_19_deaths',
29-
"timestamp", "geo_id", "population"]).all()
28+
"timestamp", "geo_id", "population"]).all()
29+
30+
def test_bad_file_with_inconsistent_time_col(self):
31+
with pytest.raises(ValueError):
32+
df = pull_nchs_mortality_data(token, map_df,
33+
"bad_data_with_inconsistent_time_col.csv")

0 commit comments

Comments
 (0)