Skip to content

Commit bfb15a7

Browse files
zhuoran-Cheng16krivard
authored andcommitted
modified the bad code at function find_issue_specific_csv_files and add test
1 parent 6985267 commit bfb15a7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/acquisition/covidcast/csv_importer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def find_issue_specific_csv_files(scan_dir, glob=glob):
8888
logger = get_structured_logger('find_issue_specific_csv_files')
8989
for path in sorted(glob.glob(os.path.join(scan_dir, '*'))):
9090
issuedir_match = CsvImporter.PATTERN_ISSUE_DIR.match(path.lower())
91-
if issuedir_match and os.path.isdir(path):
91+
if issuedir_match and glob.glob(os.path.isdir(path)):
9292
issue_date_value = int(issuedir_match.group(2))
9393
issue_date = CsvImporter.is_sane_day(issue_date_value)
9494
if issue_date:
95-
logger.info(event='processing csv files from issue', detail=issue_date, path)
95+
logger.info(event='processing csv files from issue', detail=issue_date, file=path)
9696
yield from CsvImporter.find_csv_files(path, issue=(issue_date, epi.Week.fromdate(issue_date)), glob=glob)
9797
else:
9898
logger.warning(event='invalid issue directory day', detail=issue_date_value, file=path)

tests/acquisition/covidcast/test_csv_importer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ def test_is_sane_week(self):
4141
self.assertFalse(CsvImporter.is_sane_week(202000))
4242
self.assertFalse(CsvImporter.is_sane_week(202054))
4343
self.assertFalse(CsvImporter.is_sane_week(20200418))
44-
44+
4545
def test_find_issue_specific_csv_files(self):
4646
"""Recursively explore and find issue specific CSV files."""
47-
4847
path_prefix='prefix/to/the/data/'
4948
#valid day path
5049
issue_path='issue_20200408'
5150
glob_issue_path = path_prefix + issue_path
52-
glob_file_path = path_prefix + issue_path + '/valid/20200408_nation_sig.csv'
51+
glob_file_path = path_prefix + issue_path + '/ght/20200408_state_rawsearch.csv'
5352
mock_glob = MagicMock()
54-
mock_glob.glob.side_effect = ([glob_issue_path], [glob_file_path])
55-
issuedir_match = CsvImporter.PATTERN_ISSUE_DIR.match(glob_issue_path.lower())
56-
issue_date_value = int(issuedir_match.group(2))
53+
mock_glob.glob.side_effect = ([glob_issue_path], [glob_file_path], [glob_file_path])
5754

5855
#check if the day is a valid issue day.
56+
issuedir_match = CsvImporter.PATTERN_ISSUE_DIR.match(glob_issue_path.lower())
57+
issue_date_value = int(issuedir_match.group(2))
58+
5959
self.assertTrue(CsvImporter.is_sane_day(issue_date_value))
60-
60+
6161
found = set(CsvImporter.find_issue_specific_csv_files(path_prefix, glob=mock_glob))
6262
self.assertTrue(len(found)>0)
6363

0 commit comments

Comments
 (0)