def test_no_implementations(self): with mock.mask_modules('pylibmc', 'memcache'): with mock.reset_modules('celery.backends.cache'): from celery.backends import cache cache._imp = [None] with pytest.raises(ImproperlyConfigured): cache.get_best_memcache()
def test_memcache(self): with self.mock_memcache(): with mock.reset_modules('celery.backends.cache'): with mock.mask_modules('pylibmc'): from celery.backends import cache cache._imp = [None] assert (cache.get_best_memcache()[0]().__module__ == 'memcache')
def test_no_cpickle(self): prev = sys.modules.pop('celery.utils.serialization', None) try: with mock.mask_modules('cPickle'): from celery.utils.serialization import pickle import pickle as orig_pickle assert pickle.dumps is orig_pickle.dumps finally: sys.modules['celery.utils.serialization'] = prev
def test_memcache_bytes_key(self): with self.mock_memcache(): with mock.reset_modules('celery.backends.cache'): with mock.mask_modules('pylibmc'): from celery.backends import cache cache._imp = [None] task_id, result = str_to_bytes(uuid()), 42 b = cache.CacheBackend(backend='memcache', app=self.app) b.store_result(task_id, result, state=states.SUCCESS) assert b.get_result(task_id) == result
def test_fixup(self, patching): with patch('celery.fixups.django.DjangoFixup') as Fixup: patching.setenv('DJANGO_SETTINGS_MODULE', '') fixup(self.app) Fixup.assert_not_called() patching.setenv('DJANGO_SETTINGS_MODULE', 'settings') with mock.mask_modules('django'): with pytest.warns(FixupWarning): fixup(self.app) Fixup.assert_not_called() with mock.module_exists('django'): fixup(self.app) Fixup.assert_called()
def test_pool_no_multiprocessing(self): with mock.mask_modules('multiprocessing.util'): pool = self.app.pool assert pool is self.app._pool
def test_setup_logging_subsystem_no_mputil(self): with mock.mask_modules('billiard.util'): self.app.log.setup_logging_subsystem()