generated from Grigo/AndroidTemplate
added opentopo
This commit is contained in:
@@ -23,6 +23,16 @@ class _FakeClient:
|
||||
return False
|
||||
|
||||
def get(self, url, params=None):
|
||||
params = params or {}
|
||||
if "locations" in params:
|
||||
locs = params["locations"].split("|")
|
||||
return _FakeResponse({
|
||||
"status": "OK",
|
||||
"results": [
|
||||
{"elevation": 11.0 + i, "location": {"lat": 0, "lng": 0}}
|
||||
for i, _ in enumerate(locs)
|
||||
],
|
||||
})
|
||||
return _FakeResponse({"elevation": [152.0]})
|
||||
|
||||
|
||||
@@ -34,13 +44,20 @@ def test_probe_elevation_api_ok(monkeypatch):
|
||||
|
||||
assert status["ok"] is True
|
||||
assert status["error"] is None
|
||||
assert status["opentopodata_ok"] is True
|
||||
|
||||
|
||||
def test_fetch_skips_when_unreachable(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {"ok": False, "url": elev.ELEVATION_API_URL, "error": "down"},
|
||||
lambda force=False: {
|
||||
"ok": False,
|
||||
"url": elev.ELEVATION_OPENTOPO_URL,
|
||||
"error": "down",
|
||||
"opentopodata_ok": False,
|
||||
"fallback_ok": False,
|
||||
},
|
||||
)
|
||||
|
||||
vals = elev.fetch_elevations_batch([55.75], [37.62])
|
||||
@@ -52,7 +69,13 @@ def test_build_profile_reports_unreachable(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {"ok": False, "url": elev.ELEVATION_API_URL, "error": "down"},
|
||||
lambda force=False: {
|
||||
"ok": False,
|
||||
"url": elev.ELEVATION_OPENTOPO_URL,
|
||||
"error": "down",
|
||||
"opentopodata_ok": False,
|
||||
"fallback_ok": False,
|
||||
},
|
||||
)
|
||||
|
||||
profile = elev.build_elevation_profile(
|
||||
@@ -76,7 +99,16 @@ def test_resample_track_path_count_even_spacing():
|
||||
|
||||
def test_build_profile_target_points(monkeypatch):
|
||||
monkeypatch.setattr(elev, "_probe_checked_at", 0.0)
|
||||
monkeypatch.setattr(elev, "probe_elevation_api", lambda force=False: {"ok": True, "error": None})
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {
|
||||
"ok": True,
|
||||
"error": None,
|
||||
"opentopodata_ok": True,
|
||||
"fallback_ok": True,
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"fetch_elevations_batch",
|
||||
@@ -96,7 +128,13 @@ def test_find_nearest_hill_unreachable(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {"ok": False, "url": elev.ELEVATION_API_URL, "error": "down"},
|
||||
lambda force=False: {
|
||||
"ok": False,
|
||||
"url": elev.ELEVATION_OPENTOPO_URL,
|
||||
"error": "down",
|
||||
"opentopodata_ok": False,
|
||||
"fallback_ok": False,
|
||||
},
|
||||
)
|
||||
result = elev.find_nearest_hill(55.75, 37.62)
|
||||
assert result["ok"] is False
|
||||
@@ -104,7 +142,16 @@ def test_find_nearest_hill_unreachable(monkeypatch):
|
||||
|
||||
def test_find_nearest_hill_picks_nearest_peak(monkeypatch):
|
||||
monkeypatch.setattr(elev, "_probe_checked_at", 0.0)
|
||||
monkeypatch.setattr(elev, "probe_elevation_api", lambda force=False: {"ok": True, "error": None})
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {
|
||||
"ok": True,
|
||||
"error": None,
|
||||
"opentopodata_ok": True,
|
||||
"fallback_ok": True,
|
||||
},
|
||||
)
|
||||
|
||||
def fake_batch(lats, lons):
|
||||
out = []
|
||||
@@ -125,7 +172,16 @@ def test_find_nearest_hill_picks_nearest_peak(monkeypatch):
|
||||
|
||||
def test_build_elevation_grid_delta(monkeypatch):
|
||||
monkeypatch.setattr(elev, "_probe_checked_at", 0.0)
|
||||
monkeypatch.setattr(elev, "probe_elevation_api", lambda force=False: {"ok": True, "error": None})
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {
|
||||
"ok": True,
|
||||
"error": None,
|
||||
"opentopodata_ok": True,
|
||||
"fallback_ok": True,
|
||||
},
|
||||
)
|
||||
|
||||
def fake_batch(lats, lons):
|
||||
return [100.0 + (la - 55.75) * 1000.0 for la, lo in zip(lats, lons)]
|
||||
@@ -143,7 +199,16 @@ def test_build_elevation_grid_delta(monkeypatch):
|
||||
|
||||
def test_build_elevation_grid_fine_step_small_radius(monkeypatch):
|
||||
monkeypatch.setattr(elev, "_probe_checked_at", 0.0)
|
||||
monkeypatch.setattr(elev, "probe_elevation_api", lambda force=False: {"ok": True, "error": None})
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {
|
||||
"ok": True,
|
||||
"error": None,
|
||||
"opentopodata_ok": True,
|
||||
"fallback_ok": True,
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(elev, "fetch_elevation_m", lambda lat, lon: 120.0)
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
@@ -159,7 +224,16 @@ def test_build_elevation_grid_fine_step_small_radius(monkeypatch):
|
||||
|
||||
def test_build_elevation_grid_limits_points(monkeypatch):
|
||||
monkeypatch.setattr(elev, "_probe_checked_at", 0.0)
|
||||
monkeypatch.setattr(elev, "probe_elevation_api", lambda force=False: {"ok": True, "error": None})
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {
|
||||
"ok": True,
|
||||
"error": None,
|
||||
"opentopodata_ok": True,
|
||||
"fallback_ok": True,
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(elev, "fetch_elevation_m", lambda lat, lon: 50.0)
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
@@ -170,3 +244,31 @@ def test_build_elevation_grid_limits_points(monkeypatch):
|
||||
step = elev._resolve_grid_step(55.75, 37.62, 500.0, 5.0)
|
||||
cells = elev._sample_circular_grid(55.75, 37.62, 500.0, step)
|
||||
assert len(cells) <= elev._MAX_GRID_POINTS
|
||||
|
||||
|
||||
def test_fetch_uses_fallback_when_opentopo_missing(monkeypatch):
|
||||
monkeypatch.setattr(elev, "_CACHE", {})
|
||||
monkeypatch.setattr(
|
||||
elev,
|
||||
"probe_elevation_api",
|
||||
lambda force=False: {
|
||||
"ok": True,
|
||||
"error": None,
|
||||
"opentopodata_ok": True,
|
||||
"fallback_ok": True,
|
||||
},
|
||||
)
|
||||
|
||||
def fake_opentopo(batch_lat, batch_lon):
|
||||
return [None] * len(batch_lat)
|
||||
|
||||
def fake_fallback(batch_lat, batch_lon):
|
||||
return [42.0] * len(batch_lat)
|
||||
|
||||
monkeypatch.setattr(elev, "_fetch_opentopodata_batch", fake_opentopo)
|
||||
monkeypatch.setattr(elev, "_fetch_fallback_batch", fake_fallback)
|
||||
|
||||
vals = elev.fetch_elevations_batch([55.75], [37.62])
|
||||
|
||||
assert vals == [42.0]
|
||||
assert elev._last_fetch_source == "openmeteo"
|
||||
|
||||
Reference in New Issue
Block a user