3
3
# standard library
4
4
import unittest
5
5
from unittest .mock import MagicMock
6
+ from unittest .mock import patch
6
7
from datetime import date
7
8
import math
8
9
import numpy as np
10
+ import os
9
11
10
12
# third party
11
13
import pandas
@@ -42,6 +44,36 @@ def test_is_sane_week(self):
42
44
self .assertFalse (CsvImporter .is_sane_week (202054 ))
43
45
self .assertFalse (CsvImporter .is_sane_week (20200418 ))
44
46
47
+ @patch ("os.path.isdir" )
48
+ def test_find_issue_specific_csv_files (self ,os_isdir_mock ):
49
+ """Recursively explore and find issue specific CSV files."""
50
+ # check valid path
51
+ path_prefix = 'prefix/to/the/data/issue_20200408'
52
+ os_isdir_mock .return_value = True
53
+ issue_path = path_prefix + 'ght/20200408_state_rawsearch.csv'
54
+
55
+ mock_glob = MagicMock ()
56
+ mock_glob .glob .side_effect = ([path_prefix ], [issue_path ])
57
+
58
+ #check if the day is a valid day.
59
+ issuedir_match = CsvImporter .PATTERN_ISSUE_DIR .match (path_prefix .lower ())
60
+ issue_date_value = int (issuedir_match .group (2 ))
61
+ self .assertTrue (CsvImporter .is_sane_day (issue_date_value ))
62
+
63
+ found = set (CsvImporter .find_issue_specific_csv_files (path_prefix , glob = mock_glob ))
64
+ self .assertTrue (len (found )> 0 )
65
+
66
+ # check unvalid path:
67
+ path_prefix_invalid = 'invalid/prefix/to/the/data/issue_20200408'
68
+ os_isdir_mock .return_value = False
69
+ issue_path_invalid = path_prefix_invalid + 'ght/20200408_state_rawsearch.csv'
70
+ mock_glob_invalid = MagicMock ()
71
+ mock_glob_invalid .glob .side_effect = ([path_prefix_invalid ], [issue_path_invalid ])
72
+
73
+ found = set (CsvImporter .find_issue_specific_csv_files (path_prefix_invalid , glob = mock_glob_invalid ))
74
+ self .assertFalse (len (found )> 0 )
75
+
76
+
45
77
def test_find_csv_files (self ):
46
78
"""Recursively explore and find CSV files."""
47
79
@@ -306,4 +338,4 @@ def test_load_csv_with_valid_header(self):
306
338
self .assertEqual (rows [2 ].missing_stderr , Nans .NOT_MISSING )
307
339
self .assertEqual (rows [2 ].missing_sample_size , Nans .REGION_EXCEPTION )
308
340
309
- self .assertIsNone (rows [3 ])
341
+ self .assertIsNone (rows [3 ])
0 commit comments