Skip to content

Commit

Permalink
Tests for polygons missing inner or outer boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Jan 29, 2024
1 parent 1c6e51d commit 5839fe3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 0 additions & 2 deletions fastkml/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def _etree_coordinates(
Element,
config.etree.Element(f"{self.ns}coordinates"), # type: ignore[attr-defined]
)
if not coordinates:
return element
if len(coordinates[0]) == 2:
tuples = (f"{c[0]:f},{c[1]:f}" for c in coordinates)
elif len(coordinates[0]) == 3:
Expand Down
10 changes: 10 additions & 0 deletions tests/geometries/point_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ def test_from_string_invalid_coordinates_non_numerical(self) -> None:
ns="",
)

def test_from_string_invalid_coordinates_nan(self) -> None:
with pytest.raises(
KMLParseError,
match=(r"^Invalid coordinates in"),
):
Point.class_from_string(
"<Point><coordinates>a,b</coordinates></Point>",
ns="",
)


class TestPointLxml(Lxml, TestPoint):
"""Test with lxml."""
30 changes: 30 additions & 0 deletions tests/geometries/polygon_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ def test_from_string_interiors_only(self) -> None:
with pytest.raises(KMLParseError, match=r"^Missing outerBoundaryIs in <"):
Polygon.class_from_string(doc)

def test_from_string_exterior_wo_linearring(self) -> None:
"""Test exterior when no LinearRing in outer boundary."""
doc = """<kml:Polygon xmlns:kml="http://www.opengis.net/kml/2.2">
<kml:outerBoundaryIs>
<kml:coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000
0.000000,0.000000</kml:coordinates>
</kml:outerBoundaryIs>
</kml:Polygon>"""

with pytest.raises(KMLParseError, match=r"^Missing LinearRing in <"):
Polygon.class_from_string(doc)

def test_from_string_interior_wo_linearring(self) -> None:
"""Test interior when no LinearRing in inner boundary."""
doc = """<kml:Polygon xmlns:kml="http://www.opengis.net/kml/2.2">
<kml:outerBoundaryIs>
<kml:LinearRing>
<kml:coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000
0.000000,0.000000</kml:coordinates>
</kml:LinearRing>
</kml:outerBoundaryIs>
<kml:innerBoundaryIs>
<kml:coordinates>0.000000,0.000000 1.000000,0.000000 1.000000,1.000000
0.000000,0.000000</kml:coordinates>
</kml:innerBoundaryIs>
</kml:Polygon>"""

with pytest.raises(KMLParseError, match=r"^Missing LinearRing in <"):
Polygon.class_from_string(doc)

def test_from_string_exterior_interior(self) -> None:
doc = """<kml:Polygon xmlns:kml="http://www.opengis.net/kml/2.2">
<kml:outerBoundaryIs>
Expand Down

0 comments on commit 5839fe3

Please sign in to comment.