def test_no_cpickle(self):
     from celery.tests.utils import mask_modules
     del(sys.modules["celery.serialization"])
     with mask_modules("cPickle"):
         from celery.serialization import pickle
         import pickle as orig_pickle
         self.assertTrue(pickle.dumps is orig_pickle.dumps)
Exemple #2
0
 def test_no_implementations(self):
     with mask_modules("pylibmc", "memcache"):
         with reset_modules("celery.backends.cache"):
             from celery.backends import cache
             cache._imp = [None]
             with self.assertRaises(ImproperlyConfigured):
                 cache.get_best_memcache()
Exemple #3
0
 def test_no_implementations(self):
     with mask_modules('pylibmc', 'memcache'):
         with reset_modules('celery.backends.cache'):
             from celery.backends import cache
             cache._imp = [None]
             with self.assertRaises(ImproperlyConfigured):
                 cache.get_best_memcache()
Exemple #4
0
    def test_missing_SQLAlchemy_raises_ImproperlyConfigured(self):

        def with_SQLAlchemy_masked(_val):
            from celery.backends.database import _sqlalchemy_installed
            self.assertRaises(ImproperlyConfigured, _sqlalchemy_installed)

        execute_context(mask_modules("sqlalchemy"), with_SQLAlchemy_masked)
Exemple #5
0
 def test_tyrant_None_if_tyrant_not_installed(self):
     from celery.tests.utils import mask_modules
     prev = sys.modules.pop("celery.backends.pyredis")
     with mask_modules("redis"):
         from celery.backends.pyredis import redis
         self.assertTrue(redis is None)
     sys.modules["celery.backends.pyredis"] = prev
Exemple #6
0
 def test_memcache(self):
     with self.mock_memcache():
         with reset_modules("celery.backends.cache"):
             with mask_modules("pylibmc"):
                 from celery.backends import cache
                 cache._imp = [None]
                 self.assertEqual(cache.get_best_memcache().__module__,
                                  "memcache")
Exemple #7
0
 def test_memcache(self):
     with self.mock_memcache():
         with reset_modules('celery.backends.cache'):
             with mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 self.assertEqual(cache.get_best_memcache().__module__,
                                  'memcache')
Exemple #8
0
 def test_redis_None_if_redis_not_installed(self):
     prev = sys.modules.pop("celery.backends.redis")
     try:
         with mask_modules("redis"):
             from celery.backends.redis import redis
             self.assertIsNone(redis)
     finally:
         sys.modules["celery.backends.redis"] = prev
 def test_no_cpickle(self):
     from celery.tests.utils import mask_modules
     prev = sys.modules.pop("billiard.serialization")
     with mask_modules("cPickle"):
         from billiard.serialization import pickle
         import pickle as orig_pickle
         self.assertTrue(pickle.dumps is orig_pickle.dumps)
     sys.modules["billiard.serialization"] = prev
 def test_no_cpickle(self):
     prev = sys.modules.pop('celery.utils.serialization', None)
     try:
         with mask_modules('cPickle'):
             from celery.utils.serialization import pickle
             import pickle as orig_pickle
             self.assertIs(pickle.dumps, orig_pickle.dumps)
     finally:
         sys.modules['celery.utils.serialization'] = prev
 def test_no_cpickle(self):
     prev = sys.modules.pop("celery.utils.serialization", None)
     try:
         with mask_modules("cPickle"):
             from celery.utils.serialization import pickle
             import pickle as orig_pickle
             self.assertIs(pickle.dumps, orig_pickle.dumps)
     finally:
         sys.modules["celery.utils.serialization"] = prev
Exemple #12
0
 def test_memcache_bytes_key(self):
     with self.mock_memcache():
         with reset_modules('celery.backends.cache'):
             with mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 task_id, result = str_to_bytes(uuid()), 42
                 b = cache.CacheBackend(backend='memcache')
                 b.store_result(task_id, result, status=states.SUCCESS)
                 self.assertEqual(b.get_result(task_id), result)
Exemple #13
0
 def test_memcache_bytes_key(self):
     with self.mock_memcache():
         with reset_modules("celery.backends.cache"):
             with mask_modules("pylibmc"):
                 from celery.backends import cache
                 cache._imp = [None]
                 task_id, result = str_to_bytes(uuid()), 42
                 b = cache.CacheBackend(backend='memcache')
                 b.store_result(task_id, result, status=states.SUCCESS)
                 self.assertEqual(b.get_result(task_id), result)
 def test_tyrant_None_if_tyrant_not_installed(self):
     prev = sys.modules.pop("celery.backends.pyredis")
     try:
         def with_redis_masked(_val):
             from celery.backends.pyredis import redis
             self.assertIsNone(redis)
         context = mask_modules("redis")
         execute_context(context, with_redis_masked)
     finally:
         sys.modules["celery.backends.pyredis"] = prev
Exemple #15
0
    def test_redis_None_if_redis_not_installed(self):
        prev = sys.modules.pop("celery.backends.pyredis")
        try:

            def with_redis_masked(_val):
                from celery.backends.pyredis import redis
                self.assertIsNone(redis)
            context = mask_modules("redis")
            execute_context(context, with_redis_masked)
        finally:
            sys.modules["celery.backends.pyredis"] = prev
Exemple #16
0
 def test_gen_unique_id_without_ctypes(self):
     from celery.tests.utils import mask_modules
     old_utils = sys.modules.pop("celery.utils")
     try:
         with mask_modules("ctypes"):
             from celery.utils import ctypes, gen_unique_id
             self.assertTrue(ctypes is None)
             uuid = gen_unique_id()
             self.assertTrue(uuid)
             self.assertTrue(isinstance(uuid, basestring))
     finally:
         sys.modules["celery.utils"] = old_utils
    def test_no_implementations(self):
        def with_no_memcache_libs():
            sys.modules.pop("celery.backends.cache", None)
            from celery.backends import cache
            self.assertRaises(ImproperlyConfigured, cache.get_best_memcache)

        context = mask_modules("pylibmc", "memcache")
        context.__enter__()
        try:
            with_no_memcache_libs()
        finally:
            context.__exit__(None, None, None)
Exemple #18
0
    def test_no_cpickle(self):
        prev = sys.modules.pop("billiard.serialization")
        try:
            def with_cPickle_masked(_val):
                from billiard.serialization import pickle
                import pickle as orig_pickle
                self.assertIs(pickle.dumps, orig_pickle.dumps)

            context = mask_modules("cPickle")
            execute_context(context, with_cPickle_masked)

        finally:
            sys.modules["billiard.serialization"] = prev
Exemple #19
0
    def test_no_implementations(self):

        def with_no_memcache_libs():
            sys.modules.pop("celery.backends.cache", None)
            from celery.backends import cache
            self.assertRaises(ImproperlyConfigured, cache.get_best_memcache)

        context = mask_modules("pylibmc", "memcache")
        context.__enter__()
        try:
            with_no_memcache_libs()
        finally:
            context.__exit__(None, None, None)
Exemple #20
0
    def test_no_cpickle(self):
        prev = sys.modules.pop("celery.utils.serialization", None)
        try:

            def with_cPickle_masked(_val):
                from celery.utils.serialization import pickle
                import pickle as orig_pickle
                self.assertIs(pickle.dumps, orig_pickle.dumps)

            context = mask_modules("cPickle")
            execute_context(context, with_cPickle_masked)

        finally:
            sys.modules["celery.utils.serialization"] = prev
    def test_memcache(self):
        def with_no_pylibmc():
            sys.modules.pop("celery.backends.cache", None)
            from celery.backends import cache
            self.assertEqual(cache.get_best_memcache().__module__, "memcache")

        context = mask_modules("pylibmc")
        context.__enter__()
        try:
            memcache = self.mock_memcache()
            memcache.next()
            with_no_pylibmc()
            memcache.next()
        finally:
            context.__exit__(None, None, None)
Exemple #22
0
    def test_memcache(self):

        def with_no_pylibmc():
            sys.modules.pop("celery.backends.cache", None)
            from celery.backends import cache
            self.assertEqual(cache.get_best_memcache().__module__, "memcache")

        context = mask_modules("pylibmc")
        context.__enter__()
        try:
            memcache = self.mock_memcache()
            memcache.next()
            with_no_pylibmc()
            memcache.next()
        finally:
            context.__exit__(None, None, None)
Exemple #23
0
    def test_gen_unique_id_without_ctypes(self):
        old_utils = sys.modules.pop("celery.utils")

        def with_ctypes_masked(_val):
            from celery.utils import ctypes, gen_unique_id

            self.assertIsNone(ctypes)
            uuid = gen_unique_id()
            self.assertTrue(uuid)
            self.assertIsInstance(uuid, basestring)

        try:
            context = mask_modules("ctypes")
            execute_context(context, with_ctypes_masked)
        finally:
            sys.modules["celery.utils"] = old_utils
    def test_gen_unique_id_without_ctypes(self):
        old_utils = sys.modules.pop("celery.utils")

        def with_ctypes_masked(_val):
            from celery.utils import ctypes, gen_unique_id

            self.assertIsNone(ctypes)
            uuid = gen_unique_id()
            self.assertTrue(uuid)
            self.assertIsInstance(uuid, basestring)

        try:
            context = mask_modules("ctypes")
            execute_context(context, with_ctypes_masked)
        finally:
            sys.modules["celery.utils"] = old_utils
Exemple #25
0
 def test_cpu_count_no_mp(self):
     with mask_modules("multiprocessing"):
         with reset_modules("celery.apps.worker"):
             from celery.apps.worker import cpu_count
             self.assertEqual(cpu_count(), 2)
Exemple #26
0
    def test_missing_SQLAlchemy_raises_ImproperlyConfigured(self):
        def with_SQLAlchemy_masked(_val):
            from celery.backends.database import _sqlalchemy_installed
            self.assertRaises(ImproperlyConfigured, _sqlalchemy_installed)

        execute_context(mask_modules("sqlalchemy"), with_SQLAlchemy_masked)
 def test_missing_SQLAlchemy_raises_ImproperlyConfigured(self):
     with mask_modules('sqlalchemy'):
         from celery.backends.database import _sqlalchemy_installed
         with self.assertRaises(ImproperlyConfigured):
             _sqlalchemy_installed()
Exemple #28
0
 def test_missing_SQLAlchemy_raises_ImproperlyConfigured(self):
     with mask_modules("sqlalchemy"):
         from celery.backends.database import _sqlalchemy_installed
         with self.assertRaises(ImproperlyConfigured):
             _sqlalchemy_installed()
Exemple #29
0
 def test_process_name_wo_mp(self):
     with mask_modules("multiprocessing"):
         with reset_modules("celery.apps.worker"):
             from celery.apps.worker import get_process_name
             self.assertIsNone(get_process_name())
Exemple #30
0
 def test_process_name_wo_mp(self):
     with mask_modules("multiprocessing"):
         with reset_modules("celery.apps.worker"):
             from celery.apps.worker import get_process_name
             self.assertIsNone(get_process_name())
Exemple #31
0
 def test_no_multiprocessing(self):
     with mask_modules("multiprocessing"):
         with reset_modules("celery.apps.worker"):
             from celery.apps.worker import multiprocessing
             self.assertIsNone(multiprocessing)
Exemple #32
0
    def test_without_threadpool(self):

        with mask_modules('threadpool'):
            with self.assertRaises(ImportError):
                TaskPool()
Exemple #33
0
    def test_without_threadpool(self):

        with mask_modules("threadpool"):
            with self.assertRaises(ImportError):
                TaskPool()
Exemple #34
0
 def test_no_multiprocessing(self):
     with mask_modules("multiprocessing"):
         with reset_modules("celery.apps.worker"):
             from celery.apps.worker import multiprocessing
             self.assertIsNone(multiprocessing)
Exemple #35
0
 def test_cpu_count_no_mp(self):
     with mask_modules("multiprocessing"):
         with reset_modules("celery.apps.worker"):
             from celery.apps.worker import cpu_count
             self.assertEqual(cpu_count(), 2)
Exemple #36
0
 def test_pool_no_multiprocessing(self):
     with mask_modules("multiprocessing.util"):
         pool = self.app.pool
         self.assertIs(pool, self.app._pool)
Exemple #37
0
 def test_pool_no_multiprocessing(self):
     with mask_modules('multiprocessing.util'):
         pool = self.app.pool
         self.assertIs(pool, self.app._pool)