Parcourir la source

[Py3] Tests passing

Ask Solem il y a 11 ans
Parent
commit
bf9ac41856

+ 3 - 3
celery/backends/base.py

@@ -377,21 +377,21 @@ class KeyValueStoreBackend(BaseBackend):
     def get_key_for_task(self, task_id, key=''):
         """Get the cache key for a task by id."""
         key_t = self.key_t
-        return ''.join([
+        return key_t('').join([
             self.task_keyprefix, key_t(task_id), key_t(key),
         ])
 
     def get_key_for_group(self, group_id, key=''):
         """Get the cache key for a group by id."""
         key_t = self.key_t
-        return ''.join([
+        return key_t('').join([
             self.group_keyprefix, key_t(group_id), key_t(key),
         ])
 
     def get_key_for_chord(self, group_id, key=''):
         """Get the cache key for the chord waiting on group with given id."""
         key_t = self.key_t
-        return ''.join([
+        return key_t('').join([
             self.chord_keyprefix, key_t(group_id), key_t(key),
         ])
 

+ 4 - 1
celery/backends/redis.py

@@ -206,9 +206,12 @@ class RedisBackend(KeyValueStoreBackend):
             .expire(jkey, 86400)                                        \
             .execute()
 
+        print('YEA')
+
         try:
             callback = maybe_signature(request.chord, app=app)
             total = callback['chord_size']
+            print('TOTAL: %r' % (readycount, ))
             if readycount >= total:
                 decode, unpack = self.decode, self._unpack_chord_result
                 resl, _ = client.pipeline()     \
@@ -228,7 +231,7 @@ class RedisBackend(KeyValueStoreBackend):
             )
         except Exception as exc:
             app._tasks[callback.task].backend.fail_from_current_stack(
-                callback.id, exc=ChordError('Join error: {0!r}').format(exc),
+                callback.id, exc=ChordError('Join error: {0!r}'.format(exc)),
             )
 
     @property

+ 1 - 1
celery/tests/app/test_log.py

@@ -255,7 +255,7 @@ class test_default_logger(AppCase):
     def test_setup_logger_no_handlers_file(self, *args):
         tempfile = mktemp(suffix='unittest', prefix='celery')
         _open = ('builtins.open' if sys.version_info[0] == 3
-                 else '__builtins__.open')
+                 else '__builtin__.open')
         with patch(_open) as osopen:
             with restore_logging():
                 files = defaultdict(StringIO)

+ 16 - 0
celery/tests/backends/test_redis.py

@@ -74,6 +74,22 @@ class Redis(MockCallbacks):
     def pipeline(self):
         return self.Pipeline(self)
 
+    def _get_list(self, key):
+        try:
+            return self.keyspace[key]
+        except KeyError:
+            l = self.keyspace[key] = []
+            return l
+
+    def rpush(self, key, value):
+        self._get_list(key).append(value)
+
+    def lrange(self, key, start, stop):
+        return self._get_list(key)[start:stop]
+
+    def llen(self, key):
+        return len(self.keyspace.get(key) or [])
+
 
 class redis(object):
     Redis = Redis

+ 11 - 1
celery/tests/case.py

@@ -69,6 +69,8 @@ sentinel = mock.sentinel
 MagicMock = mock.MagicMock
 ANY = mock.ANY
 
+PY3 = sys.version_info[0] == 3
+
 CASE_REDEFINES_SETUP = """\
 {name} (subclass of AppCase) redefines private "setUp", should be: "setup"\
 """
@@ -178,11 +180,19 @@ def _bind(f, o):
     return bound_meth
 
 
+if PY3:  # pragma: no cover
+    def _get_class_fun(meth):
+        return meth
+else:
+    def _get_class_fun(meth):
+        return meth.__func__
+
+
 class MockCallbacks(object):
 
     def __new__(cls, *args, **kwargs):
         r = Mock(name=cls.__name__)
-        cls.__init__.__func__(r, *args, **kwargs)
+        _get_class_fun(cls.__init__)(r, *args, **kwargs)
         for key, value in items(vars(cls)):
             if key not in ('__dict__', '__weakref__', '__new__', '__init__'):
                 if inspect.ismethod(value) or inspect.isfunction(value):