From 7d5c7df6a943b5659831e4f38546798c7bd541c0 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Thu, 1 Apr 2010 16:56:55 +0000 Subject: [PATCH] Fixed #13256 -- `OGRGeometry` no longer raises an exception when compared to instances of different types. Thanks, ninowalker for the bug report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12905 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/gdal/geometries.py | 7 +++++-- django/contrib/gis/gdal/tests/test_geom.py | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index d08d0d53a4..30125d5764 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -180,11 +180,14 @@ class OGRGeometry(GDALBase): def __eq__(self, other): "Is this Geometry equal to the other?" - return self.equals(other) + if isinstance(other, OGRGeometry): + return self.equals(other) + else: + return False def __ne__(self, other): "Tests for inequality." - return not self.equals(other) + return not (self == other) def __str__(self): "WKT is used for the string representation." diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index 0d2f88c55f..5aa1f244ae 100644 --- a/django/contrib/gis/gdal/tests/test_geom.py +++ b/django/contrib/gis/gdal/tests/test_geom.py @@ -481,6 +481,11 @@ class OGRGeomTest(unittest.TestCase): self.assertEqual(3, geom[0].coord_dim) self.assertEqual(wkt_3d, geom.wkt) + def test19_equivalence_regression(self): + "Testing equivalence methods with non-OGRGeometry instances." + self.assertNotEqual(None, OGRGeometry('POINT(0 0)')) + self.assertEqual(False, OGRGeometry('LINESTRING(0 0, 1 1)') == 3) + def suite(): s = unittest.TestSuite() s.addTest(unittest.makeSuite(OGRGeomTest))