Skip to content

Commit a233937

Browse files
authored
Merge pull request #399 from sgsmob/usa_tests
Turn on `test_run` tests for usafacts
2 parents bdaa4c0 + 455f1dc commit a233937

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

usafacts/tests/test_run.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import pytest
2-
1+
"""Tests for running the USAFacts indicator."""
2+
from itertools import product
33
from os import listdir
44
from os.path import join
55

66
import pandas as pd
7-
from delphi_usafacts.run import run_module
87

98

109
class TestRun:
10+
"""Tests for the `run_module()` function."""
1111
def test_output_files_exist(self, run_as_module):
12-
13-
csv_files = listdir("receiving")
12+
"""Test that the expected output files exist."""
13+
csv_files = [f for f in listdir("receiving") if f.endswith(".csv")]
1414

1515
dates = [
1616
"20200229",
@@ -23,30 +23,28 @@ def test_output_files_exist(self, run_as_module):
2323
"20200307",
2424
"20200308",
2525
"20200309",
26-
"202003010",
26+
"20200310",
2727
]
2828
geos = ["county", "hrr", "msa", "state"]
29-
metrics = [
30-
"deaths_cumulative_num",
31-
"deaths_incidence_num",
32-
"deaths_incidence_prop",
33-
"confirmed_cumulative_num",
34-
"confirmed_incidence_num",
35-
"confirmed_incidence_prop",
36-
"deaths_7dav_cumulative_prop",
37-
"confirmed_7dav_cumulative_prop",
38-
]
29+
30+
# enumerate metric names.
31+
metrics = []
32+
for event, span, stat in product(["deaths", "confirmed"],
33+
["cumulative", "incidence"],
34+
["num", "prop"]):
35+
metrics.append("_".join([event, span, stat]))
36+
metrics.append("_".join([event, "7dav", span, stat]))
3937

4038
expected_files = []
4139
for date in dates:
4240
for geo in geos:
4341
for metric in metrics:
4442
expected_files += [date + "_" + geo + "_" + metric + ".csv"]
4543

46-
set(csv_files) == set(expected_files)
44+
assert set(csv_files) == set(expected_files)
4745

4846
def test_output_file_format(self, run_as_module):
49-
47+
"""Test that the output files have the proper format."""
5048
df = pd.read_csv(
5149
join("receiving", "20200310_state_confirmed_cumulative_num.csv")
5250
)

0 commit comments

Comments
 (0)