django.utils.six.moves.xrange

Here are the examples of the python api django.utils.six.moves.xrange taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 51

Project: splunk-webframework
Source File: test_geos.py
View license
    def test_symdifference(self):
        "Testing sym_difference()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = fromstr(self.geometries.topology_geoms[i].wkt_a)
            b = fromstr(self.geometries.topology_geoms[i].wkt_b)
            d1 = fromstr(self.geometries.sdiff_geoms[i].wkt)
            d2 = a.sym_difference(b)
            self.assertEqual(d1, d2)
            self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
            a ^= b # testing __ixor__
            self.assertEqual(d1, a)

Example 52

Project: hue
Source File: cache.py
View license
    def create(self):
        # Because a cache can fail silently (e.g. memcache), we don't know if
        # we are failing to create a new session because of a key collision or
        # because the cache is missing. So we try for a (large) number of times
        # and then raise an exception. That's the risk you shoulder if using
        # cache backing.
        for i in xrange(10000):
            self._session_key = self._get_new_session_key()
            try:
                self.save(must_create=True)
            except CreateError:
                continue
            self.modified = True
            return
        raise RuntimeError(
            "Unable to create a new session key. "
            "It is likely that the cache is unavailable.")

Example 53

Project: splunk-webframework
Source File: cache.py
View license
    def create(self):
        # Because a cache can fail silently (e.g. memcache), we don't know if
        # we are failing to create a new session because of a key collision or
        # because the cache is missing. So we try for a (large) number of times
        # and then raise an exception. That's the risk you shoulder if using
        # cache backing.
        for i in xrange(10000):
            self._session_key = self._get_new_session_key()
            try:
                self.save(must_create=True)
            except CreateError:
                continue
            self.modified = True
            return
        raise RuntimeError("Unable to create a new session key.")

Example 54

Project: hue
Source File: formsets.py
View license
    @cached_property
    def forms(self):
        """
        Instantiate forms at first property access.
        """
        # DoS protection is included in total_form_count()
        forms = [self._construct_form(i) for i in xrange(self.total_form_count())]
        return forms

Example 55

Project: splunk-webframework
Source File: mutable_list.py
View license
    def _assign_simple_slice(self, start, stop, valueList):
        'Assign a simple slice; Can assign slice of any length'
        origLen = len(self)
        stop = max(start, stop)
        newLen  = origLen - stop + start + len(valueList)
        def newItems():
            for i in xrange(origLen + 1):
                if i == start:
                    for val in valueList:
                        yield val

                if i < origLen:
                    if i < start or i >= stop:
                        yield self._get_single_internal(i)

        self._rebuild(newLen, newItems())

Example 56

Project: hue
Source File: test_geos.py
View license
    def test_union(self):
        "Testing union()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = fromstr(self.geometries.topology_geoms[i].wkt_a)
            b = fromstr(self.geometries.topology_geoms[i].wkt_b)
            u1 = fromstr(self.geometries.union_geoms[i].wkt)
            u2 = a.union(b)
            self.assertEqual(u1, u2)
            self.assertEqual(u1, a | b) # __or__ is union operator
            a |= b # testing __ior__
            self.assertEqual(u1, a)

Example 57

Project: django-happenings
Source File: common.py
View license
def clean_year_month_day(year, month, day, net):
    error = False
    error_msg = "The date given was invalid."
    # check that the month is within 1-12
    if month not in xrange(1, 13):
        month = now.month
        error = error_msg
    # check that the day is within range for the month
    if day not in xrange(1, monthrange(year, month)[1] + 1):
        day = 1
        error = error_msg
    # if no error yet, increment the day by net then check the year
    if not error:
        year, month, day = _inc_day(year, month, day, net)
        year, month, error = _check_year(year, month, error, error_msg)
    return year, month, day, error

Example 58

Project: PyClassLessons
Source File: formsets.py
View license
    @cached_property
    def forms(self):
        """
        Instantiate forms at first property access.
        """
        # DoS protection is included in total_form_count()
        forms = [self._construct_form(i) for i in xrange(self.total_form_count())]
        return forms

Example 59

Project: decode-Django
Source File: tests.py
View license
    def test_bulk(self):
        from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
        s = S.objects.create(r=R.objects.create())
        for i in xrange(2*GET_ITERATOR_CHUNK_SIZE):
            T.objects.create(s=s)
        #   1 (select related `T` instances)
        # + 1 (select related `U` instances)
        # + 2 (delete `T` instances in batches)
        # + 1 (delete `s`)
        self.assertNumQueries(5, s.delete)
        self.assertFalse(S.objects.exists())

Example 60

Project: decode-Django
Source File: test_geos.py
View license
    def test_symdifference(self):
        "Testing sym_difference()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = fromstr(self.geometries.topology_geoms[i].wkt_a)
            b = fromstr(self.geometries.topology_geoms[i].wkt_b)
            d1 = fromstr(self.geometries.sdiff_geoms[i].wkt)
            d2 = a.sym_difference(b)
            self.assertEqual(d1, d2)
            self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
            a ^= b # testing __ixor__
            self.assertEqual(d1, a)

Example 61

Project: django-sharding
Source File: test_fields.py
View license
    def test_uses_get_next_id_in_get_pk_value_on_save(self):
        class FakeModel(object):
            pk = None

        field = ShardedIDFieldMixin(strategy=FakeIDGenerationStrategy())
        for i in xrange(1, 100):
            self.assertEqual(field.get_pk_value_on_save(FakeModel()), i)
        self.assertEqual(field.strategy.id, 99)
        self.assertEqual(field.strategy.call_count, 99)

Example 62

Project: django-happenings
Source File: handlers.py
View license
    def _biweekly_helper(self):
        """Created to take some of the load off of _handle_weekly_repeat_out"""
        self.num = 14
        mycount = self.repeat_biweekly()
        if mycount:
            if self.event.is_chunk() and min(mycount) not in xrange(1, 8):
                mycount = _chunk_fill_out_first_week(
                    self.year, self.month, mycount, self.event,
                    diff=self.event.start_end_diff,
                )
            for k, v in mycount.items():
                for item in v:
                    self.count[k].append(item)

Example 63

Project: decode-Django
Source File: test_geos.py
View license
    def test_union(self):
        "Testing union()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = fromstr(self.geometries.topology_geoms[i].wkt_a)
            b = fromstr(self.geometries.topology_geoms[i].wkt_b)
            u1 = fromstr(self.geometries.union_geoms[i].wkt)
            u2 = a.union(b)
            self.assertEqual(u1, u2)
            self.assertEqual(u1, a | b) # __or__ is union operator
            a |= b # testing __ior__
            self.assertEqual(u1, a)

Example 64

Project: PyClassLessons
Source File: coordseq.py
View license
    @property
    def tuple(self):
        "Returns a tuple version of this coordinate sequence."
        n = self.size
        if n == 1:
            return self[0]
        else:
            return tuple(self[i] for i in xrange(n))

Example 65

View license
    def test_largest_value_stored_in_db(self):
        sut = TableStrategy('tests.ShardedModelIDs')
        for i in xrange(100):
            id = sut.get_next_id()
            self.assertEqual(ShardedModelIDs.objects.latest('pk').pk, id)
            self.assertFalse(ShardedModelIDs.objects.filter(pk__gt=id).exists())

Example 66

Project: splunk-webframework
Source File: layer.py
View license
    def __getitem__(self, index):
        "Gets the Feature at the specified index."
        if isinstance(index, six.integer_types):
            # An integer index was given -- we cannot do a check based on the
            # number of features because the beginning and ending feature IDs
            # are not guaranteed to be 0 and len(layer)-1, respectively.
            if index < 0: raise OGRIndexError('Negative indices are not allowed on OGR Layers.')
            return self._make_feature(index)
        elif isinstance(index, slice):
            # A slice was given
            start, stop, stride = index.indices(self.num_feat)
            return [self._make_feature(fid) for fid in xrange(start, stop, stride)]
        else:
            raise TypeError('Integers and slices may only be used when indexing OGR Layers.')

Example 67

Project: decode-Django
Source File: mutable_list.py
View license
    def __getitem__(self, index):
        "Get the item(s) at the specified index/slice."
        if isinstance(index, slice):
            return [self._get_single_external(i) for i in xrange(*index.indices(len(self)))]
        else:
            index = self._checkindex(index)
            return self._get_single_external(index)

Example 68

Project: decode-Django
Source File: coordseq.py
View license
    @property
    def tuple(self):
        "Returns a tuple version of this coordinate sequence."
        n = self.size
        if n == 1: return self[0]
        else: return tuple([self[i] for i in xrange(n)])

Example 69

Project: decode-Django
Source File: mutable_list.py
View license
    def __delitem__(self, index):
        "Delete the item(s) at the specified index/slice."
        if not isinstance(index, six.integer_types + (slice,)):
            raise TypeError("%s is not a legal index" % index)

        # calculate new length and dimensions
        origLen     = len(self)
        if isinstance(index, six.integer_types):
            index = self._checkindex(index)
            indexRange  = [index]
        else:
            indexRange  = range(*index.indices(origLen))

        newLen      = origLen - len(indexRange)
        newItems    = ( self._get_single_internal(i)
                        for i in xrange(origLen)
                        if i not in indexRange )

        self._rebuild(newLen, newItems)

Example 70

View license
    def check_dates(self, event, valid_dates):
        """A DRY helper function."""
        for year, dates in valid_dates.items():
            for month, days in dates.items():
                response = self.client.get(reverse(
                    'calendar:list', kwargs={'year': year, 'month': month}
                ))
                self.clean_whitespace(response)
                if days:
                    self.assertContains(response, event.title)
                else:
                    self.assertNotContains(response, event.title)

                for day in days:
                    self.assertContains(response, self.cal_str(day))

                [self.assertNotContains(response, self.cal_str(day)) for
                 day in xrange(1, monthrange(2014, int(month))[1] + 1)
                 if day not in days]

Example 71

Project: PyClassLessons
Source File: layer.py
View license
    def __iter__(self):
        "Iterates over each Feature in the Layer."
        # ResetReading() must be called before iteration is to begin.
        capi.reset_reading(self._ptr)
        for i in xrange(self.num_feat):
            yield Feature(capi.get_next_feature(self._ptr), self)

Example 72

Project: splunk-webframework
Source File: layer.py
View license
    @property
    def field_types(self):
        """
        Returns a list of the types of fields in this Layer.  For example,
        the list [OFTInteger, OFTReal, OFTString] would be returned for
        an OGR layer that had an integer, a floating-point, and string
        fields.
        """
        return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))]
                for i in xrange(self.num_fields)]

Example 73

View license
    def test_returns_value_with_db_name_and_uuid(self):
        sut = UUIDStrategy()
        for i in xrange(100):
            database = choice(list(settings.DATABASES.keys()))
            id = sut.get_next_id(database)
            self.assertTrue(id.startswith(database))
            uuid_value = id[len(database) + 1:]
            self.assertEqual(str(UUID(uuid_value, version=4)), uuid_value)

Example 74

Project: django-happenings
Source File: test_repeat.py
View license
    def check_dates_yearly(self, event, valid_dates):
        """A DRY helper function for yearly repeat tests."""
        for year, dates in valid_dates.items():
            for month, days in dates.items():
                response = self.client.get(reverse(
                    'calendar:list', kwargs={'year': year, 'month': month}
                ))
                self.clean_whitespace(response)
                if days:
                    self.assertContains(response, event.title)
                else:
                    self.assertNotContains(response, event.title)

                for day in days:
                    self.assertContains(response, self.cal_str(day))

                [self.assertNotContains(response, self.cal_str(day)) for
                 day in xrange(1, monthrange(2014, int(month))[1] + 1)
                 if day not in days]

Example 75

Project: decode-Django
Source File: test_geom.py
View license
    def test10_difference(self):
        "Testing difference()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            d1 = OGRGeometry(self.geometries.diff_geoms[i].wkt)
            d2 = a.difference(b)
            self.assertEqual(d1, d2)
            self.assertEqual(d1, a - b) # __sub__ is difference operator
            a -= b # testing __isub__
            self.assertEqual(d1, a)

Example 76

Project: splunk-webframework
Source File: test_geom.py
View license
    def test11_intersection(self):
        "Testing intersects() and intersection()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt)
            self.assertEqual(True, a.intersects(b))
            i2 = a.intersection(b)
            self.assertEqual(i1, i2)
            self.assertEqual(i1, a & b) # __and__ is intersection operator
            a &= b # testing __iand__
            self.assertEqual(i1, a)

Example 77

Project: decode-Django
Source File: test_geom.py
View license
    def test11_intersection(self):
        "Testing intersects() and intersection()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt)
            self.assertEqual(True, a.intersects(b))
            i2 = a.intersection(b)
            self.assertEqual(i1, i2)
            self.assertEqual(i1, a & b) # __and__ is intersection operator
            a &= b # testing __iand__
            self.assertEqual(i1, a)

Example 78

Project: splunk-webframework
Source File: test_geom.py
View license
    def test12_symdifference(self):
        "Testing sym_difference()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            d1 = OGRGeometry(self.geometries.sdiff_geoms[i].wkt)
            d2 = a.sym_difference(b)
            self.assertEqual(d1, d2)
            self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
            a ^= b # testing __ixor__
            self.assertEqual(d1, a)

Example 79

Project: PyClassLessons
Source File: mutable_list.py
View license
    def __delitem__(self, index):
        "Delete the item(s) at the specified index/slice."
        if not isinstance(index, six.integer_types + (slice,)):
            raise TypeError("%s is not a legal index" % index)

        # calculate new length and dimensions
        origLen = len(self)
        if isinstance(index, six.integer_types):
            index = self._checkindex(index)
            indexRange = [index]
        else:
            indexRange = range(*index.indices(origLen))

        newLen = origLen - len(indexRange)
        newItems = (self._get_single_internal(i)
                    for i in xrange(origLen)
                    if i not in indexRange)

        self._rebuild(newLen, newItems)

Example 80

Project: hue
Source File: layer.py
View license
    def __iter__(self):
        "Iterates over each Feature in the Layer."
        # ResetReading() must be called before iteration is to begin.
        capi.reset_reading(self._ptr)
        for i in xrange(self.num_feat):
            yield Feature(capi.get_next_feature(self._ptr), self)

Example 81

Project: decode-Django
Source File: test_geom.py
View license
    def test12_symdifference(self):
        "Testing sym_difference()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            d1 = OGRGeometry(self.geometries.sdiff_geoms[i].wkt)
            d2 = a.sym_difference(b)
            self.assertEqual(d1, d2)
            self.assertEqual(d1, a ^ b) # __xor__ is symmetric difference operator
            a ^= b # testing __ixor__
            self.assertEqual(d1, a)

Example 82

Project: hue
Source File: test_geom.py
View license
    def test11_intersection(self):
        "Testing intersects() and intersection()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt)
            self.assertEqual(True, a.intersects(b))
            i2 = a.intersection(b)
            self.assertEqual(i1, i2)
            self.assertEqual(i1, a & b) # __and__ is intersection operator
            a &= b # testing __iand__
            self.assertEqual(i1, a)

Example 83

Project: splunk-webframework
Source File: coordseq.py
View license
    @property
    def kml(self):
        "Returns the KML representation for the coordinates."
        # Getting the substitution string depending on whether the coordinates have
        #  a Z dimension.
        if self.hasz: substr = '%s,%s,%s '
        else: substr = '%s,%s,0 '
        return '<coordinates>%s</coordinates>' % \
            ''.join([substr % self[i] for i in xrange(len(self))]).strip()

Example 84

Project: hue
Source File: test_geom.py
View license
    def test13_union(self):
        "Testing union()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            u1 = OGRGeometry(self.geometries.union_geoms[i].wkt)
            u2 = a.union(b)
            self.assertEqual(u1, u2)
            self.assertEqual(u1, a | b) # __or__ is union operator
            a |= b # testing __ior__
            self.assertEqual(u1, a)

Example 85

Project: PyClassLessons
Source File: mutable_list.py
View license
    def index(self, val):
        "Standard list index method"
        for i in xrange(0, len(self)):
            if self[i] == val:
                return i
        raise ValueError('%s not found in object' % str(val))

Example 86

Project: hue
Source File: coordseq.py
View license
    @property
    def tuple(self):
        "Returns a tuple version of this coordinate sequence."
        n = self.size
        if n == 1: return self[0]
        else: return tuple([self[i] for i in xrange(n)])

Example 87

Project: PyClassLessons
Source File: layer.py
View license
    @property
    def field_types(self):
        """
        Returns a list of the types of fields in this Layer.  For example,
        the list [OFTInteger, OFTReal, OFTString] would be returned for
        an OGR layer that had an integer, a floating-point, and string
        fields.
        """
        return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))]
                for i in xrange(self.num_fields)]

Example 88

Project: hue
Source File: linestring.py
View license
    def _listarr(self, func):
        """
        Internal routine that returns a sequence (list) corresponding with
        the given function.  Will return a numpy array if possible.
        """
        lst = [func(i) for i in xrange(len(self))]
        if numpy: return numpy.array(lst) # ARRRR!
        else: return lst

Example 89

View license
    def test_is_cyclic(self):
        sut = RoundRobinRoutingStrategy(settings.DATABASES)
        expected_cycled_shards = ['app_shard_001_replica_001', 'app_shard_001_replica_002', 'app_shard_001']
        expected_cycled_shards.sort()

        resulting_shards = [sut.pick_read_db('app_shard_001') for i in xrange(150)]

        self.assertEqual(len(set([resulting_shards[i] for i in xrange(0, 150, 3)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(1, 150, 3)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(2, 150, 3)])), 1)

        resulting_cycled_shard = resulting_shards[:3]
        resulting_cycled_shard.sort()

        self.assertEqual(expected_cycled_shards, resulting_cycled_shard)

Example 90

Project: hue
Source File: mutable_list.py
View license
    def __delitem__(self, index):
        "Delete the item(s) at the specified index/slice."
        if not isinstance(index, six.integer_types + (slice,)):
            raise TypeError("%s is not a legal index" % index)

        # calculate new length and dimensions
        origLen     = len(self)
        if isinstance(index, six.integer_types):
            index = self._checkindex(index)
            indexRange  = [index]
        else:
            indexRange  = range(*index.indices(origLen))

        newLen      = origLen - len(indexRange)
        newItems    = ( self._get_single_internal(i)
                        for i in xrange(origLen)
                        if i not in indexRange )

        self._rebuild(newLen, newItems)

Example 91

Project: splunk-webframework
Source File: mutable_list.py
View license
    def __getitem__(self, index):
        "Get the item(s) at the specified index/slice."
        if isinstance(index, slice):
            return [self._get_single_external(i) for i in xrange(*index.indices(len(self)))]
        else:
            index = self._checkindex(index)
            return self._get_single_external(index)

Example 92

Project: hue
Source File: polygon.py
View license
    @property
    def kml(self):
        "Returns the KML representation of this Polygon."
        inner_kml = ''.join(["<innerBoundaryIs>%s</innerBoundaryIs>" % self[i+1].kml
                             for i in xrange(self.num_interior_rings)])
        return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml)

Example 93

Project: PyClassLessons
Source File: polygon.py
View license
    @property
    def kml(self):
        "Returns the KML representation of this Polygon."
        inner_kml = ''.join("<innerBoundaryIs>%s</innerBoundaryIs>" % self[i + 1].kml
            for i in xrange(self.num_interior_rings))
        return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml)

Example 94

View license
    def test_picking_is_cyclic(self):
        class FakeUser():
            username = None

        expected_cycle = ['app_shard_001', 'app_shard_002']

        sut = RoundRobinBucketingStrategy(shard_group='default', databases=settings.DATABASES)
        resulting_shards = [sut.pick_shard(FakeUser()) for i in xrange(100)]

        self.assertEqual(len(set([resulting_shards[i] for i in xrange(0, 100, 2)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(1, 100, 2)])), 1)

        resulting_cycled_shard = resulting_shards[:2]
        resulting_cycled_shard.sort()

        self.assertEqual(resulting_cycled_shard, expected_cycle)

Example 95

View license
    def test_is_always_primary(self):
        sut = PrimaryOnlyRoutingStrategy(settings.DATABASES)
        expected_shards = ['app_shard_001'] * 150

        resulting_shards = [sut.pick_read_db('app_shard_001') for i in xrange(150)]
        self.assertEqual(expected_shards, resulting_shards)

Example 96

Project: decode-Django
Source File: layer.py
View license
    def __iter__(self):
        "Iterates over each Feature in the Layer."
        # ResetReading() must be called before iteration is to begin.
        capi.reset_reading(self._ptr)
        for i in xrange(self.num_feat):
            yield Feature(capi.get_next_feature(self._ptr), self)

Example 97

Project: hue
Source File: tests.py
View license
    def test_bulk(self):
        from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
        s = S.objects.create(r=R.objects.create())
        for i in xrange(2*GET_ITERATOR_CHUNK_SIZE):
            T.objects.create(s=s)
        #   1 (select related `T` instances)
        # + 1 (select related `U` instances)
        # + 2 (delete `T` instances in batches)
        # + 1 (delete `s`)
        self.assertNumQueries(5, s.delete)
        self.assertFalse(S.objects.exists())

Example 98

Project: hue
Source File: test_geos.py
View license
    def test_difference(self):
        "Testing difference()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = fromstr(self.geometries.topology_geoms[i].wkt_a)
            b = fromstr(self.geometries.topology_geoms[i].wkt_b)
            d1 = fromstr(self.geometries.diff_geoms[i].wkt)
            d2 = a.difference(b)
            self.assertEqual(d1, d2)
            self.assertEqual(d1, a - b) # __sub__ is difference operator
            a -= b # testing __isub__
            self.assertEqual(d1, a)

Example 99

Project: PyClassLessons
Source File: test_geom.py
View license
    def test13_union(self):
        "Testing union()."
        for i in xrange(len(self.geometries.topology_geoms)):
            a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
            b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
            u1 = OGRGeometry(self.geometries.union_geoms[i].wkt)
            u2 = a.union(b)
            self.assertEqual(u1, u2)
            self.assertEqual(u1, a | b)  # __or__ is union operator
            a |= b  # testing __ior__
            self.assertEqual(u1, a)

Example 100

Project: django-happenings
Source File: common.py
View license
def _check_year(year, month, error, error_msg):
    """Checks that the year is within 50 years from now."""
    if year not in xrange((now.year - 50), (now.year + 51)):
        year = now.year
        month = now.month
        error = error_msg
    return year, month, error