summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas NoƩ <nicolas@niconoe.eu>2016-05-11 11:29:16 +0200
committerTim Graham <timograham@gmail.com>2016-05-13 11:30:19 -0400
commite158ec0ba0b43cbe9b509d4ed5587fa3b2ae3cc6 (patch)
tree3f428824cc5ccef75070d0c48fde072b33003825
parent32dc8c0beb100aa1eae480aa24ead7200668c0f4 (diff)
Fixed #26333 -- Made GIS Geometry classes deconstructible.
-rw-r--r--django/contrib/gis/geos/geometry.py2
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py65
2 files changed, 67 insertions, 0 deletions
diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
index 99e680e492..c48e99cd5b 100644
--- a/django/contrib/gis/geos/geometry.py
+++ b/django/contrib/gis/geos/geometry.py
@@ -21,10 +21,12 @@ from django.contrib.gis.geos.prototypes.io import (
ewkb_w, wkb_r, wkb_w, wkt_r, wkt_w,
)
from django.utils import six
+from django.utils.deconstruct import deconstructible
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_bytes, force_text
+@deconstructible
class GEOSGeometry(GEOSBase, ListMixin):
"A class that, generally, encapsulates a GEOS geometry."
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 6c32835237..02943baf0d 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -1246,6 +1246,71 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertEqual(mls.interpolate(9), Point(0, 9))
self.assertEqual(mls.interpolate(17), Point(10, 7))
+ def test_deconstructible(self):
+ """
+ Geometry classes should be deconstructible.
+ """
+ point = Point(4.337844, 50.827537, srid=4326)
+ path, args, kwargs = point.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.point.Point')
+ self.assertEqual(args, (4.337844, 50.827537))
+ self.assertEqual(kwargs, {'srid': 4326})
+
+ ls = LineString(((0, 0), (1, 1)))
+ path, args, kwargs = ls.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.linestring.LineString')
+ self.assertEqual(args, (((0, 0), (1, 1))))
+ self.assertEqual(kwargs, {})
+
+ ls2 = LineString([Point(0, 0), Point(1, 1)], srid=4326)
+ path, args, kwargs = ls2.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.linestring.LineString')
+ self.assertEqual(args, ([Point(0, 0), Point(1, 1)]))
+ self.assertEqual(kwargs, {'srid': 4326})
+
+ ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
+ int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 0.4))
+ poly = Polygon(ext_coords, int_coords)
+ path, args, kwargs = poly.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.polygon.Polygon')
+ self.assertEqual(args, (ext_coords, int_coords))
+ self.assertEqual(kwargs, {})
+
+ lr = LinearRing((0, 0), (0, 1), (1, 1), (0, 0))
+ path, args, kwargs = lr.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.linestring.LinearRing')
+ self.assertEqual(args, ((0, 0), (0, 1), (1, 1), (0, 0)))
+ self.assertEqual(kwargs, {})
+
+ mp = MultiPoint(Point(0, 0), Point(1, 1))
+ path, args, kwargs = mp.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.collections.MultiPoint')
+ self.assertEqual(args, (Point(0, 0), Point(1, 1)))
+ self.assertEqual(kwargs, {})
+
+ ls1 = LineString((0, 0), (1, 1))
+ ls2 = LineString((2, 2), (3, 3))
+ mls = MultiLineString(ls1, ls2)
+ path, args, kwargs = mls.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.collections.MultiLineString')
+ self.assertEqual(args, (ls1, ls2))
+ self.assertEqual(kwargs, {})
+
+ p1 = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
+ p2 = Polygon(((1, 1), (1, 2), (2, 2), (1, 1)))
+ mp = MultiPolygon(p1, p2)
+ path, args, kwargs = mp.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.collections.MultiPolygon')
+ self.assertEqual(args, (p1, p2, ))
+ self.assertEqual(kwargs, {})
+
+ poly = Polygon(((0, 0), (0, 1), (1, 1), (0, 0)))
+ gc = GeometryCollection(Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly)
+ path, args, kwargs = gc.deconstruct()
+ self.assertEqual(path, 'django.contrib.gis.geos.collections.GeometryCollection')
+ self.assertEqual(args, (Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly))
+ self.assertEqual(kwargs, {})
+
def test_geos_version(self):
"""Testing the GEOS version regular expression."""
from django.contrib.gis.geos.libgeos import version_regex