Skip to content

Commit 83d4448

Browse files
authored
Remove non async methods (#69)
* Remove non async methods * More cleanup / updated tests * Use annotation for tests * Add pytest-asyncio dependency * await * Marked def with `async` * Bump version
1 parent 5ae0dd2 commit 83d4448

12 files changed

+76
-367
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ install_requires =
2626
protobuf == 4.21.12
2727
test_require =
2828
pytest
29+
pytest-asyncio
2930

3031
[flake8]
3132
per-file-ignores = __init__.py:F401

tests/geocoding_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
def test_geocoding_search(sdk):
2-
response = sdk.geocoding(
1+
import pytest
2+
3+
4+
@pytest.mark.asyncio
5+
async def test_geocoding_search(sdk):
6+
response = await sdk.geocoding_async(
37
query="Parliament square", limit=30, within_countries=["gb", "de"]
48
)
59
assert len(response.features) > 0
610
assert len(response.features) < 31
711

812

9-
def test_geocoding_reverse(sdk):
10-
response = sdk.geocoding_reverse(lat=51.507281, lng=-0.132120)
13+
@pytest.mark.asyncio
14+
async def test_geocoding_reverse(sdk):
15+
response = await sdk.geocoding_reverse_async(lat=51.507281, lng=-0.132120)
1116
assert len(response.features) > 0

tests/map_info_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
def test_map_info(sdk):
2-
maps = sdk.map_info()
1+
import pytest
2+
3+
4+
@pytest.mark.asyncio
5+
async def test_map_info(sdk):
6+
maps = await sdk.map_info_async()
37
assert len(maps) > 0

tests/postcodes_test.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
1+
import pytest
12
from datetime import datetime
23

34
from traveltimepy import Coordinates, PublicTransport
45

56

6-
def test_departures(sdk):
7-
results = sdk.postcodes(
7+
@pytest.mark.asyncio
8+
async def test_departures(sdk):
9+
results = await sdk.postcodes_async(
810
coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
911
departure_time=datetime.now(),
1012
transportation=PublicTransport(),
1113
)
1214
assert len(results) > 0
1315

1416

15-
def test_arrivals(sdk):
16-
results = sdk.postcodes(
17+
@pytest.mark.asyncio
18+
async def test_arrivals(sdk):
19+
results = await sdk.postcodes_async(
1720
coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
1821
arrival_time=datetime.now(),
1922
transportation=PublicTransport(),
2023
)
2124
assert len(results) > 0
2225

2326

24-
def test_districts_departure(sdk):
25-
results = sdk.postcode_districts(
27+
@pytest.mark.asyncio
28+
async def test_districts_departure(sdk):
29+
results = await sdk.postcodes_districts_async(
2630
coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
2731
departure_time=datetime.now(),
2832
transportation=PublicTransport(),
2933
)
3034
assert len(results) > 0
3135

3236

33-
def test_districts_arrival(sdk):
34-
results = sdk.postcode_districts(
37+
@pytest.mark.asyncio
38+
async def test_districts_arrival(sdk):
39+
results = await sdk.postcodes_districts_async(
3540
coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
3641
arrival_time=datetime.now(),
3742
transportation=PublicTransport(),
3843
)
3944
assert len(results) > 0
4045

4146

42-
def test_sectors_departure(sdk):
43-
results = sdk.postcode_sectors(
47+
@pytest.mark.asyncio
48+
async def test_sectors_departure(sdk):
49+
results = await sdk.postcodes_sectors_async(
4450
coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
4551
departure_time=datetime.now(),
4652
transportation=PublicTransport(),
4753
)
4854
assert len(results) > 0
4955

5056

51-
def test_sectors_arrival(sdk):
52-
results = sdk.postcode_sectors(
57+
@pytest.mark.asyncio
58+
async def test_sectors_arrival(sdk):
59+
results = await sdk.postcodes_sectors_async(
5360
coordinates=[Coordinates(lat=51.507609, lng=-0.128315)],
5461
arrival_time=datetime.now(),
5562
transportation=PublicTransport(),

tests/routes_test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import pytest
12
from datetime import datetime
23

34
from traveltimepy import PublicTransport
45

56

6-
def test_departures(sdk, locations):
7-
results = sdk.routes(
7+
@pytest.mark.asyncio
8+
async def test_departures(sdk, locations):
9+
results = await sdk.routes_async(
810
locations=locations,
911
search_ids={
1012
"London center": ["Hyde Park", "ZSL London Zoo"],
@@ -16,8 +18,9 @@ def test_departures(sdk, locations):
1618
assert len(results) == 2
1719

1820

19-
def test_arrivals(sdk, locations):
20-
results = sdk.routes(
21+
@pytest.mark.asyncio
22+
async def test_arrivals(sdk, locations):
23+
results = await sdk.routes_async(
2124
locations=locations,
2225
search_ids={
2326
"London center": ["Hyde Park", "ZSL London Zoo"],

tests/supported_locations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import pytest
2+
13
from traveltimepy import Location, Coordinates
24

35

4-
def test_supported_locations(sdk):
6+
@pytest.mark.asyncio
7+
async def test_supported_locations(sdk):
58
locations = [
69
Location(id="Kaunas", coords=Coordinates(lat=54.900008, lng=23.957734)),
710
Location(id="London", coords=Coordinates(lat=51.506756, lng=-0.12805)),
811
Location(id="Bangkok", coords=Coordinates(lat=13.761866, lng=100.544818)),
912
Location(id="Lisbon", coords=Coordinates(lat=38.721869, lng=-9.138549)),
1013
Location(id="Unsupported", coords=Coordinates(lat=68.721869, lng=-9.138549)),
1114
]
12-
response = sdk.supported_locations(locations)
15+
response = await sdk.supported_locations_async(locations)
1316
assert len(response.locations) == 4
1417
assert len(response.unsupported_locations) == 1

tests/time_filter_fast_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import pytest
2+
13
from traveltimepy.dto.requests.time_filter_fast import Transportation
24

35

4-
def test_one_to_many(sdk, locations):
5-
results = sdk.time_filter_fast(
6+
@pytest.mark.asyncio
7+
async def test_one_to_many(sdk, locations):
8+
results = await sdk.time_filter_fast_async(
69
locations=locations,
710
search_ids={
811
"London center": ["Hyde Park", "ZSL London Zoo"],
@@ -14,8 +17,9 @@ def test_one_to_many(sdk, locations):
1417
assert len(results) > 0
1518

1619

17-
def test_many_to_one(sdk, locations):
18-
results = sdk.time_filter_fast(
20+
@pytest.mark.asyncio
21+
async def test_many_to_one(sdk, locations):
22+
results = await sdk.time_filter_fast_async(
1923
locations=locations,
2024
search_ids={
2125
"London center": ["Hyde Park", "ZSL London Zoo"],

tests/time_filter_test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import pytest
12
from datetime import datetime
23

34
from traveltimepy import PublicTransport
45

56

6-
def test_departures(sdk, locations):
7-
results = sdk.time_filter(
7+
@pytest.mark.asyncio
8+
async def test_departures(sdk, locations):
9+
results = await sdk.time_filter_async(
810
locations=locations,
911
search_ids={
1012
"London center": ["Hyde Park", "ZSL London Zoo"],
@@ -16,8 +18,9 @@ def test_departures(sdk, locations):
1618
assert len(results) == 2
1719

1820

19-
def test_arrivals(sdk, locations):
20-
results = sdk.time_filter(
21+
@pytest.mark.asyncio
22+
async def test_arrivals(sdk, locations):
23+
results = await sdk.time_filter_async(
2124
locations=locations,
2225
search_ids={
2326
"London center": ["Hyde Park", "ZSL London Zoo"],

tests/time_map_test.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import pytest
12
from datetime import datetime
23

34
from traveltimepy import Coordinates, Driving
45

56

6-
def test_departures(sdk):
7-
results = sdk.time_map(
7+
@pytest.mark.asyncio
8+
async def test_departures(sdk):
9+
results = await sdk.time_map_async(
810
coordinates=[
911
Coordinates(lat=51.507609, lng=-0.128315),
1012
Coordinates(lat=51.517609, lng=-0.138315),
@@ -16,8 +18,9 @@ def test_departures(sdk):
1618
assert len(results) == 2
1719

1820

19-
def test_arrivals(sdk):
20-
results = sdk.time_map(
21+
@pytest.mark.asyncio
22+
async def test_arrivals(sdk):
23+
results = await sdk.time_map_async(
2124
coordinates=[
2225
Coordinates(lat=51.507609, lng=-0.128315),
2326
Coordinates(lat=51.517609, lng=-0.138315),
@@ -29,8 +32,9 @@ def test_arrivals(sdk):
2932
assert len(results) == 2
3033

3134

32-
def test_union_departures(sdk):
33-
result = sdk.union(
35+
@pytest.mark.asyncio
36+
async def test_union_departures(sdk):
37+
result = await sdk.union_async(
3438
coordinates=[
3539
Coordinates(lat=51.507609, lng=-0.128315),
3640
Coordinates(lat=51.517609, lng=-0.138315),
@@ -42,8 +46,9 @@ def test_union_departures(sdk):
4246
assert len(result.shapes) > 0
4347

4448

45-
def test_intersection_arrivals(sdk):
46-
result = sdk.intersection(
49+
@pytest.mark.asyncio
50+
async def test_intersection_arrivals(sdk):
51+
result = await sdk.intersection_async(
4752
coordinates=[
4853
Coordinates(lat=51.507609, lng=-0.128315),
4954
Coordinates(lat=51.517609, lng=-0.138315),

traveltimepy/http.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,6 @@ def _window_size(rate_limit: int):
7777
return rate_limit
7878

7979

80-
def send_post(
81-
response_class: Type[T],
82-
path: str,
83-
headers: Dict[str, str],
84-
request: TravelTimeRequest,
85-
sdk_params: SdkParams,
86-
) -> T:
87-
return asyncio.run(
88-
send_post_async(response_class, path, headers, request, sdk_params)
89-
)
90-
91-
9280
async def send_get_async(
9381
response_class: Type[T],
9482
path: str,
@@ -109,18 +97,6 @@ async def send_get_async(
10997
return await _process_response(response_class, resp)
11098

11199

112-
def send_get(
113-
response_class: Type[T],
114-
path: str,
115-
headers: Dict[str, str],
116-
sdk_params: SdkParams,
117-
params: Dict[str, str] = None,
118-
) -> T:
119-
return asyncio.run(
120-
send_get_async(response_class, path, headers, sdk_params, params)
121-
)
122-
123-
124100
async def _process_response(response_class: Type[T], response: ClientResponse) -> T:
125101
text = await response.text()
126102
if response.status != 200:

0 commit comments

Comments
 (0)