Skip to content

Commit bc57b1b

Browse files
committed
test: add test coverage for GeneralizePoints
1 parent 63e137d commit bc57b1b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/geogenalg/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
)
2626
from geogenalg.application.generalize_fences import GeneralizeFences
2727
from geogenalg.application.generalize_landcover import GeneralizeLandcover
28-
from geogenalg.application.generalize_shoreline import GeneralizeShoreline
2928
from geogenalg.application.generalize_points import GeneralizePoints
29+
from geogenalg.application.generalize_shoreline import GeneralizeShoreline
3030
from geogenalg.utility.dataframe_processing import read_gdf_from_file_and_set_index
3131

3232
GEOPACKAGE_URI_HELP = (

test/application/test_generalize_points.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
# LICENSE file in the root directory of this source tree.
77

88
import geopandas as gpd
9+
import pytest
910
from pandas.testing import assert_frame_equal
10-
from shapely import Point, equals_exact
11+
from shapely import LineString, Point, equals_exact
1112

1213
from geogenalg.application.generalize_points import GeneralizePoints
14+
from geogenalg.core.exceptions import GeometryTypeError
1315

1416

1517
def test_generalize_points() -> None:
@@ -91,3 +93,28 @@ def test_generalize_points() -> None:
9193
result_attrs = result_gdf.drop(columns="geometry").reset_index(drop=True)
9294
expected_attrs = expected_gdf.drop(columns="geometry").reset_index(drop=True)
9395
assert_frame_equal(result_attrs, expected_attrs)
96+
97+
98+
def test_generalize_points_invalid_geometry_type():
99+
algorithm = GeneralizePoints(
100+
reduce_threshold=0.5,
101+
displace_threshold=3,
102+
displace_points_iterations=10,
103+
unique_key_column="id",
104+
cluster_members_column="cluster_members",
105+
)
106+
107+
input_data = gpd.GeoDataFrame(
108+
{
109+
"id": [1, 2],
110+
},
111+
geometry=[
112+
LineString([Point(0.5, 0.5), Point(1.0, 1.0)]),
113+
LineString([Point(2.0, 2.0), Point(2.5, 2.5)]),
114+
],
115+
)
116+
117+
with pytest.raises(
118+
GeometryTypeError, match=r"GeneralizePoints works only with Point geometries."
119+
):
120+
algorithm.execute(input_data, {})

0 commit comments

Comments
 (0)