瀏覽代碼

Tests passing on Jython 2.5.2

Ask Solem 14 年之前
父節點
當前提交
f5ad428a43

+ 2 - 0
celery/tests/test_app/test_app_defaults.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import, with_statement
+
 import sys
 
 from importlib import import_module

+ 9 - 3
celery/tests/test_backends/test_pyredis_compat.py

@@ -1,12 +1,18 @@
-from celery.backends import pyredis
+from nose import SkipTest
+
+from celery.exceptions import ImproperlyConfigured
 from celery.tests.utils import unittest
 
 
 class test_RedisBackend(unittest.TestCase):
 
     def test_constructor(self):
-        x = pyredis.RedisBackend(redis_host="foobar", redis_port=312,
-                                 redis_db=1, redis_password="foo")
+        from celery.backends import pyredis
+        try:
+            x = pyredis.RedisBackend(redis_host="foobar", redis_port=312,
+                                    redis_db=1, redis_password="foo")
+        except ImproperlyConfigured:
+            raise SkipTest("redis-py not installed")
         self.assertEqual(x.redis_host, "foobar")
         self.assertEqual(x.redis_port, 312)
         self.assertEqual(x.redis_db, 1)

+ 18 - 7
celery/tests/test_bin/test_celeryd.py

@@ -25,7 +25,8 @@ from celery.bin.celeryd import WorkerCommand, windows_main, \
 from celery.exceptions import ImproperlyConfigured
 
 from celery.tests.compat import catch_warnings
-from celery.tests.utils import AppCase, StringIO, mask_modules, reset_modules
+from celery.tests.utils import (AppCase, StringIO, mask_modules,
+                                reset_modules, skip_unless_module)
 
 
 from celery.utils.patch import ensure_process_aware_logger
@@ -73,12 +74,17 @@ class test_compilation(AppCase):
                 from celery.apps.worker import cpu_count
                 self.assertEqual(cpu_count(), 2)
 
-    @patch("multiprocessing.cpu_count")
+    @skip_unless_module("multiprocessing")
     def test_no_cpu_count(self, pcount):
-        pcount.side_effect = NotImplementedError("cpu_count")
-        from celery.apps.worker import cpu_count
-        self.assertEqual(cpu_count(), 2)
-        pcount.assert_called_with()
+
+        @patch("multiprocessing.cpu_count")
+        def _do_test():
+            pcount.side_effect = NotImplementedError("cpu_count")
+            from celery.apps.worker import cpu_count
+            self.assertEqual(cpu_count(), 2)
+            pcount.assert_called_with()
+
+        _do_test()
 
     def test_process_name_wo_mp(self):
         with mask_modules("multiprocessing"):
@@ -86,11 +92,16 @@ class test_compilation(AppCase):
                 from celery.apps.worker import get_process_name
                 self.assertIsNone(get_process_name())
 
-    @patch("multiprocessing.current_process")
+    @skip_unless_module("multiprocessing")
     def test_process_name_w_mp(self, current_process):
+
+        @patch("multiprocessing.current_process")
+        def _do_test():
             from celery.apps.worker import get_process_name
             self.assertTrue(get_process_name())
 
+        _do_test()
+
 
 class test_Worker(AppCase):
     Worker = Worker

+ 8 - 4
celery/tests/test_concurrency/test_concurrency_processes.py

@@ -189,11 +189,15 @@ class test_TaskPool(unittest.TestCase):
         pool.start()
         pool.apply_async(lambda x: x, (2, ), {})
 
-    @patch("celery.concurrency.processes._kill")
     def test_terminate_job(self, _kill):
-        pool = TaskPool(10)
-        pool.terminate_job(1341)
-        _kill.assert_called_with(1341, signal.SIGTERM)
+
+        @patch("celery.concurrency.processes._kill")
+        def _do_test():
+            pool = TaskPool(10)
+            pool.terminate_job(1341)
+            _kill.assert_called_with(1341, signal.SIGTERM)
+
+        _do_test()
 
     def test_grow_shrink(self):
         pool = TaskPool(10)

+ 18 - 0
celery/tests/utils.py

@@ -37,6 +37,24 @@ class Mock(mock.Mock):
             setattr(self, attr_name, attr_value)
 
 
+def skip_unless_module(module):
+
+    def _inner(fun):
+
+        @wraps(fun)
+        def __inner(*args, **kwargs):
+            try:
+                importlib.import_module(module)
+            except ImportError:
+                raise SkipTest("Does not have %s" % (module, ))
+
+            return fun(*args, **kwargs)
+
+        return __inner
+    return _inner
+
+
+
 class AppCase(unittest.TestCase):
 
     def setUp(self):

+ 2 - 0
celery/worker/consumer.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import, with_statement
+
 """
 
 This module contains the component responsible for consuming messages