Andriy Kornatskyy avatar Andriy Kornatskyy committed e42913a

Added warning if pylibmc/memcache packages are not installed but corresponding cache implementations are imported.

Comments (0)

Files changed (4)

src/wheezy/caching/memcache.py

     Client = __import__('memcache', None, None, ['Client']).Client
 except ImportError:  # pragma: nocover
     Client = None
+    import warnings
+    warnings.warn("No module named 'memcache'", stacklevel=2)
 
 
 class MemcachedClient(object):
 
     def __init__(self, *args, **kwargs):
         self.key_encode = kwargs.pop('key_encode', string_encode)
+        if Client is None:  # pragma: nocover
+            raise ImportError("No module named 'memcache'")
         self.client = Client(*args, **kwargs)
 
     def set(self, key, value, time=0, namespace=None):

src/wheezy/caching/pylibmc.py

 
     del c
 except ImportError:  # pragma: nocover
-    pass
+    import warnings
+    warnings.warn("No module named 'pylibmc'", stacklevel=2)
 
 
 class MemcachedClient(object):

src/wheezy/caching/tests/test_memcache.py

 from unittest import TestCase
 
 from wheezy.caching.tests.test_cache import CacheTestMixin
+from wheezy.caching.memcache import Client
 
-try:
+
+if Client:
     from wheezy.caching.memcache import MemcachedClient
 
     class MemcacheClientTestCase(TestCase, CacheTestMixin):
             assert self.client.delete('d')
             self.setget('d', 1)
             assert self.client.delete('d')
-
-except ImportError:
-    pass

src/wheezy/caching/tests/test_pylibmc.py

 
 
 try:
+    from wheezy.caching.pylibmc import client_factory
+except ImportError:
+    pass
+else:
     from wheezy.caching.pylibmc import MemcachedClient
-    from wheezy.caching.pylibmc import client_factory
 
     class EagerPool(object):
 
             assert not self.client.delete_multi(keys)
             self.setget_multi(mapping)
             assert self.client.delete_multi(keys)
-
-except ImportError:
-    pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.