From bfe714f014d54f1f9bd67166b530006f740a820e Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Tue, 22 Jul 2008 02:43:47 +0000 Subject: [PATCH] gis: Fixed #7873, `GEOSGeometry` equivalence comparison with `None` should not raise an exception. Thanks, Denis. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8040 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/geos/base.py | 4 +++- django/contrib/gis/tests/test_geos.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/django/contrib/gis/geos/base.py b/django/contrib/gis/geos/base.py index 728e99e2be..8200d59eec 100644 --- a/django/contrib/gis/geos/base.py +++ b/django/contrib/gis/geos/base.py @@ -166,8 +166,10 @@ class GEOSGeometry(object): """ if isinstance(other, basestring): return self.wkt == other - else: + elif isinstance(other, GEOSGeometry): return self.equals_exact(other) + else: + return False def __ne__(self, other): "The not equals operator." diff --git a/django/contrib/gis/tests/test_geos.py b/django/contrib/gis/tests/test_geos.py index 15fdfb66ec..8ea450700c 100644 --- a/django/contrib/gis/tests/test_geos.py +++ b/django/contrib/gis/tests/test_geos.py @@ -107,13 +107,19 @@ class GEOSTest(unittest.TestCase): self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json)) def test01j_eq(self): - "Testing equivalence with WKT." + "Testing equivalence." p = fromstr('POINT(5 23)') self.assertEqual(p, p.wkt) self.assertNotEqual(p, 'foo') ls = fromstr('LINESTRING(0 0, 1 1, 5 5)') self.assertEqual(ls, ls.wkt) self.assertNotEqual(p, 'bar') + # Error shouldn't be raise on equivalence testing with + # an invalid type. + for g in (p, ls): + self.assertNotEqual(g, None) + self.assertNotEqual(g, {'foo' : 'bar'}) + self.assertNotEqual(g, False) def test02a_points(self): "Testing Point objects."