1- import pytest
2-
1+ """Tests for running the USAFacts indicator."""
2+ from itertools import product
33from os import listdir
44from os .path import join
55
66import pandas as pd
7- from delphi_usafacts .run import run_module
87
98
109class 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