Skip to content

Commit

Permalink
Add tests for geointerface of GeometryCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Oct 21, 2016
1 parent 4924e5a commit 6b52ae6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_collection.py
@@ -1,6 +1,8 @@
from . import unittest
from shapely.geometry import LineString
from shapely.geometry.collection import GeometryCollection
from shapely.geometry import shape
from shapely.geometry import asShape


class CollectionTestCase(unittest.TestCase):
Expand All @@ -24,6 +26,43 @@ def test_child_with_deleted_parent(self):
# access geometry, this should not seg fault as 1.2.15 did
self.assertIsNotNone(child.wkt)

def test_geointerface(self):
d = {"type": "GeometryCollection","geometries": [
{"type": "Point", "coordinates": (0, 3)},
{"type": "LineString", "coordinates": ((2, 0), (1, 0))}
]}

# asShape
m = asShape(d)
self.assertEqual(m.geom_type, "GeometryCollection")
self.assertEqual(len(m), 2)
geom_types = [g.geom_type for g in m.geoms]
self.assertIn("Point", geom_types)
self.assertIn("LineString", geom_types)

# shape
m = shape(d)
self.assertEqual(m.geom_type, "GeometryCollection")
self.assertEqual(len(m), 2)
geom_types = [g.geom_type for g in m.geoms]
self.assertIn("Point", geom_types)
self.assertIn("LineString", geom_types)

def test_empty_geointerface(self):
d = {"type": "GeometryCollection", "geometries": []}

# asShape
m = asShape(d)
self.assertEqual(m.geom_type, "GeometryCollection")
self.assertEqual(len(m), 0)
self.assertEqual(m.geoms, [])

# shape
m = shape(d)
self.assertEqual(m.geom_type, "GeometryCollection")
self.assertEqual(len(m), 0)
self.assertEqual(m.geoms, [])


def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(CollectionTestCase)

0 comments on commit 6b52ae6

Please sign in to comment.