Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions usafacts/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import pytest

"""Tests for running the USAFacts indicator."""
from itertools import product
from os import listdir
from os.path import join

import pandas as pd
from delphi_usafacts.run import run_module


class TestRun:
"""Tests for the `run_module()` function."""
def test_output_files_exist(self, run_as_module):

csv_files = listdir("receiving")
"""Test that the expected output files exist."""
csv_files = [f for f in listdir("receiving") if f.endswith(".csv")]

dates = [
"20200229",
Expand All @@ -23,30 +23,28 @@ def test_output_files_exist(self, run_as_module):
"20200307",
"20200308",
"20200309",
"202003010",
"20200310",
]
geos = ["county", "hrr", "msa", "state"]
metrics = [
"deaths_cumulative_num",
"deaths_incidence_num",
"deaths_incidence_prop",
"confirmed_cumulative_num",
"confirmed_incidence_num",
"confirmed_incidence_prop",
"deaths_7dav_cumulative_prop",
"confirmed_7dav_cumulative_prop",
]

# enumerate metric names.
metrics = []
for event, span, stat in product(["deaths", "confirmed"],
["cumulative", "incidence"],
["num", "prop"]):
metrics.append("_".join([event, span, stat]))
metrics.append("_".join([event, "7dav", span, stat]))

expected_files = []
for date in dates:
for geo in geos:
for metric in metrics:
expected_files += [date + "_" + geo + "_" + metric + ".csv"]

set(csv_files) == set(expected_files)
assert set(csv_files) == set(expected_files)

def test_output_file_format(self, run_as_module):

"""Test that the output files have the proper format."""
df = pd.read_csv(
join("receiving", "20200310_state_confirmed_cumulative_num.csv")
)
Expand Down