Skip to content

Commit

Permalink
Test empty MultiGeometries fixes #221
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Oct 15, 2023
1 parent c65d97f commit 0ccb523
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fastkml/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ def etree_element(
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
assert isinstance(self.geometry, geo._MultiGeometry)
_map_to_kml = {mg: self.__class__ for mg in self.multi_geometries}
_map_to_kml.update(self.map_to_kml)

if self.geometry is None:
return element
for geometry in self.geometry.geoms:
geometry_class = _map_to_kml[type(geometry)]
element.append(
Expand Down
12 changes: 12 additions & 0 deletions tests/geometries/multigeometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ def test_multi_geometries_read(self) -> None:
)
)

def test_empty_multi_geometries_read(self) -> None:
xml = (
"<MultiGeometry><extrude>0</extrude><tessellate>0</tessellate>"
"<MultiGeometry></MultiGeometry></MultiGeometry>"
)

mg = MultiGeometry.class_from_string(xml, ns="")

assert mg.geometry is None
assert "MultiGeometry>" in mg.to_string()
assert "coordinates>" not in mg.to_string()


class TestMultiPointLxml(Lxml, TestMultiPointStdLibrary):
"""Test with lxml."""
Expand Down

0 comments on commit 0ccb523

Please sign in to comment.