@@ -185,29 +185,30 @@ def test_load_nightlight_noaa(self):
185185 # compressed image to a gzip file
186186 with gzip .GzipFile (SYSTEM_DIR .joinpath (gzfile ), 'wb' ) as f :
187187 f .write (mem .getvalue ())
188- SYSTEM_DIR .joinpath (pfile ).unlink (missing_ok = True )
189-
190- # using already existing file and without providing arguments
191- night , coord_nl , fn_light = nightlight .load_nightlight_noaa ()
192- self .assertIsInstance (night , sparse ._csr .csr_matrix )
193- self .assertIn (tiffile , str (fn_light ))
194- self .assertTrue (np .array_equal (np .array ([[- 65 , NOAA_RESOLUTION_DEG ],
195- [- 180 , NOAA_RESOLUTION_DEG ]]),coord_nl ))
196- SYSTEM_DIR .joinpath (pfile ).unlink ()
197-
198- # with arguments
199- night , coord_nl , fn_light = nightlight .load_nightlight_noaa (ref_year = year , sat_name = sat_name )
200- self .assertIsInstance (night , sparse ._csr .csr_matrix )
201- self .assertIn (tiffile , str (fn_light ))
202- SYSTEM_DIR .joinpath (pfile ).unlink ()
203- SYSTEM_DIR .joinpath (gzfile ).unlink ()
204-
205- # test raises from wrong input agruments
206- with self .assertRaises (ValueError ) as cm :
207- night , coord_nl , fn_light = nightlight .load_nightlight_noaa (
208- ref_year = 2050 , sat_name = 'F150' )
209- self .assertEqual ('Nightlight intensities for year 2050 and satellite F150 do not exist.' ,
210- str (cm .exception ))
188+
189+ try :
190+ # with arguments
191+ night , coord_nl , fn_light = nightlight .load_nightlight_noaa (ref_year = year , sat_name = sat_name )
192+ self .assertIsInstance (night , sparse ._csr .csr_matrix )
193+ self .assertIn (tiffile , str (fn_light ))
194+
195+ # using already existing file and without providing arguments
196+ night , coord_nl , fn_light = nightlight .load_nightlight_noaa ()
197+ self .assertIsInstance (night , sparse ._csr .csr_matrix )
198+ self .assertIn (pfile , str (fn_light ))
199+ self .assertTrue (np .array_equal (np .array ([[- 65 , NOAA_RESOLUTION_DEG ],
200+ [- 180 , NOAA_RESOLUTION_DEG ]]),coord_nl ))
201+
202+ # test raises from wrong input agruments
203+ with self .assertRaises (ValueError ) as cm :
204+ night , coord_nl , fn_light = nightlight .load_nightlight_noaa (
205+ ref_year = 2050 , sat_name = 'F150' )
206+ self .assertEqual ('Nightlight intensities for year 2050 and satellite F150 do not exist.' ,
207+ str (cm .exception ))
208+ finally :
209+ # clean up
210+ SYSTEM_DIR .joinpath (pfile ).unlink (missing_ok = True )
211+ SYSTEM_DIR .joinpath (gzfile ).unlink (missing_ok = True )
211212
212213 def test_untar_noaa_stable_nighlight (self ):
213214 """ Testing that input .tar file is moved into SYSTEM_DIR,
0 commit comments