diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-11-13 16:04:47 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-11-13 16:04:47 -0500 |
commit | 5dcc3367619ae8bcd1b34019e8727d4050bb2747 (patch) | |
tree | b05085dedee8056d9aa16d0392675e2b0a2a273b /tests | |
parent | 8cc7e8d184168f36fb05cac96834ea7ec35fb8a0 (diff) | |
download | dogpile-cache-5dcc3367619ae8bcd1b34019e8727d4050bb2747.tar.gz |
Add subclasshook for CacheMutex
Also restore python-memcached to test suite
Change-Id: If4cd5e4604a0c5b51e1b34ba5a1a397ec1ef15cf
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cache/_fixtures.py | 7 | ||||
-rw-r--r-- | tests/cache/test_region.py | 32 |
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/cache/_fixtures.py b/tests/cache/_fixtures.py index e55c471..1be5a2c 100644 --- a/tests/cache/_fixtures.py +++ b/tests/cache/_fixtures.py @@ -12,6 +12,7 @@ import pytest from dogpile.cache import CacheRegion from dogpile.cache import register_backend from dogpile.cache.api import CacheBackend +from dogpile.cache.api import CacheMutex from dogpile.cache.api import NO_VALUE from dogpile.cache.region import _backend_loader from . import assert_raises_message @@ -395,6 +396,12 @@ class _GenericMutexTest(_GenericBackendFixture, TestCase): assert ac3 mutex.release() + def test_subclass_match(self): + backend = self._backend() + mutex = backend.get_mutex("foo") + + assert isinstance(mutex, CacheMutex) + @pytest.mark.time_intensive def test_mutex_threaded(self): backend = self._backend() diff --git a/tests/cache/test_region.py b/tests/cache/test_region.py index 7168433..087d533 100644 --- a/tests/cache/test_region.py +++ b/tests/cache/test_region.py @@ -13,6 +13,7 @@ from dogpile.cache import make_region from dogpile.cache import util from dogpile.cache.api import CacheBackend from dogpile.cache.api import CachedValue +from dogpile.cache.api import CacheMutex from dogpile.cache.api import NO_VALUE from dogpile.cache.proxy import ProxyBackend from dogpile.cache.region import _backend_loader @@ -605,6 +606,37 @@ class TestProxyValue(object): self.value = value +class MutexAPITest(TestCase): + def test_mutex_non_match(self): + assert not isinstance(5, CacheMutex) + assert not isinstance("some string", CacheMutex) + + class Foo: + def release(self): + pass + + assert not isinstance(Foo(), CacheMutex) + + class Bar: + def acquire(self): + pass + + assert not isinstance(Bar(), CacheMutex) + + def test_mutex_match(self): + class Foo: + def acquire(self): + # note we are missing the "wait" parameter. not sure + # how ABCs are supposed to efficiently test these + # things. + pass + + def release(self): + pass + + assert isinstance(Foo(), CacheMutex) + + class AsyncCreatorTest(TestCase): def _fixture(self): def async_creation_runner(cache, somekey, creator, mutex): |