File: test_hash.py

package info (click to toggle)
python-shapely 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,528 kB
  • sloc: python: 18,648; ansic: 6,615; makefile: 88; sh: 62
file content (28 lines) | stat: -rw-r--r-- 673 bytes parent folder | download | duplicates (3)
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
import pytest

import shapely
from shapely.affinity import translate
from shapely.geometry import GeometryCollection, LineString, MultiPoint, Point


@pytest.mark.parametrize(
    "geom",
    [
        Point(1, 2),
        MultiPoint([(1, 2), (3, 4)]),
        LineString([(1, 2), (3, 4)]),
        Point(0, 0).buffer(1.0),
        GeometryCollection([Point(1, 2), LineString([(1, 2), (3, 4)])]),
    ],
    ids=[
        "Point",
        "MultiPoint",
        "LineString",
        "Polygon",
        "GeometryCollection",
    ],
)
def test_hash(geom):
    h1 = hash(geom)
    assert h1 == hash(shapely.from_wkb(geom.wkb))
    assert h1 != hash(translate(geom, 1.0, 2.0))