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."