33# standard library
44import unittest
55from unittest .mock import MagicMock
6+ from unittest .mock import patch
67from datetime import date
78import math
89import numpy as np
10+ import os
911
1012# third party
1113import pandas
@@ -42,6 +44,36 @@ def test_is_sane_week(self):
4244 self .assertFalse (CsvImporter .is_sane_week (202054 ))
4345 self .assertFalse (CsvImporter .is_sane_week (20200418 ))
4446
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+
4577 def test_find_csv_files (self ):
4678 """Recursively explore and find CSV files."""
4779
@@ -306,4 +338,4 @@ def test_load_csv_with_valid_header(self):
306338 self .assertEqual (rows [2 ].missing_stderr , Nans .NOT_MISSING )
307339 self .assertEqual (rows [2 ].missing_sample_size , Nans .REGION_EXCEPTION )
308340
309- self .assertIsNone (rows [3 ])
341+ self .assertIsNone (rows [3 ])
0 commit comments