Ticket #19366: 19366-3.diff

File 19366-3.diff, 4.1 KB (added by Craig de Stigter, 12 years ago)

19366-2.diff plus fix lt when geometries are different lengths

  • 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..b41a83a 100644
    a b class ListMixin(object):  
    149149        return self
    150150
    151151    def __eq__(self, other):
    152         for i in range(len(self)):
     152        olen = len(other)
     153        for i in range(olen):
    153154            try:
    154155                c = self[i] == other[i]
    155             except IndexError:
    156                 # must be other is shorter
     156            except self._IndexError:
     157                # self must be shorter
    157158                return False
    158159            if not c:
    159160                return False
    160         return True
     161        return len(self) == olen
    161162
    162163    def __lt__(self, other):
    163         slen = len(self)
    164         for i in range(slen):
     164        olen = len(other)
     165        for i in range(olen):
    165166            try:
    166167                c = self[i] < other[i]
    167             except IndexError:
    168                 # must be other is shorter
    169                 return False
     168            except self._IndexError:
     169                # self must be shorter
     170                return True
    170171            if c:
    171172                return c
    172         return slen < len(other)
     173        return len(self) < olen
    173174
    174175    ### Public list interface Methods ###
    175176    ## Non-mutating ##
  • 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..ec320f9 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        self.assertFalse(p2 > p1)
     460        self.assertTrue(p2 < p1)
     461
     462        p3 = Polygon(((0, 0), (0, 1), (1, 1), (2, 0), (0, 0)))
     463        p4 = Polygon(((0, 0), (0, 1), (2, 2), (1, 0), (0, 0)))
     464        self.assertFalse(p4 < p3)
     465        self.assertTrue(p3 < p4)
     466        self.assertTrue(p4 > p3)
     467        self.assertFalse(p3 > p4)
     468
    454469    def test_multipolygons(self):
    455470        "Testing MultiPolygon objects."
    456471        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')
  • django/contrib/gis/tests/__init__.py

    diff --git a/django/contrib/gis/tests/__init__.py b/django/contrib/gis/tests/__init__.py
    index 765c030..54c945d 100644
    a b class GeoDjangoTestSuiteRunner(DjangoTestSuiteRunner):  
    121121
    122122    def build_suite(self, test_labels, extra_tests=None, **kwargs):
    123123        return geodjango_suite()
     124
     125from django.contrib.gis.geos.tests.test_geos import *
Back to Top