1
- import pytest
2
-
1
+ """Tests for running the USAFacts indicator."""
2
+ from itertools import product
3
3
from os import listdir
4
4
from os .path import join
5
5
6
6
import pandas as pd
7
- from delphi_usafacts .run import run_module
8
7
9
8
10
9
class TestRun :
10
+ """Tests for the `run_module()` function."""
11
11
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" )]
14
14
15
15
dates = [
16
16
"20200229" ,
@@ -23,30 +23,28 @@ def test_output_files_exist(self, run_as_module):
23
23
"20200307" ,
24
24
"20200308" ,
25
25
"20200309" ,
26
- "202003010 " ,
26
+ "20200310 " ,
27
27
]
28
28
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 ]))
39
37
40
38
expected_files = []
41
39
for date in dates :
42
40
for geo in geos :
43
41
for metric in metrics :
44
42
expected_files += [date + "_" + geo + "_" + metric + ".csv" ]
45
43
46
- set (csv_files ) == set (expected_files )
44
+ assert set (csv_files ) == set (expected_files )
47
45
48
46
def test_output_file_format (self , run_as_module ):
49
-
47
+ """Test that the output files have the proper format."""
50
48
df = pd .read_csv (
51
49
join ("receiving" , "20200310_state_confirmed_cumulative_num.csv" )
52
50
)
0 commit comments