diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index a78901f749..84ddbffe00 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -37,6 +37,7 @@ jobs: uv cache clean uv pip install --find-links https://girder.github.io/large_image_wheels GDAL pyproj uv pip install -r pyproject.toml --extra all + uv pip install joblib - name: Test import run: | uv run python -c "import geemap; print('geemap import successful')" diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 627cca8433..e14e825a4a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -41,6 +41,9 @@ jobs: run: | uv pip install --find-links https://girder.github.io/large_image_wheels gdal pyproj uv pip install -r pyproject.toml --extra tests + uv pip install -r pyproject.toml --extra all + # For python > 3.12, make sure setuptools is installed. + uv pip install setuptools - name: Test import run: | uv run python -c "import geemap; print('geemap import successful')" diff --git a/tests/test_common.py b/tests/test_common.py index 3a7aff98a8..fb4ccda05a 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -21,6 +21,14 @@ import requests +try: + import joblib + + JOBLIB_AVAILABLE = True +except ImportError: + JOBLIB_AVAILABLE = False + + class CommonTest(unittest.TestCase): # TODO: test_ee_export_image @@ -598,7 +606,65 @@ def test_check_file_path(self): # TODO: test_dynamic_world_s2 # TODO: test_download_ee_image # TODO: test_download_ee_image_tiles - # TODO: test_download_ee_image_tiles_parallel + + @unittest.skipIf(not JOBLIB_AVAILABLE, "joblib not available.") + @mock.patch.object(common, "download_ee_image") + def test_download_ee_image_tiles_parallel(self, mock_download_ee_image): + image_mock = mock.MagicMock(spec=ee.Image) + feature_mock = mock.MagicMock(spec=ee.Feature) + geom_mock = mock.MagicMock(spec=ee.Geometry) + feature_mock.geometry.return_value = geom_mock + fc_mock = mock.MagicMock(spec=ee.FeatureCollection) + fc_mock.size.return_value.getInfo.return_value = 2 + fc_mock.toList.return_value.get.side_effect = [feature_mock, feature_mock] + fc_mock.aggregate_array.return_value.getInfo.return_value = ["1", "2"] + + with tempfile.TemporaryDirectory() as tmpdir: + common.download_ee_image_tiles_parallel( + image_mock, + fc_mock, + out_dir=tmpdir, + column="id", + ee_init=False, + # Avoid separate process spawning. + job_args={"n_jobs": 1, "prefer": "threads"}, + ) + self.assertEqual(mock_download_ee_image.call_count, 2) + mock_download_ee_image.assert_any_call( + image_mock, + os.path.join(tmpdir, "1.tif"), + geom_mock, + None, + None, + None, + "near", + None, + True, + None, + None, + None, + None, + False, + None, + ) + mock_download_ee_image.assert_any_call( + image_mock, + os.path.join(tmpdir, "2.tif"), + geom_mock, + None, + None, + None, + "near", + None, + True, + None, + None, + None, + None, + False, + None, + ) + # TODO: test_download_ee_image_collection def test_get_palette_colors(self):