test_hash.py 673 B

12345678910111213141516171819202122232425262728
  1. import pytest
  2. import shapely
  3. from shapely.affinity import translate
  4. from shapely.geometry import GeometryCollection, LineString, MultiPoint, Point
  5. @pytest.mark.parametrize(
  6. "geom",
  7. [
  8. Point(1, 2),
  9. MultiPoint([(1, 2), (3, 4)]),
  10. LineString([(1, 2), (3, 4)]),
  11. Point(0, 0).buffer(1.0),
  12. GeometryCollection([Point(1, 2), LineString([(1, 2), (3, 4)])]),
  13. ],
  14. ids=[
  15. "Point",
  16. "MultiPoint",
  17. "LineString",
  18. "Polygon",
  19. "GeometryCollection",
  20. ],
  21. )
  22. def test_hash(geom):
  23. h1 = hash(geom)
  24. assert h1 == hash(shapely.from_wkb(geom.wkb))
  25. assert h1 != hash(translate(geom, 1.0, 2.0))