Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full coverage for geometry.py with minimal tests #53

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
jGaboardi marked this conversation as resolved.
Show resolved Hide resolved
]
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