Skip to content

Commit 196cdd4

Browse files
committed
Fix integration tests
1 parent 9c4a872 commit 196cdd4

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

climada/test/test_litpop_integr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_switzerland30normPop_pass(self):
120120
self.assertIn("LitPop: Init Exposure for country: CHE", cm.output[0])
121121
self.assertEqual(ent.region_id.min(), 756)
122122
self.assertEqual(ent.region_id.max(), 756)
123-
self.assertEqual(ent.value.sum(), 1.0)
123+
self.assertAlmostEqual(ent.value.sum(), 1.0)
124124
self.assertEqual(ent.ref_year, 2015)
125125

126126
def test_suriname30_nfw_pass(self):

climada/test/test_nightlight.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -236,45 +236,44 @@ def test_load_nightlight_noaa(self):
236236
with gzip.GzipFile(SYSTEM_DIR.joinpath(gzfile), "wb") as f:
237237
f.write(mem.getvalue())
238238

239-
try:
240-
# with arguments
241-
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(
242-
ref_year=year, sat_name=sat_name
243-
)
244-
self.assertIsInstance(night, sparse._csr.csr_matrix)
245-
self.assertIn(tiffile, str(fn_light))
246-
247-
# using already existing file and without providing arguments
248-
night, coord_nl, fn_light = nightlight.load_nightlight_noaa()
249-
self.assertIsInstance(night, sparse._csr.csr_matrix)
250-
self.assertIn(pfile, str(fn_light))
251-
self.assertTrue(
252-
np.array_equal(
253-
np.array([[-65, NOAA_RESOLUTION_DEG], [-180, NOAA_RESOLUTION_DEG]]),
254-
coord_nl,
255-
)
239+
# with arguments
240+
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(
241+
ref_year=year, sat_name=sat_name
242+
)
243+
self.assertIsInstance(night, sparse._csr.csr_matrix)
244+
self.assertIn(tiffile, str(fn_light))
245+
246+
# using already existing file and without providing arguments
247+
night, coord_nl, fn_light = nightlight.load_nightlight_noaa()
248+
self.assertIsInstance(night, sparse._csr.csr_matrix)
249+
self.assertIn(pfile, str(fn_light))
250+
self.assertTrue(
251+
np.array_equal(
252+
np.array([[-65, NOAA_RESOLUTION_DEG], [-180, NOAA_RESOLUTION_DEG]]),
253+
coord_nl,
256254
)
255+
)
257256

258-
# test raises from wrong input agruments
259-
with self.assertRaises(ValueError) as cm:
260-
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(
261-
ref_year=2050, sat_name="F150"
262-
)
263-
self.assertEqual(
264-
"Nightlight intensities for year 2050 and satellite F150 do not exist.",
265-
str(cm.exception),
257+
# test raises from wrong input agruments
258+
with self.assertRaises(ValueError) as cm:
259+
night, coord_nl, fn_light = nightlight.load_nightlight_noaa(
260+
ref_year=2050, sat_name="F150"
266261
)
267-
finally:
268-
# clean up
269-
SYSTEM_DIR.joinpath(pfile).unlink(missing_ok=True)
270-
SYSTEM_DIR.joinpath(gzfile).unlink(missing_ok=True)
262+
self.assertEqual(
263+
"Nightlight intensities for year 2050 and satellite F150 do not exist.",
264+
str(cm.exception),
265+
)
266+
# clean up
267+
SYSTEM_DIR.joinpath(pfile).unlink(missing_ok=True)
268+
SYSTEM_DIR.joinpath(gzfile).unlink(missing_ok=True)
271269

272270
def test_untar_noaa_stable_nighlight(self):
273271
"""Testing that input .tar file is moved into SYSTEM_DIR,
274272
tif.gz file is extracted from .tar file and moved into SYSTEM_DIR,
275273
exception are raised when no .tif.gz file is present in the tar file,
276274
and the logger message is recorded if more then one .tif.gz is present in
277275
.tar file."""
276+
nightlight.load_nightlight_noaa()
278277

279278
# Create path to .tif.gz and .csv files already existing in SYSTEM_DIR
280279
path_tif_gz_1 = Path(SYSTEM_DIR, "F182013.v4c_web.stable_lights.avg_vis.tif.gz")

0 commit comments

Comments
 (0)