Ticket #19366: 19366-1.diff

File 19366-1.diff, 2.9 KB (added by Claude Paroz, 12 years ago)
  • django/contrib/gis/geos/mutable_list.py

    diff --git a/django/contrib/gis/geos/mutable_list.py b/django/contrib/gis/geos/mutable_list.py
    index 820cdfa..f3641d5 100644
    a b class ListMixin(object):  
    152152        for i in range(len(self)):
    153153            try:
    154154                c = self[i] == other[i]
    155             except IndexError:
     155            except (IndexError, self._IndexError):
    156156                # must be other is shorter
    157157                return False
    158158            if not c:
    159159                return False
    160         return True
     160        return len(self) == len(other)
    161161
    162162    def __lt__(self, other):
    163163        slen = len(self)
    164164        for i in range(slen):
    165165            try:
    166166                c = self[i] < other[i]
    167             except IndexError:
     167            except (IndexError, self._IndexError):
    168168                # must be other is shorter
    169169                return False
    170170            if c:
  • django/contrib/gis/geos/tests/test_geos.py

    diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
    index 283daa4..ff548a1 100644
    a b class GEOSTest(unittest.TestCase, TestDataMixin):  
    451451            self.assertEqual(poly.wkt, Polygon(*tuple(r for r in poly)).wkt)
    452452            self.assertEqual(poly.wkt, Polygon(*tuple(LinearRing(r.tuple) for r in poly)).wkt)
    453453
     454    def test_polygon_comparison(self):
     455        p1 = Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)))
     456        p2 = Polygon(((0, 0), (0, 1), (1, 0), (0, 0)))
     457        self.assertTrue(p1 > p2)
     458        self.assertFalse(p1 < p2)
     459
    454460    def test_multipolygons(self):
    455461        "Testing MultiPolygon objects."
    456462        prev = fromstr('POINT (0 0)')
  • django/contrib/gis/geos/tests/test_mutable_list.py

    diff --git a/django/contrib/gis/geos/tests/test_mutable_list.py b/django/contrib/gis/geos/tests/test_mutable_list.py
    index 675505f..988d841 100644
    a b class ListMixinTest(unittest.TestCase):  
    363363
    364364        pl, ul = self.lists_of_len()
    365365        self.assertEqual(pl, ul, 'cmp for equal')
     366        self.assertFalse(ul == pl + [2], 'cmp for not equal')
    366367        self.assertTrue(pl >= ul, 'cmp for gte self')
    367368        self.assertTrue(pl <= ul, 'cmp for lte self')
    368369        self.assertTrue(ul >= pl, 'cmp for self gte')
    class ListMixinTest(unittest.TestCase):  
    377378        self.assertTrue(ul < pl + [2], 'cmp')
    378379        self.assertTrue(ul <= pl + [2], 'cmp')
    379380
     381        # Also works with a custom IndexError
     382        ul_longer = ul + [2]
     383        ul_longer._IndexError = TypeError
     384        ul._IndexError = TypeError
     385        self.assertFalse(ul_longer == pl)
     386        self.assertFalse(ul == ul_longer)
     387        self.assertTrue(ul_longer > ul)
     388
    380389        pl[1] = 20
    381390        self.assertTrue(pl > ul, 'cmp for gt self')
    382391        self.assertTrue(ul < pl, 'cmp for self lt')
Back to Top