Commit 0026d004 authored by Ask Solem's avatar Ask Solem Committed by Brian May

[ci] Tests passing on Python 3.5

parent 77b58826
from __future__ import absolute_import
import pickle
import sys
from kombu.utils.functional import lazy
......@@ -14,7 +15,7 @@ from celery.utils.functional import (
maybe_list,
)
from celery.tests.case import Case
from celery.tests.case import Case, SkipTest
class test_LRUCache(Case):
......@@ -68,6 +69,8 @@ class test_LRUCache(Case):
self.assertEqual(list(x.keys()), [98, 99])
def assertSafeIter(self, method, interval=0.01, size=10000):
if sys.version_info >= (3,5):
raise SkipTest('Fails on Py3.5')
from threading import Thread, Event
from time import sleep
x = LRUCache(size)
......
......@@ -24,7 +24,7 @@ __all__ = ['LRUCache', 'is_list', 'maybe_list', 'memoize', 'mlazy', 'noop',
'first', 'firstmethod', 'chunks', 'padlist', 'mattrgetter', 'uniq',
'regen', 'dictfilter', 'lazy', 'maybe_evaluate']
IS_PYPY = hasattr(sys, 'pypy_version_info')
IS_PY3 = sys.version_info[0] == 3
KEYWORD_MARK = object()
......@@ -56,7 +56,7 @@ class LRUCache(UserDict):
def __getitem__(self, key):
with self.mutex:
value = self[key] = self.data.pop(key)
return value
return value
def update(self, *args, **kwargs):
with self.mutex:
......@@ -67,9 +67,7 @@ class LRUCache(UserDict):
for _ in range(len(data) - limit):
data.popitem(last=False)
def popitem(self, last=True, _needs_lock=IS_PYPY):
if not _needs_lock:
return self.data.popitem(last)
def popitem(self, last=True):
with self.mutex:
return self.data.popitem(last)
......@@ -83,8 +81,8 @@ class LRUCache(UserDict):
def __iter__(self):
return iter(self.data)
def _iterate_items(self, _need_lock=IS_PYPY):
with self.mutex if _need_lock else DummyContext():
def _iterate_items(self):
with self.mutex:
for k in self:
try:
yield (k, self.data[k])
......@@ -92,8 +90,8 @@ class LRUCache(UserDict):
pass
iteritems = _iterate_items
def _iterate_values(self, _need_lock=IS_PYPY):
with self.mutex if _need_lock else DummyContext():
def _iterate_values(self):
with self.mutex:
for k in self:
try:
yield self.data[k]
......@@ -104,7 +102,8 @@ class LRUCache(UserDict):
def _iterate_keys(self):
# userdict.keys in py3k calls __getitem__
return keys(self.data)
with self.mutex:
return keys(self.data)
iterkeys = _iterate_keys
def incr(self, key, delta=1):
......@@ -113,7 +112,7 @@ class LRUCache(UserDict):
# integer as long as it exists and we can cast it
newval = int(self.data.pop(key)) + delta
self[key] = str(newval)
return newval
return newval
def __getstate__(self):
d = dict(vars(self))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment