summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2015-11-24 14:21:32 +0500
committerTim Graham <timograham@gmail.com>2015-12-14 13:29:38 -0500
commit5146e2cf984a83c2eb9d8102ea73ee0792a9528b (patch)
treeb464f59550d16d03a227eed0aab7adeb6dbcfca9 /tests
parent8035cee92293f3319919c8248c7787ba43c05917 (diff)
Fixed #25662 -- Allowed creation of empty GEOS geometries.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py57
-rw-r--r--tests/gis_tests/geos_tests/test_mutable_list.py8
2 files changed, 52 insertions, 13 deletions
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index da9db06c33..fd08e3037a 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -793,6 +793,9 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
p[:] = (1, 2, 3)
self.assertEqual(p, Point(1, 2, 3))
+ p[:] = ()
+ self.assertEqual(p.wkt, Point())
+
p[:] = (1, 2)
self.assertEqual(p.wkt, Point(1, 2))
@@ -804,6 +807,9 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
def test_linestring_list_assignment(self):
ls = LineString((0, 0), (1, 1))
+ ls[:] = ()
+ self.assertEqual(ls, LineString())
+
ls[:] = ((0, 0), (1, 1), (2, 2))
self.assertEqual(ls, LineString((0, 0), (1, 1), (2, 2)))
@@ -813,12 +819,34 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
def test_linearring_list_assignment(self):
ls = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))
+ ls[:] = ()
+ self.assertEqual(ls, LinearRing())
+
ls[:] = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
self.assertEqual(ls, LinearRing((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)))
with self.assertRaises(ValueError):
ls[:] = ((0, 0), (1, 1), (2, 2))
+ def test_polygon_list_assignment(self):
+ pol = Polygon()
+
+ pol[:] = (((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)),)
+ self.assertEqual(pol, Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)),))
+
+ pol[:] = ()
+ self.assertEqual(pol, Polygon())
+
+ def test_geometry_collection_list_assignment(self):
+ p = Point()
+ gc = GeometryCollection()
+
+ gc[:] = [p]
+ self.assertEqual(gc, GeometryCollection(p))
+
+ gc[:] = ()
+ self.assertEqual(gc, GeometryCollection())
+
def test_threed(self):
"Testing three-dimensional geometries."
# Testing a 3D Point
@@ -874,16 +902,27 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
def test_emptyCollections(self):
"Testing empty geometries and collections."
- gc1 = GeometryCollection([])
- gc2 = fromstr('GEOMETRYCOLLECTION EMPTY')
- pnt = fromstr('POINT EMPTY')
- ls = fromstr('LINESTRING EMPTY')
- poly = fromstr('POLYGON EMPTY')
- mls = fromstr('MULTILINESTRING EMPTY')
- mpoly1 = fromstr('MULTIPOLYGON EMPTY')
- mpoly2 = MultiPolygon(())
+ geoms = [
+ GeometryCollection([]),
+ fromstr('GEOMETRYCOLLECTION EMPTY'),
+ GeometryCollection(),
+ fromstr('POINT EMPTY'),
+ Point(),
+ fromstr('LINESTRING EMPTY'),
+ LineString(),
+ fromstr('POLYGON EMPTY'),
+ Polygon(),
+ fromstr('MULTILINESTRING EMPTY'),
+ MultiLineString(),
+ fromstr('MULTIPOLYGON EMPTY'),
+ MultiPolygon(()),
+ MultiPolygon(),
+ ]
+
+ if numpy:
+ geoms.append(LineString(numpy.array([])))
- for g in [gc1, gc2, pnt, ls, poly, mls, mpoly1, mpoly2]:
+ for g in geoms:
self.assertEqual(True, g.empty)
# Testing len() and num_geom.
diff --git a/tests/gis_tests/geos_tests/test_mutable_list.py b/tests/gis_tests/geos_tests/test_mutable_list.py
index 67338ee865..8f2242ea31 100644
--- a/tests/gis_tests/geos_tests/test_mutable_list.py
+++ b/tests/gis_tests/geos_tests/test_mutable_list.py
@@ -299,18 +299,18 @@ class ListMixinTest(unittest.TestCase):
def test08_min_length(self):
'Length limits'
- pl, ul = self.lists_of_len()
- ul._minlength = 1
+ pl, ul = self.lists_of_len(5)
+ ul._minlength = 3
def delfcn(x, i):
del x[:i]
def setfcn(x, i):
x[:i] = []
- for i in range(self.limit - ul._minlength + 1, self.limit + 1):
+ for i in range(len(ul) - ul._minlength + 1, len(ul)):
self.assertRaises(ValueError, delfcn, ul, i)
self.assertRaises(ValueError, setfcn, ul, i)
- del ul[:ul._minlength]
+ del ul[:len(ul) - ul._minlength]
ul._maxlength = 4
for i in range(0, ul._maxlength - len(ul)):