File: test_radius.py

package info (click to toggle)
python-opensky 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: python: 859; sh: 5; makefile: 4
file content (91 lines) | stat: -rw-r--r-- 2,224 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Tests for the OpenSky Library."""

import pytest
from _pytest.python_api import approx

from python_opensky import (
    BoundingBox,
    OpenSky,
)

PRECISION = 0.01


@pytest.mark.parametrize(
    ("latitude", "longitude", "radius", "bounding_box"),
    [
        (
            0.0,
            0.0,
            111120,
            BoundingBox(
                min_latitude=-1.0,
                max_latitude=1.0,
                min_longitude=-1.0,
                max_longitude=1.0,
            ),
        ),
        (
            45.0,
            0.0,
            111120,
            BoundingBox(
                min_latitude=44.0,
                max_latitude=46.0,
                min_longitude=-1.4,
                max_longitude=1.438,
            ),
        ),
        (
            360.0,
            0.0,
            111120,
            BoundingBox(
                min_latitude=-1.0,
                max_latitude=1.0,
                min_longitude=-1.0,
                max_longitude=1.0,
            ),
        ),
        (
            0.0,
            45.0,
            111120,
            BoundingBox(
                min_latitude=-1.0,
                max_latitude=1.0,
                min_longitude=44.0,
                max_longitude=46.0,
            ),
        ),
        (
            0.0,
            90.0,
            111120,
            BoundingBox(
                min_latitude=-1.0,
                max_latitude=1.0,
                min_longitude=89.0,
                max_longitude=91.0,
            ),
        ),
    ],
)
async def test_calculating_bounding_box(
    latitude: float,
    longitude: float,
    radius: float,
    bounding_box: BoundingBox,
) -> None:
    """Test calculating bounding box."""
    res_bounding_box = OpenSky.get_bounding_box(latitude, longitude, radius)
    assert res_bounding_box.min_latitude == approx(bounding_box.min_latitude, PRECISION)
    assert res_bounding_box.max_latitude == approx(bounding_box.max_latitude, PRECISION)
    assert res_bounding_box.min_longitude == approx(
        bounding_box.min_longitude,
        PRECISION,
    )
    assert res_bounding_box.max_longitude == approx(
        bounding_box.max_longitude,
        PRECISION,
    )