@@ -84,12 +84,12 @@ def test_get_required_nl_files(self):
8484 """ get_required_nl_files return a boolean matrix of 0 and 1
8585 indicating which tile of NASA nighlight files are needed giving
8686 a bounding box. This test check a few configuration of tiles
87- and check that a value error is raised if the bounding box are
87+ and check that a value error is raised if the bounding box are
8888 incorrect """
8989
9090 # incorrect bounds: bounds size =! 4, min lon > max lon, min lat > min lat
91- BOUNDS = [(20 , 30 , 40 ),
92- (120 , - 20 , 110 , 30 ),
91+ BOUNDS = [(20 , 30 , 40 ),
92+ (120 , - 20 , 110 , 30 ),
9393 (- 120 , 50 , 130 , 10 )]
9494 # correct bounds
9595 bounds_c1 = (- 120 , - 20 , 0 , 40 )
@@ -98,13 +98,13 @@ def test_get_required_nl_files(self):
9898
9999 for bounds in BOUNDS :
100100 with self .assertRaises (ValueError ) as cm :
101-
101+
102102 nightlight .get_required_nl_files (bounds = bounds )
103103
104104 self .assertEqual ('Invalid bounds supplied. `bounds` must be tuple'
105105 ' with (min_lon, min_lat, max_lon, max_lat).' ,
106106 str (cm .exception ))
107-
107+
108108 # test first correct bounds configurations
109109 req_files = nightlight .get_required_nl_files (bounds = bounds_c1 )
110110 bool = np .array_equal (np .array ([1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 ]), req_files )
@@ -117,7 +117,7 @@ def test_get_required_nl_files(self):
117117 req_files = nightlight .get_required_nl_files (bounds = bounds_c3 )
118118 bool = np .array_equal (np .array ([0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ]), req_files )
119119 self .assertTrue (bool )
120-
120+
121121 def test_check_nl_local_file_exists (self ):
122122 """ Test that an array with the correct number of already existing files
123123 is produced, the LOGGER messages logged and the ValueError raised. """
@@ -127,31 +127,32 @@ def test_check_nl_local_file_exists(self):
127127 nightlight .check_nl_local_file_exists (required_files = np .array ([0 , 0 , 1 , 1 ]))
128128 self .assertIn ('The parameter \' required_files\' was too short and is ignored' ,
129129 cm .output [0 ])
130-
131- # check logger message: not all files are available
130+
131+ # check logger message: not all files are available
132132 with self .assertLogs ('climada.entity.exposures.litpop.nightlight' , level = 'DEBUG' ) as cm :
133133 nightlight .check_nl_local_file_exists ()
134- self .assertIn ('Not all satellite files available. '
135- f'Found 5 out of 8 required files in { Path (SYSTEM_DIR )} ' , cm .output [0 ])
136-
134+ self .assertIn ('Not all satellite files available. Found ' , cm . output [ 0 ])
135+ self . assertIn ( f' out of 8 required files in { Path (SYSTEM_DIR )} ' , cm .output [0 ])
136+
137137 # check logger message: no files found in checkpath
138138 check_path = Path ('climada/entity/exposures' )
139139 with self .assertLogs ('climada.entity.exposures.litpop.nightlight' , level = 'INFO' ) as cm :
140140 # using a random path where no files are stored
141141 nightlight .check_nl_local_file_exists (check_path = check_path )
142142 self .assertIn (f'No satellite files found locally in { check_path } ' ,
143143 cm .output [0 ])
144-
144+
145145 # test raises with wrong path
146146 check_path = Path ('/random/wrong/path' )
147147 with self .assertRaises (ValueError ) as cm :
148148 nightlight .check_nl_local_file_exists (check_path = check_path )
149149 self .assertEqual (f'The given path does not exist: { check_path } ' ,
150150 str (cm .exception ))
151151
152- # test that files_exist is correct
152+ # test that files_exist is correct
153153 files_exist = nightlight .check_nl_local_file_exists ()
154- self .assertEqual (int (sum (files_exist )), 5 )
154+ self .assertGreaterEqual (int (sum (files_exist )), 3 )
155+ self .assertLessEqual (int (sum (files_exist )), 8 )
155156
156157# Execute Tests
157158if __name__ == "__main__" :
0 commit comments