Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions tests/unit/simulation/test_monte_carlo_plots_background.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.

Expand Down
Loading