File: test_geometries.py

package info (click to toggle)
python-georss-client 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 320 kB
  • sloc: python: 1,582; xml: 430; makefile: 8; sh: 5
file content (61 lines) | stat: -rw-r--r-- 1,466 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
"""Test geometries."""

from georss_client.xml_parser.geometry import Point, Polygon


def test_point():
    """Test point."""
    point = Point(-37.1234, 149.2345)
    assert point.latitude == -37.1234
    assert point.longitude == 149.2345
    assert repr(point) == "<Point(latitude=-37.1234, longitude=149.2345)>"


def test_point_equality():
    """Test points."""
    point1 = Point(10.0, 15.0)
    point2 = Point(10.0, 15.0)
    assert point1 == point2


def test_polygon():
    """Test polygon."""
    polygon = Polygon(
        [
            Point(-30.1, 150.1),
            Point(-30.2, 150.2),
            Point(-30.4, 150.4),
            Point(-30.8, 150.8),
            Point(-30.1, 150.1),
        ]
    )
    assert len(polygon.points) == 5
    assert polygon.centroid.latitude == -30.32
    assert polygon.centroid.longitude == 150.32
    assert (
        repr(polygon) == "<Polygon(centroid="
        "<Point(latitude=-30.32, longitude=150.32)>)>"
    )


def test_polygon_equality():
    """Test points."""
    polygon1 = Polygon(
        [
            Point(30.0, 30.0),
            Point(30.0, 35.0),
            Point(35.0, 35.0),
            Point(35.0, 30.0),
            Point(30.0, 30.0),
        ]
    )
    polygon2 = Polygon(
        [
            Point(30.0, 30.0),
            Point(30.0, 35.0),
            Point(35.0, 35.0),
            Point(35.0, 30.0),
            Point(30.0, 30.0),
        ]
    )
    assert polygon1 == polygon2