summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-11-30 12:33:58 +0100
committerClaude Paroz <claude@2xlibre.net>2016-11-30 17:49:41 +0100
commitcc9e4297019bcec9fe0fee2199aa30fb1f6e90b7 (patch)
tree8de0a88688b81a555c15fe686a407f8a7ca727ad /tests
parent4464b9b9ad9da921f8b50b4e7e26bb4233e05ca0 (diff)
Fixed #27557 -- Casted GEOSGeometry only when necessary
Thanks Pete Flugstad for the report, and Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 544bd3f48f..9bb55a1b4d 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -1308,6 +1308,25 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
self.assertEqual(args, (Point(0, 0), MultiPoint(Point(0, 0), Point(1, 1)), poly))
self.assertEqual(kwargs, {})
+ def test_subclassing(self):
+ """
+ GEOSGeometry subclass may itself be subclassed without being forced-cast
+ to the parent class during `__init__`.
+ """
+ class ExtendedPolygon(Polygon):
+ def __init__(self, *args, **kwargs):
+ data = kwargs.pop('data', 0)
+ super(ExtendedPolygon, self).__init__(*args, **kwargs)
+ self._data = data
+
+ def __str__(self):
+ return "EXT_POLYGON - data: %d - %s" % (self._data, self.wkt)
+
+ ext_poly = ExtendedPolygon(((0, 0), (0, 1), (1, 1), (0, 0)), data=3)
+ self.assertEqual(type(ext_poly), ExtendedPolygon)
+ # ExtendedPolygon.__str__ should be called (instead of Polygon.__str__).
+ self.assertEqual(str(ext_poly), "EXT_POLYGON - data: 3 - POLYGON ((0 0, 0 1, 1 1, 0 0))")
+
def test_geos_version(self):
"""Testing the GEOS version regular expression."""
from django.contrib.gis.geos.libgeos import version_regex