Skip to content

Commit 10b4d1e

Browse files
committed
Fix integration tests
1 parent 687d586 commit 10b4d1e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

climada/test/test_nightlight.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import gzip
2323
import io
24+
import shutil
2425
import tarfile
2526
import unittest
2627
from pathlib import Path
@@ -225,6 +226,10 @@ def test_load_nightlight_noaa(self):
225226
pfile = f"{pattern}.p"
226227
tiffile = f"{pattern}.tif"
227228

229+
# Clean up potentially existing files
230+
SYSTEM_DIR.joinpath(pfile).unlink(missing_ok=True)
231+
SYSTEM_DIR.joinpath(gzfile).unlink(missing_ok=True)
232+
228233
# create an empty image
229234
image = np.zeros((100, 100), dtype=np.uint8)
230235
pilim = Image.fromarray(image)
@@ -343,12 +348,18 @@ def test_check_nl_local_file_exists(self):
343348
)
344349

345350
# check logger message: not all files are available
346-
with self.assertLogs(
347-
"climada.entity.exposures.litpop.nightlight", level="DEBUG"
348-
) as cm:
349-
nightlight.check_nl_local_file_exists()
350-
self.assertIn("Not all satellite files available. Found ", cm.output[0])
351-
self.assertIn(f" out of 8 required files in {Path(SYSTEM_DIR)}", cm.output[0])
351+
bm_filenames = [name % 2016 for name in BM_FILENAMES]
352+
with TemporaryDirectory() as tmpdir:
353+
# Copy two files
354+
shutil.copy(SYSTEM_DIR / bm_filenames[0], Path(tmpdir) / bm_filenames[0])
355+
shutil.copy(SYSTEM_DIR / bm_filenames[2], Path(tmpdir) / bm_filenames[2])
356+
357+
with self.assertLogs(
358+
"climada.entity.exposures.litpop.nightlight", level="DEBUG"
359+
) as cm:
360+
nightlight.check_nl_local_file_exists(check_path=tmpdir)
361+
self.assertIn("Not all satellite files available. Found 2", cm.output[0])
362+
self.assertIn(f" out of 8 required files in {tmpdir}", cm.output[0])
352363

353364
# check logger message: no files found in checkpath
354365
check_path = Path("climada/entity/exposures")

0 commit comments

Comments
 (0)