Skip to content

Commit

Permalink
full coverage for geometry.py with minimal tests (#53)
Browse files Browse the repository at this point in the history
* proper snap targets warning test

* full coverage geometry - #52

* martin comment
  • Loading branch information
jGaboardi authored Oct 20, 2024
1 parent 95b0aa3 commit 8d82df6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ exclude_lines = [
]
ignore_errors = true
omit = ["sgeop/tests/*"]

[tool.pytest.ini_options]
filterwarnings = [
# this is an internal warning thrown within ``sgeop.geometry.snap_to_targets()``
'ignore:Could not create a connection*:UserWarning',
]
56 changes: 56 additions & 0 deletions sgeop/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,59 @@ def test_split_add():
observed_splits, observed_adds = sgeop.geometry._split_add(sl, [], [])
assert observed_splits == known_splits
assert observed_adds == known_adds


class TestSnapToTargets:
def setup_method(self):
# edgelines
line1 = shapely.LineString(((100, 100), (1000, 100)))
line2 = shapely.LineString(((1000, 100), (1000, 1000)))
line3 = shapely.LineString(((100, 100), (100, 1000)))
line4 = shapely.LineString(((100, 1000), (1000, 1000)))
self.lines = [line1, line2, line3, line4]

# poly
self.poly = shapely.polygonize(self.lines).buffer(0)

# snap_to
self.snap_to_1 = (
geopandas.GeoSeries(self.lines)
.polygonize()
.extract_unique_points()
.explode()
)

def test_warn(self):
with pytest.warns(
UserWarning,
match=(
"Could not create a connection as it would "
"lead outside of the artifact."
),
):
sgeop.geometry.snap_to_targets(
self.lines,
self.poly,
snap_to=self.snap_to_1,
)

def test_secondary(self):
known = ([None], [None])

line1_b = shapely.LineString(((500, 500), (1500, 500)))
line2_b = shapely.LineString(((1500, 500), (1500, 1500)))
line3_b = shapely.LineString(((500, 500), (500, 1500)))
line4_b = shapely.LineString(((500, 1500), (1500, 1500)))
lines_b = [line1_b, line2_b, line3_b, line4_b]
snap_to_2 = (
geopandas.GeoSeries(lines_b).polygonize().extract_unique_points().explode()
)

observed = sgeop.geometry.snap_to_targets(
self.lines + lines_b,
self.poly,
snap_to=self.snap_to_1,
secondary_snap_to=snap_to_2,
)

assert observed == known

0 comments on commit 8d82df6

Please sign in to comment.