Skip to content

Commit

Permalink
Fix usage of multiprocessing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Apr 15, 2024
1 parent 3c656d9 commit c248ff4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions geotiepoints/tests/test_modis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import h5py
import os

import pytest

FILENAME_250M_RESULT = os.path.join(
os.path.dirname(__file__), '../../testdata/250m_lonlat_section_result.h5')
FILENAME_250M_INPUT = os.path.join(
Expand Down Expand Up @@ -68,8 +70,12 @@ def test_5_to_1(self):
np.testing.assert_allclose(tlons, glons, atol=0.05)
np.testing.assert_allclose(tlats, glats, atol=0.05)

def test_1000m_to_250m(self):
@pytest.mark.parametrize("ncores", [None, 4])
def test_1000m_to_250m(self, ncores):
"""Test the 1 km to 250 meter interpolation facility."""
if ncores:
import multiprocessing as mp
mp.set_start_method("spawn", force=True)

with h5py.File(FILENAME_250M_RESULT) as h5f:
glons = h5f['longitude'][:] / 1000.
Expand All @@ -79,10 +85,7 @@ def test_1000m_to_250m(self):
lons = h5f['longitude'][:] / 1000.
lats = h5f['latitude'][:] / 1000.

tlons, tlats = modis1kmto250m(lons, lats)
np.testing.assert_allclose(tlons, glons, atol=0.05)
np.testing.assert_allclose(tlats, glats, atol=0.05)

tlons, tlats = modis1kmto250m(lons, lats, cores=4)
kwargs = {"cores": ncores} if ncores is not None else {}
tlons, tlats = modis1kmto250m(lons, lats, **kwargs)
np.testing.assert_allclose(tlons, glons, atol=0.05)
np.testing.assert_allclose(tlats, glats, atol=0.05)

0 comments on commit c248ff4

Please sign in to comment.