| 1 |
# type: ignore |
| 2 |
import inspect |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from cachelib import BaseCache |
| 7 |
from cachelib import FileSystemCache |
| 8 |
from cachelib import MemcachedCache |
| 9 |
from cachelib import RedisCache |
| 10 |
from cachelib import SimpleCache |
| 11 |
|
| 12 |
|
| 13 |
@pytest.fixture(autouse=True) |
| 14 |
def create_cache_list(request, tmpdir): |
| 15 |
mc = MemcachedCache(servers=["127.0.0.1:11212"]) |
| 16 |
mc.clear() |
| 17 |
rc = RedisCache(port=6360) |
| 18 |
rc._write_client.flushdb() |
| 19 |
request.cls.cache_list = [FileSystemCache(tmpdir), mc, rc, SimpleCache()] |
| 20 |
|
| 21 |
|
| 22 |
@pytest.mark.network |
| 23 |
@pytest.mark.usefixtures("redis_server", "memcached_server") |
| 24 |
class TestInterfaceUniformity: |
| 25 |
def test_types_have_all_base_methods(self): |
| 26 |
public_api_methods = [ |
| 27 |
meth |
| 28 |
for meth in inspect.getmembers(BaseCache, predicate=inspect.isfunction) |
| 29 |
if not meth[0].startswith("_") |
| 30 |
] |
| 31 |
for cache_type in self.cache_list: |
| 32 |
for meth in public_api_methods: |
| 33 |
assert hasattr(cache_type, meth[0]) and callable(meth[1]) |