From 966cb8a60becb962b94682539d11a58d4c4675d6 Mon Sep 17 00:00:00 2001 From: Ting-Hong Shieh <32212900+ting-hong-shieh@users.noreply.github.com> Date: Mon, 17 Aug 2026 01:47:55 +0800 Subject: [PATCH 1/3] MNT: install contextily with the other optional requirements contextily is declared in the monte-carlo extra in pyproject.toml but not in requirements-optional.txt, and the Makefile's install target reads the requirements files. test_monte_carlo_plots_background.py opens with pytest.importorskip("contextily"), so anyone who sets up with `make install` skips that file: 18 tests, and 53 statements that Codecov counts as covered. The workflow installs .[all], so CI already has it and is unaffected. What this fixes is the local suite silently disagreeing with CI, with a skip reason as the only clue. Same specifier as pyproject.toml, including the 3.14 marker. --- requirements-optional.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-optional.txt b/requirements-optional.txt index a79ed6b13..d1d95b2e6 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -7,5 +7,6 @@ imageio multiprocess>=0.70 statsmodels prettytable +contextily>=1.0.0; python_version < '3.14' pyvista>=0.45 imageio-ffmpeg>=0.5 \ No newline at end of file From 0e87657a2f6ebf5fd35d80dec2fe42148e07a637 Mon Sep 17 00:00:00 2001 From: Ting-Hong Shieh <32212900+ting-hong-shieh@users.noreply.github.com> Date: Wed, 19 Aug 2026 11:04:53 +0800 Subject: [PATCH 2/3] TST: mock contextily tile fetches --- .../test_monte_carlo_plots_background.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/simulation/test_monte_carlo_plots_background.py b/tests/unit/simulation/test_monte_carlo_plots_background.py index 8a9de5cf6..89a554a85 100644 --- a/tests/unit/simulation/test_monte_carlo_plots_background.py +++ b/tests/unit/simulation/test_monte_carlo_plots_background.py @@ -1,4 +1,5 @@ # pylint: disable=unused-argument,assignment-from-no-return +import math import os import urllib.error from unittest.mock import MagicMock, patch @@ -19,6 +20,33 @@ ) +@pytest.fixture(autouse=True) +def mock_background_tiles(monkeypatch): + """Return deterministic map tiles without contacting a tile provider.""" + contextily = import_optional_dependency("contextily") + + def mock_bounds2img(west, south, east, north, **kwargs): + earth_radius = 6378137.0 + + def to_mercator(longitude, latitude): + x = earth_radius * math.radians(longitude) + y = earth_radius * math.log( + math.tan(math.pi / 4 + math.radians(latitude) / 2) + ) + return x, y + + min_x, min_y = to_mercator(west, south) + max_x, max_y = to_mercator(east, north) + return np.zeros((2, 2, 3), dtype=np.uint8), ( + min_x, + max_x, + min_y, + max_y, + ) + + monkeypatch.setattr(contextily, "bounds2img", mock_bounds2img) + + class MockMonteCarlo(MonteCarlo): """Create a mock class to test the method without running a real simulation. From e054e8ab2e627ecd724124cb404d02ff76dc49f7 Mon Sep 17 00:00:00 2001 From: Ting-Hong Shieh <32212900+ting-hong-shieh@users.noreply.github.com> Date: Thu, 20 Aug 2026 12:34:23 +0800 Subject: [PATCH 3/3] CI: retry cancelled jobs