Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 19 additions & 13 deletions tests/test_geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
NominatimGeocodingProvider,
OpenMeteoGeocodingProvider,
PrecisionReducingGeocodingProvider,
_location_name_matches,
_mainland_china_rules,
_specific_location_name,
possibly_mainland_china,
)
from weather_briefing.geocoding.matching import (
location_name_matches as _location_name_matches,
)
from weather_briefing.geocoding.matching import (
mainland_china_rules as _mainland_china_rules,
)
from weather_briefing.geocoding.matching import (
specific_location_name as _specific_location_name,
)
from weather_briefing.models import LocationSpec, ResolvedLocation
from weather_briefing.reference_data import ReferenceDataError, reference_value

Expand Down Expand Up @@ -294,9 +300,9 @@ async def test_nominatim_reverse_geocoder_rate_limits_consecutive_requests(monke
async def fake_sleep(delay: float) -> None:
sleep_calls.append(delay)

monkeypatch.setattr("weather_briefing.geocoding.asyncio.sleep", fake_sleep)
monkeypatch.setattr("weather_briefing.geocoding.nominatim.asyncio.sleep", fake_sleep)
monkeypatch.setattr(
"weather_briefing.geocoding.time",
"weather_briefing.geocoding.nominatim.time",
SimpleNamespace(monotonic=lambda: next(monotonic_values)),
)

Expand Down Expand Up @@ -847,9 +853,9 @@ async def test_nominatim_rate_limits_consecutive_requests(monkeypatch) -> None:
async def fake_sleep(delay: float) -> None:
sleep_calls.append(delay)

monkeypatch.setattr("weather_briefing.geocoding.asyncio.sleep", fake_sleep)
monkeypatch.setattr("weather_briefing.geocoding.nominatim.asyncio.sleep", fake_sleep)
monkeypatch.setattr(
"weather_briefing.geocoding.time",
"weather_briefing.geocoding.nominatim.time",
SimpleNamespace(monotonic=lambda: next(monotonic_values)),
)

Expand Down Expand Up @@ -1004,9 +1010,9 @@ def fake_value(filename: str, *path: str) -> object:
return {"minimum": "73", "maximum": "136"}
raise AssertionError(f"Unexpected call: {filename} {path}")

monkeypatch.setattr("weather_briefing.geocoding.reference_value", fake_value)
monkeypatch.setattr("weather_briefing.geocoding.matching.reference_value", fake_value)
monkeypatch.setattr(
"weather_briefing.geocoding.reference_string_tuple",
"weather_briefing.geocoding.matching.reference_string_tuple",
lambda *_: (),
)
with pytest.raises(ReferenceDataError, match="latitude"):
Expand All @@ -1023,9 +1029,9 @@ def fake_value(filename: str, *path: str) -> object:
return {"minimum": "200", "maximum": "250"}
raise AssertionError(f"Unexpected call: {filename} {path}")

monkeypatch.setattr("weather_briefing.geocoding.reference_value", fake_value)
monkeypatch.setattr("weather_briefing.geocoding.matching.reference_value", fake_value)
monkeypatch.setattr(
"weather_briefing.geocoding.reference_string_tuple",
"weather_briefing.geocoding.matching.reference_string_tuple",
lambda *_: (),
)
with pytest.raises(ReferenceDataError, match="longitude"):
Expand All @@ -1035,7 +1041,7 @@ def fake_value(filename: str, *path: str) -> object:
def test_mainland_china_rules_handles_corrupt_reference_data(monkeypatch) -> None:
_mainland_china_rules.cache_clear()
monkeypatch.setattr(
"weather_briefing.geocoding.reference_value",
"weather_briefing.geocoding.matching.reference_value",
lambda *_: (_ for _ in ()).throw(KeyError("missing")),
)
with pytest.raises(ReferenceDataError, match="mainland China geography"):
Expand All @@ -1044,7 +1050,7 @@ def test_mainland_china_rules_handles_corrupt_reference_data(monkeypatch) -> Non

def test_specific_location_name_rejects_non_string_suffix(monkeypatch) -> None:
monkeypatch.setattr(
"weather_briefing.geocoding.reference_value",
"weather_briefing.geocoding.matching.reference_value",
lambda *_: 123,
)
with pytest.raises(ReferenceDataError, match="suffix characters must be a string"):
Expand Down
Loading