Skip to content

Commit

Permalink
Merge pull request #622 from cmu-delphi/logging-patch
Browse files Browse the repository at this point in the history
fix logger bug for batch issue upload
  • Loading branch information
krivard authored Jul 12, 2021
2 parents 7d08b87 + 54c8fad commit a09889f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/acquisition/covidcast/csv_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def find_issue_specific_csv_files(scan_dir, glob=glob):
issue_date_value = int(issuedir_match.group(2))
issue_date = CsvImporter.is_sane_day(issue_date_value)
if issue_date:
logger.info('processing csv files from issue date: "' + str(issue_date) + '", directory', path)
logger.info(event='processing csv files from issue', detail=issue_date, file=path)
yield from CsvImporter.find_csv_files(path, issue=(issue_date, epi.Week.fromdate(issue_date)), glob=glob)
else:
logger.warning(event='invalid issue directory day', detail=issue_date_value, file=path)
Expand Down
34 changes: 33 additions & 1 deletion tests/acquisition/covidcast/test_csv_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# standard library
import unittest
from unittest.mock import MagicMock
from unittest.mock import patch
from datetime import date
import math
import numpy as np
import os

# third party
import pandas
Expand Down Expand Up @@ -42,6 +44,36 @@ def test_is_sane_week(self):
self.assertFalse(CsvImporter.is_sane_week(202054))
self.assertFalse(CsvImporter.is_sane_week(20200418))

@patch("os.path.isdir")
def test_find_issue_specific_csv_files(self,os_isdir_mock):
"""Recursively explore and find issue specific CSV files."""
# check valid path
path_prefix='prefix/to/the/data/issue_20200408'
os_isdir_mock.return_value=True
issue_path=path_prefix+'ght/20200408_state_rawsearch.csv'

mock_glob = MagicMock()
mock_glob.glob.side_effect = ([path_prefix], [issue_path])

#check if the day is a valid day.
issuedir_match= CsvImporter.PATTERN_ISSUE_DIR.match(path_prefix.lower())
issue_date_value = int(issuedir_match.group(2))
self.assertTrue(CsvImporter.is_sane_day(issue_date_value))

found = set(CsvImporter.find_issue_specific_csv_files(path_prefix, glob=mock_glob))
self.assertTrue(len(found)>0)

# check unvalid path:
path_prefix_invalid='invalid/prefix/to/the/data/issue_20200408'
os_isdir_mock.return_value=False
issue_path_invalid=path_prefix_invalid+'ght/20200408_state_rawsearch.csv'
mock_glob_invalid = MagicMock()
mock_glob_invalid.glob.side_effect = ([path_prefix_invalid], [issue_path_invalid])

found = set(CsvImporter.find_issue_specific_csv_files(path_prefix_invalid, glob=mock_glob_invalid))
self.assertFalse(len(found)>0)


def test_find_csv_files(self):
"""Recursively explore and find CSV files."""

Expand Down Expand Up @@ -306,4 +338,4 @@ def test_load_csv_with_valid_header(self):
self.assertEqual(rows[2].missing_stderr, Nans.NOT_MISSING)
self.assertEqual(rows[2].missing_sample_size, Nans.REGION_EXCEPTION)

self.assertIsNone(rows[3])
self.assertIsNone(rows[3])

0 comments on commit a09889f

Please sign in to comment.