Skip to content

Commit

Permalink
Merge c38a2bd into dba2704
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Nov 26, 2023
2 parents dba2704 + c38a2bd commit 093c022
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
37 changes: 36 additions & 1 deletion shapely/tests/geometry/test_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import shapely
from shapely import LinearRing, LineString, MultiLineString, Point, Polygon
from shapely.tests.common import all_types, all_types_z, ignore_invalid
from shapely.tests.common import all_types, all_types_z, empty_point, ignore_invalid

all_non_empty_types = np.array(all_types + all_types_z)[
~shapely.is_empty(all_types + all_types_z)
]


@pytest.mark.parametrize("geom", all_types + all_types_z)
Expand All @@ -14,6 +18,13 @@ def test_equality(geom):
assert not (geom != transformed)


@pytest.mark.parametrize("geom", all_non_empty_types)
def test_inequality(geom):
transformed = shapely.transform(geom, lambda x: x + 1)
assert geom != transformed
assert not (geom == transformed)


@pytest.mark.parametrize(
"left, right",
[
Expand Down Expand Up @@ -235,3 +246,27 @@ def test_comparison_not_supported():

with pytest.raises(TypeError, match="not supported between instances"):
geom1 <= geom2


@pytest.mark.parametrize(
"geom", all_types + (shapely.points(np.nan, np.nan), empty_point)
)
def test_hash_same_equal(geom):
hash1 = hash(geom)
hash2 = hash(shapely.transform(geom, lambda x: x))
if (
geom.is_empty
and shapely.get_num_geometries(geom) > 0
and geom.geom_type not in {"MultiPoint", "Point"}
and shapely.geos_version < (3, 9, 0)
):
# abnormal test for older GEOS version
assert hash1 != hash2, geom
else:
# normal test
assert hash1 == hash2, geom


@pytest.mark.parametrize("geom", all_non_empty_types)
def test_hash_same_not_equal(geom):
assert hash(geom) != hash(shapely.transform(geom, lambda x: x + 1))
34 changes: 0 additions & 34 deletions shapely/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,40 +232,6 @@ def test_adapt_ptr_raises():
point._geom += 1


@pytest.mark.parametrize(
"geom", all_types + (shapely.points(np.nan, np.nan), empty_point)
)
def test_hash_same_equal(geom):
hash1 = hash(geom)
hash2 = hash(shapely.transform(geom, lambda x: x))
if (
geom.is_empty
and shapely.get_num_geometries(geom) > 0
and geom.geom_type not in {"MultiPoint", "Point"}
and shapely.geos_version < (3, 9, 0)
):
# abnormal test for older GEOS version
assert hash1 != hash2, geom
else:
# normal test
assert hash1 == hash2, geom


@pytest.mark.parametrize("geom", all_non_empty_types)
def test_hash_same_not_equal(geom):
assert hash(geom) != hash(shapely.transform(geom, lambda x: x + 1))


@pytest.mark.parametrize("geom", all_types)
def test_eq(geom):
assert geom == shapely.transform(geom, lambda x: x)


@pytest.mark.parametrize("geom", all_non_empty_types)
def test_neq(geom):
assert geom != shapely.transform(geom, lambda x: x + 1)


@pytest.mark.parametrize("geom", all_types)
def test_set_unique(geom):
a = {geom, shapely.transform(geom, lambda x: x)}
Expand Down

0 comments on commit 093c022

Please sign in to comment.