Skip to content

Commit 346917a

Browse files
authored
Merge pull request #38 from joostlek/testing
Use parametrize for tests
2 parents 4b0083b + eaf7940 commit 346917a

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-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: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,82 @@
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+
(
28+
360.0,
29+
0.0,
30+
111120,
31+
BoundingBox(
32+
min_latitude=-1.0,
33+
max_latitude=1.0,
34+
min_longitude=-1.0,
35+
max_longitude=1.0,
36+
),
37+
),
38+
(
39+
0.0,
40+
45.0,
41+
111120,
42+
BoundingBox(
43+
min_latitude=-1.0,
44+
max_latitude=1.0,
45+
min_longitude=44.0,
46+
max_longitude=46.0,
47+
),
48+
),
49+
(
50+
0.0,
51+
90.0,
52+
111120,
53+
BoundingBox(
54+
min_latitude=-1.0,
55+
max_latitude=1.0,
56+
min_longitude=89.0,
57+
max_longitude=91.0,
58+
),
59+
),
60+
],
61+
)
62+
async def test_calculating_bounding_box(
63+
latitude: float,
64+
longitude: float,
65+
radius: float,
66+
bounding_box: BoundingBox,
67+
) -> None:
1068
"""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
69+
res_bounding_box = OpenSky.get_bounding_box(latitude, longitude, radius)
70+
assert res_bounding_box.min_latitude == approx(bounding_box.min_latitude, PRECISION)
71+
assert res_bounding_box.max_latitude == approx(bounding_box.max_latitude, PRECISION)
72+
assert res_bounding_box.min_longitude == approx(
73+
bounding_box.min_longitude,
74+
PRECISION,
75+
)
76+
assert res_bounding_box.max_longitude == approx(
77+
bounding_box.max_longitude,
78+
PRECISION,
79+
)
1680

1781

1882
async def test_calculating_direction() -> None:

0 commit comments

Comments
 (0)