Skip to content

Commit 3190bce

Browse files
committed
Use parametrize for tests
1 parent 4b0083b commit 3190bce

File tree

2 files changed

+81
-11
lines changed

2 files changed

+81
-11
lines changed

src/python_opensky/opensky.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ def get_bounding_box(
339339
south = OpenSky.calculate_point(latitude, longitude, radius, 180)
340340
west = OpenSky.calculate_point(latitude, longitude, radius, 270)
341341
return BoundingBox(
342-
min_latitude=min(north[0], south[0]) + latitude,
343-
max_latitude=max(north[0], south[0]) + latitude,
344-
min_longitude=min(east[1], west[1]) + longitude,
345-
max_longitude=max(east[1], west[1]) + longitude,
342+
min_latitude=min(north[0], south[0]),
343+
max_latitude=max(north[0], south[0]),
344+
min_longitude=min(east[1], west[1]),
345+
max_longitude=max(east[1], west[1]),
346346
)
347347

348348
async def close(self) -> None:

tests/test_radius.py

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,88 @@
11
"""Tests for the OpenSky Library."""
2-
2+
import pytest
3+
from _pytest.python_api import approx
34

45
from python_opensky import (
6+
BoundingBox,
57
OpenSky,
68
)
79

10+
PRECISION = 0.01
11+
812

9-
async def test_calculating_bounding_box() -> None:
13+
@pytest.mark.parametrize(
14+
("latitude", "longitude", "radius", "bounding_box"),
15+
[
16+
(
17+
0.0,
18+
0.0,
19+
111120,
20+
BoundingBox(
21+
min_latitude=-1.0,
22+
max_latitude=1.0,
23+
min_longitude=-1.0,
24+
max_longitude=1.0,
25+
),
26+
),
27+
# 180.0,
28+
# 0.0,
29+
# 111120,
30+
# BoundingBox(
31+
# ),
32+
# ),
33+
(
34+
360.0,
35+
0.0,
36+
111120,
37+
BoundingBox(
38+
min_latitude=-1.0,
39+
max_latitude=1.0,
40+
min_longitude=-1.0,
41+
max_longitude=1.0,
42+
),
43+
),
44+
(
45+
0.0,
46+
45.0,
47+
111120,
48+
BoundingBox(
49+
min_latitude=-1.0,
50+
max_latitude=1.0,
51+
min_longitude=44.0,
52+
max_longitude=46.0,
53+
),
54+
),
55+
(
56+
0.0,
57+
90.0,
58+
111120,
59+
BoundingBox(
60+
min_latitude=-1.0,
61+
max_latitude=1.0,
62+
min_longitude=89.0,
63+
max_longitude=91.0,
64+
),
65+
),
66+
],
67+
)
68+
async def test_calculating_bounding_box(
69+
latitude: float,
70+
longitude: float,
71+
radius: float,
72+
bounding_box: BoundingBox,
73+
) -> None:
1074
"""Test calculating bounding box."""
11-
bounding_box = OpenSky.get_bounding_box(0.0, 0.0, 25000)
12-
assert bounding_box.min_latitude == -0.22609235747829648
13-
assert bounding_box.max_latitude == 0.22609235747829648
14-
assert bounding_box.min_longitude == -0.22457882102988042
15-
assert bounding_box.max_longitude == 0.22457882102988042
75+
res_bounding_box = OpenSky.get_bounding_box(latitude, longitude, radius)
76+
assert res_bounding_box.min_latitude == approx(bounding_box.min_latitude, PRECISION)
77+
assert res_bounding_box.max_latitude == approx(bounding_box.max_latitude, PRECISION)
78+
assert res_bounding_box.min_longitude == approx(
79+
bounding_box.min_longitude,
80+
PRECISION,
81+
)
82+
assert res_bounding_box.max_longitude == approx(
83+
bounding_box.max_longitude,
84+
PRECISION,
85+
)
1686

1787

1888
async def test_calculating_direction() -> None:

0 commit comments

Comments
 (0)