-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_weather.py
More file actions
40 lines (32 loc) · 1.79 KB
/
Copy pathtest_weather.py
File metadata and controls
40 lines (32 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Tests for _geocode. All HTTP mocked — a real call here is the exact suite-
runtime regression CLAUDE.md warns about."""
from unittest.mock import patch
import pytest
import weather
class TestGeocode:
def setup_method(self):
weather._geocode_cache.clear()
def test_resolves_name_and_admin1(self):
with patch.object(weather, "_http_get_json_retry", return_value={
"results": [{"name": "Culver City", "admin1": "California",
"latitude": 34.0, "longitude": -118.4}]}) as m:
lat, lon, resolved = weather._geocode("Culver City, CA")
assert resolved == "Culver City, California"
assert m.call_args.kwargs["params"]["name"] == "Culver City, CA"
def test_passes_the_input_string_through_unchanged(self):
"""_geocode must not silently rewrite/broaden what it's given — that
contract belongs to the caller (tool description / profile), not here."""
with patch.object(weather, "_http_get_json_retry", return_value={
"results": [{"name": "X", "admin1": "Y", "latitude": 1, "longitude": 2}]}) as m:
weather._geocode("Some Specific Neighborhood, ST")
assert m.call_args.kwargs["params"]["name"] == "Some Specific Neighborhood, ST"
def test_cache_hit_skips_the_http_call(self):
with patch.object(weather, "_http_get_json_retry", return_value={
"results": [{"name": "X", "admin1": "", "latitude": 1, "longitude": 2}]}) as m:
weather._geocode("Denver")
weather._geocode(" DENVER ")
assert m.call_count == 1
def test_no_results_raises(self):
with patch.object(weather, "_http_get_json_retry", return_value={"results": []}):
with pytest.raises(ValueError):
weather._geocode("Nowhereville")