11"""Unit tests for location search."""
2+
23import pytest
34from ukfuelfinder .client import FuelFinderClient
45from ukfuelfinder .models import PFSInfo , Location
@@ -13,9 +14,9 @@ def test_haversine_distance(self):
1314 # London to Paris (approx 344 km)
1415 london_lat , london_lon = 51.5074 , - 0.1278
1516 paris_lat , paris_lon = 48.8566 , 2.3522
16-
17+
1718 distance = FuelFinderClient ._haversine (london_lon , london_lat , paris_lon , paris_lat )
18-
19+
1920 assert 340 < distance < 350 # Approximate distance
2021
2122 def test_search_by_location (self , monkeypatch ):
@@ -59,18 +60,18 @@ def test_search_by_location(self, monkeypatch):
5960 ),
6061 ),
6162 ]
62-
63+
6364 client = FuelFinderClient (client_id = "test" , client_secret = "test" )
6465 monkeypatch .setattr (client , "get_all_pfs_info" , lambda : mock_sites )
65-
66+
6667 # Search near London
6768 results = client .search_by_location (51.5074 , - 0.1278 , radius_km = 5.0 )
68-
69+
6970 # Should find first two stations (within 5km), not the third
7071 assert len (results ) == 2
7172 assert results [0 ][1 ].node_id == "site1" # Closest
7273 assert results [1 ][1 ].node_id == "site2"
73-
74+
7475 # Results should be sorted by distance
7576 assert results [0 ][0 ] < results [1 ][0 ]
7677
@@ -90,13 +91,13 @@ def test_search_by_location_no_results(self, monkeypatch):
9091 ),
9192 ),
9293 ]
93-
94+
9495 client = FuelFinderClient (client_id = "test" , client_secret = "test" )
9596 monkeypatch .setattr (client , "get_all_pfs_info" , lambda : mock_sites )
96-
97+
9798 # Search far from the station
9899 results = client .search_by_location (51.5074 , - 0.1278 , radius_km = 1.0 )
99-
100+
100101 assert len (results ) == 0
101102
102103 def test_search_by_location_missing_coordinates (self , monkeypatch ):
@@ -122,11 +123,11 @@ def test_search_by_location_missing_coordinates(self, monkeypatch):
122123 ),
123124 ),
124125 ]
125-
126+
126127 client = FuelFinderClient (client_id = "test" , client_secret = "test" )
127128 monkeypatch .setattr (client , "get_all_pfs_info" , lambda : mock_sites )
128-
129+
129130 # Should not crash, just return empty results
130131 results = client .search_by_location (51.5074 , - 0.1278 , radius_km = 5.0 )
131-
132+
132133 assert len (results ) == 0
0 commit comments