11import glob
2- from datetime import datetime , date
3- import json
4- from pathlib import Path
5- from unittest .mock import patch
6- import tempfile
2+ import logging
73import os
8- import time
9- from datetime import datetime
4+ from pathlib import Path
105
116import numpy as np
127import pandas as pd
8+ from delphi_nssp .constants import GEOS , SIGNALS_MAP
9+ from delphi_nssp .run import add_needed_columns
1310from epiweeks import Week
14- from pandas .testing import assert_frame_equal
15- from delphi_nssp .constants import GEOS , SIGNALS , SIGNALS_MAP , DATASET_ID
16- from delphi_nssp .run import (
17- add_needed_columns
18- )
1911
2012
13+ def remove_backup_and_receiving (params ):
14+ export_dir = params ["common" ]["export_dir" ]
15+ for file in Path (export_dir ).glob ("*.csv" ):
16+ os .remove (file )
17+
18+ today = pd .Timestamp .today ().strftime ("%Y%m%d" )
19+ backup_dir = glob .glob (f"{ Path (params ['common' ]['backup_dir' ])} /{ today } *" )
20+ for file in backup_dir :
21+ os .remove (file )
22+
2123class TestRun :
2224 def test_add_needed_columns (self ):
2325 df = pd .DataFrame ({"geo_id" : ["us" ], "val" : [1 ]})
@@ -68,16 +70,10 @@ def test_output_files_exist(self, params, run_as_module):
6870 ]
6971 assert set (expected_columns ).issubset (set (df .columns .values ))
7072
71- #Verify that there's no NA/empty values in the val columns
73+ # Verify that there's no NA/empty values in the val columns
7274 assert not df ["val" ].isnull ().any ()
7375
74- for file in Path (export_dir ).glob ("*.csv" ):
75- os .remove (file )
76-
77- today = pd .Timestamp .today ().strftime ("%Y%m%d" )
78- backup_dir = glob .glob (f"{ Path (params ['common' ]['backup_dir' ])} /{ today } *" )
79- for file in backup_dir :
80- os .remove (file )
76+ remove_backup_and_receiving (params )
8177
8278 def test_valid_hrr (self , run_as_module_hrr , params ):
8379 export_dir = params ["common" ]["export_dir" ]
@@ -88,10 +84,23 @@ def test_valid_hrr(self, run_as_module_hrr, params):
8884 df = pd .read_csv (f )
8985 assert (df .val == 100 ).all ()
9086
91- for file in Path (export_dir ).glob ("*.csv" ):
92- os .remove (file )
87+ remove_backup_and_receiving (params )
88+
89+ def test_empty_data (self , run_as_module_empty , params , caplog ):
90+ """
91+ Tests correct handling when there is a geo and signal combination that has no data.
92+ """
93+
94+ caplog .set_level (logging .WARNING )
95+ run_as_module_empty ()
96+ assert "No data for signal and geo combination" in caplog .text
97+
98+ export_dir = params ["common" ]["export_dir" ]
99+ csv_files = [f for f in Path (export_dir ).glob ("*.csv" )]
100+
101+ # Since only one national entry in page_no_data.json with numeric data,
102+ # while the two counties have no numeric fields,
103+ # there should be no county, hrr, hhs, or msa files.
104+ assert not any (geo in f .name for geo in ["county" , "hrr" , "hhs" , "msa" ] for f in csv_files )
93105
94- today = pd .Timestamp .today ().strftime ("%Y%m%d" )
95- backup_dir = glob .glob (f"{ Path (params ['common' ]['backup_dir' ])} /{ today } *" )
96- for file in backup_dir :
97- os .remove (file )
106+ remove_backup_and_receiving (params )
0 commit comments