File: test_interface_uniformity.py

package info (click to toggle)
cachelib 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: python: 1,555; makefile: 32; sh: 15
file content (32 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# type: ignore
import inspect

import pytest

from cachelib import BaseCache
from cachelib import FileSystemCache
from cachelib import MemcachedCache
from cachelib import RedisCache
from cachelib import SimpleCache


@pytest.fixture(autouse=True)
def create_cache_list(request, tmpdir):
    mc = MemcachedCache()
    mc._client.flush_all()
    rc = RedisCache(port=6360)
    rc._write_client.flushdb()
    request.cls.cache_list = [FileSystemCache(tmpdir), mc, rc, SimpleCache()]


@pytest.mark.usefixtures("redis_server", "memcached_server")
class TestInterfaceUniformity:
    def test_types_have_all_base_methods(self):
        public_api_methods = [
            meth
            for meth in inspect.getmembers(BaseCache, predicate=inspect.isfunction)
            if not meth[0].startswith("_")
        ]
        for cache_type in self.cache_list:
            for meth in public_api_methods:
                assert hasattr(cache_type, meth[0]) and callable(meth[1])