def test_pylibmc(self): with self.mock_pylibmc(): with reset_modules('celery.backends.cache'): from celery.backends import cache cache._imp = [None] self.assertEqual(cache.get_best_memcache().__module__, 'pylibmc')
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()
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()
def test_cached(self): with self.mock_pylibmc(): with reset_modules("celery.backends.cache"): from celery.backends import cache cache.get_best_memcache(behaviors={"foo": "bar"}) self.assertTrue(cache._imp[0]) cache.get_best_memcache()
def test_pylibmc(self): with reset_modules("celery.backends.cache"): with self.mock_pylibmc(): from celery.backends import cache cache._imp = [None] self.assertEqual(cache.get_best_memcache().__module__, "pylibmc")
def test_cached(self): with self.mock_pylibmc(): with reset_modules('celery.backends.cache'): from celery.backends import cache cache._imp = [None] cache.get_best_memcache(behaviors={'foo': 'bar'}) self.assertTrue(cache._imp[0]) cache.get_best_memcache()
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")
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')
def test_pylibmc_bytes_key(self): with reset_modules("celery.backends.cache"): with self.mock_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_pylibmc_bytes_key(self): with reset_modules('celery.backends.cache'): with self.mock_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_memcache_unicode_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 = string(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_memcache_unicode_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 = unicode(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_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())
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)
def test_no_multiprocessing(self): with mask_modules("multiprocessing"): with reset_modules("celery.apps.worker"): from celery.apps.worker import multiprocessing self.assertIsNone(multiprocessing)