Skip to content

Commit

Permalink
fixed error message for cache proxy creation (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ar0ne authored Dec 22, 2023
1 parent a6a131e commit f9156e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aiocache/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Cache:
MEMCACHED = AIOCACHE_CACHES.get("memcached")

def __new__(cls, cache_class=MEMORY, **kwargs):
if not issubclass(cache_class, BaseCache):
if not (cache_class and issubclass(cache_class, BaseCache)):
raise InvalidCacheType(
"Invalid cache type, you can only use {}".format(list(AIOCACHE_CACHES.keys()))
)
Expand Down
5 changes: 3 additions & 2 deletions tests/ut/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ async def test_new(self, cache_type):
def test_new_defaults_to_memory(self):
assert isinstance(Cache(), Cache.MEMORY)

def test_new_invalid_cache_raises(self):
@pytest.mark.parametrize("cache_type", (None, object))
def test_new_invalid_cache_raises(self, cache_type):
with pytest.raises(InvalidCacheType) as e:
Cache(object)
Cache(cache_type)
assert str(e.value) == "Invalid cache type, you can only use {}".format(
list(AIOCACHE_CACHES.keys())
)
Expand Down

0 comments on commit f9156e3

Please sign in to comment.