diff --git a/aiocache/exceptions.py b/aiocache/exceptions.py index ead77b9c..e5db3b4d 100644 --- a/aiocache/exceptions.py +++ b/aiocache/exceptions.py @@ -1,4 +1,2 @@ - - class InvalidCacheType(Exception): pass diff --git a/aiocache/factory.py b/aiocache/factory.py index d24b5256..2d711e77 100644 --- a/aiocache/factory.py +++ b/aiocache/factory.py @@ -36,14 +36,14 @@ def _create_cache(cache, serializer=None, plugins=None, **kwargs): class Cache: - MEMORY = 'memory' - REDIS = 'redis' - MEMCACHED = 'memcached' + MEMORY = "memory" + REDIS = "redis" + MEMCACHED = "memcached" _PROTOCOL_MAPPING = { - 'memory': SimpleMemoryCache, - 'redis': RedisCache, - 'memcached': MemcachedCache, + "memory": SimpleMemoryCache, + "redis": RedisCache, + "memcached": MemcachedCache, } def __new__(cls, cache_type=MEMORY, **kwargs): @@ -51,8 +51,8 @@ def __new__(cls, cache_type=MEMORY, **kwargs): cache_class = cls.get_protocol_class(cache_type) except KeyError as e: raise InvalidCacheType( - 'Invalid cache type, you can only use {}'.format( - list(cls._PROTOCOL_MAPPING.keys()))) from e + "Invalid cache type, you can only use {}".format(list(cls._PROTOCOL_MAPPING.keys())) + ) from e instance = cache_class.__new__(cache_class, **kwargs) instance.__init__(**kwargs) diff --git a/tests/ut/test_factory.py b/tests/ut/test_factory.py index 46e28ec5..bad0e866 100644 --- a/tests/ut/test_factory.py +++ b/tests/ut/test_factory.py @@ -34,9 +34,9 @@ def test_create_cache_with_everything(): class TestCache: def test_cache_types(self): - assert Cache.MEMORY == 'memory' - assert Cache.REDIS == 'redis' - assert Cache.MEMCACHED == 'memcached' + assert Cache.MEMORY == "memory" + assert Cache.REDIS == "redis" + assert Cache.MEMCACHED == "memcached" @pytest.mark.parametrize("cache_type", [Cache.MEMORY, Cache.REDIS, Cache.MEMCACHED]) def test_new(self, cache_type): @@ -53,9 +53,10 @@ def test_new_defaults_to_memory(self): def test_new_invalid_cache_raises(self): with pytest.raises(InvalidCacheType) as e: - Cache('file') - assert str(e.value) == \ - "Invalid cache type, you can only use ['memory', 'redis', 'memcached']" + Cache("file") + assert str(e.value) == "Invalid cache type, you can only use {}".format( + list(Cache._PROTOCOL_MAPPING.keys()) + ) @pytest.mark.parametrize("protocol", [Cache.MEMORY, Cache.REDIS, Cache.MEMCACHED]) def test_get_protocol_class(self, protocol): @@ -63,7 +64,7 @@ def test_get_protocol_class(self, protocol): def test_get_protocol_class_invalid(self): with pytest.raises(KeyError): - Cache.get_protocol_class('http') + Cache.get_protocol_class("http") class TestCacheHandler: