From 12f7cb63653fc34b084423cdef696e7231e2d481 Mon Sep 17 00:00:00 2001 From: profitroll Date: Sun, 16 Feb 2025 17:16:05 +0100 Subject: [PATCH] Added some basic tests for Cache --- tests/config.json | 9 +++++++++ tests/test_cache.py | 28 ++++++++++++++++++++++++++++ tox.ini | 5 +++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/test_cache.py diff --git a/tests/config.json b/tests/config.json index da84a0c..3009f0f 100644 --- a/tests/config.json +++ b/tests/config.json @@ -2,5 +2,14 @@ "locale": "en", "bot": { "bot_token": "sample_token" + }, + "cache": { + "type": "memcached", + "memcached": { + "uri": "127.0.0.1:11211" + }, + "redis": { + "uri": "redis://127.0.0.1:6379/0" + } } } \ No newline at end of file diff --git a/tests/test_cache.py b/tests/test_cache.py new file mode 100644 index 0000000..5a18a8b --- /dev/null +++ b/tests/test_cache.py @@ -0,0 +1,28 @@ +from pathlib import Path + +from libbot.cache.classes import Cache +from libbot.cache.manager import create_cache_client + +try: + from ujson import JSONDecodeError, dumps, loads +except ImportError: + from json import JSONDecodeError, dumps, loads + +from typing import Any, Dict + +import pytest + + +@pytest.mark.parametrize( + "engine", + [ + "memcached", + "redis", + ], +) +def test_cache_creation(engine: str, location_config: Path): + with open(location_config, "r", encoding="utf-8") as file: + config: Dict[str, Any] = loads(file.read()) + + cache: Cache = create_cache_client(config, engine) + assert isinstance(cache, Cache) diff --git a/tox.ini b/tox.ini index 7ee6a1c..a4fadce 100644 --- a/tox.ini +++ b/tox.ini @@ -10,13 +10,14 @@ python = 3.13: py313 [testenv] -setenv = +setenv = PYTHONPATH = {toxinidir} -deps = +deps = -r{toxinidir}/requirements/_.txt -r{toxinidir}/requirements/dev.txt -r{toxinidir}/requirements/pycord.txt -r{toxinidir}/requirements/pyrogram.txt -r{toxinidir}/requirements/speed.txt + -r{toxinidir}/requirements/cache.txt commands = pytest --basetemp={envtmpdir} --cov=libbot \ No newline at end of file