Skip to content

Commit aabb6d2

Browse files
authored
feat: add valkey module and keydb and dragonfly redis services (#83)
- Consolidate AlloyDB into the existing postgres module. - Updated tags for AlloyDB Omni and pgvector - Add `postgres_user` and `postgres_password` fixtures. - Add dedicated `keydb` and `dragonfly` fixtures - Add `valkey` service that uses `valkey` python client instead of `redis`
1 parent 5ba7b2d commit aabb6d2

File tree

18 files changed

+906
-587
lines changed

18 files changed

+906
-587
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919

2020
# Ruff replaces black, flake8, autoflake and isort
2121
- repo: https://github.com/charliermarsh/ruff-pre-commit
22-
rev: "v0.11.8" # make sure this is always consistent with hatch configs
22+
rev: "v0.11.11" # make sure this is always consistent with hatch configs
2323
hooks:
2424
- id: ruff
2525
args: [--config, ./pyproject.toml]

docs/supported-databases/alloydb.rst

Lines changed: 0 additions & 49 deletions
This file was deleted.

docs/supported-databases/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ This section provides detailed information on the supported databases, including
1111
mariadb
1212
oracle
1313
sqlserver
14-
alloydb
1514
spanner
1615
bigquery
1716
cockroachdb
1817
redis
18+
valkey
1919
elasticsearch
2020
azure_blob_storage
2121
minio

docs/supported-databases/postgres.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PostgreSQL
22
==========
33

4-
Integration with `PostgreSQL <https://www.postgresql.org/>`_ using the `PostgreSQL Docker Image <https://hub.docker.com/_/postgres>`_ or `pgvector Docker Image <https://hub.docker.com/r/ankane/pgvector>`_
4+
Integration with `PostgreSQL <https://www.postgresql.org/>`_ using the `PostgreSQL Docker Image <https://hub.docker.com/_/postgres>`_, Google's `AlloyDB Omni <https://cloud.google.com/alloydb/omni?hl=en>`_ or `pgvector Docker Image <https://hub.docker.com/r/ankane/pgvector>`_
55

66
Installation
77
------------
@@ -36,22 +36,25 @@ Usage Example
3636
Available Fixtures
3737
------------------
3838

39+
* ``postgres_user``: The PostgreSQL user.
40+
* ``postgres_password``: The PostgreSQL password.
41+
* ``postgres_database``: The PostgreSQL database name to use.
3942
* ``postgres_image``: The Docker image to use for PostgreSQL.
4043
* ``postgres_service``: A fixture that provides a PostgreSQL service.
4144
* ``postgres_connection``: A fixture that provides a PostgreSQL connection.
4245

4346
The following version-specific fixtures are also available:
4447

48+
* ``alloydb_omni_image``, ``alloydb_omni_service``, ``alloydb_omni_connection``: Latest Available AlloyDB Omni 16 Docker image.
4549
* ``postgres_11_image``, ``postgres_11_service``, ``postgres_11_connection``: PostgreSQL 11.x
4650
* ``postgres_12_image``, ``postgres_12_service``, ``postgres_12_connection``: PostgreSQL 12.x
4751
* ``postgres_13_image``, ``postgres_13_service``, ``postgres_13_connection``: PostgreSQL 13.x
4852
* ``postgres_14_image``, ``postgres_14_service``, ``postgres_14_connection``: PostgreSQL 14.x
4953
* ``postgres_15_image``, ``postgres_15_service``, ``postgres_15_connection``: PostgreSQL 15.x
5054
* ``postgres_16_image``, ``postgres_16_service``, ``postgres_16_connection``: PostgreSQL 16.x
5155
* ``postgres_17_image``, ``postgres_17_service``, ``postgres_17_connection``: PostgreSQL 17.x
52-
* ``pgvector_image``: The Docker image to use for pgvector.
53-
* ``pgvector_service``: A fixture that provides a pgvector service.
54-
* ``pgvector_connection``: A fixture that provides a pgvector connection.
56+
* ``pgvector_image``, ``pgvector_service``. ``pgvector_connection``: Latest Available pgvector Docker image.
57+
5558

5659
Service API
5760
-----------

docs/supported-databases/redis.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Redis
22
=====
33

4-
Integration with `Redis <https://redis.io/>`_
4+
Integration with `Redis <https://redis.io/>`_ using the `Redis Docker Image <https://hub.docker.com/_/redis>`_, Snap's `Key DB<https://docs.keydb.dev/>` or `Dragonfly <https://www.dragonflydb.io/>`_.
55

66
Installation
77
------------
@@ -43,6 +43,11 @@ Available Fixtures
4343
* ``redis_service``: A fixture that provides a Redis service.
4444
* ``redis_connection``: A fixture that provides a Redis connection.
4545

46+
The following version-specific fixtures are also available:
47+
48+
* ``dragonflydb_port``, ``dragonflydb_host``, ``dragonflydb_image``, ``dragonflydb_service``, ``dragonflydb_connection``: Latest Available DragonflyDB Docker image.
49+
* ``keydb_port``, ``keydb_host``, ``keydb_image``, ``keydb_service``, ``keydb_connection``: Latest Available KeyDB Docker image.
50+
4651
Service API
4752
-----------
4853

docs/supported-databases/valkey.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Valkey
2+
======
3+
4+
Integration with `Valkey <https://valkey.io//>`_ using the `Valkey Docker Image <https://hub.docker.com/_/valkey>`_
5+
6+
Installation
7+
------------
8+
9+
.. code-block:: bash
10+
11+
pip install pytest-databases[valkey]
12+
13+
Usage Example
14+
-------------
15+
16+
.. code-block:: python
17+
18+
import pytest
19+
from valkey import Valkey
20+
from pytest_databases.docker.valkey import ValkeyService
21+
22+
pytest_plugins = ["pytest_databases.docker.valkey"]
23+
24+
def test(valkey_service: ValkeyService) -> None:
25+
client = Valkey(
26+
host=valkey_service.host,
27+
port=valkey_service.port,
28+
db=valkey_service.db
29+
)
30+
client.set("test_key", "test_value")
31+
assert client.get("test_key") == b"test_value"
32+
33+
def test(valkey_connection: Valkey) -> None:
34+
valkey_connection.set("test_key", "test_value")
35+
assert valkey_connection.get("test_key") == b"test_value"
36+
37+
Available Fixtures
38+
------------------
39+
40+
* ``valkey_port``: The port number for the Valkey service.
41+
* ``valkey_host``: The host name for the Valkey service.
42+
* ``valkey_image``: The Docker image to use for Valkey.
43+
* ``valkey_service``: A fixture that provides a Valkey service.
44+
* ``valkey_connection``: A fixture that provides a Valkey connection.
45+
46+
Service API
47+
-----------
48+
49+
.. automodule:: pytest_databases.docker.valkey
50+
:members:
51+
:undoc-members:
52+
:show-inheritance:

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ keywords = [
3131
"redis",
3232
"elasticsearch",
3333
"azure",
34+
"valkey",
35+
"dragonflydb",
3436
]
3537
# options under https://pypi.org/classifiers/
3638
classifiers = [
@@ -68,12 +70,13 @@ oracle = ["oracledb"]
6870
postgres = ["psycopg>=3"]
6971
redis = ["redis"]
7072
spanner = ["google-cloud-spanner"]
73+
valkey = ["valkey"]
7174

7275
[dependency-groups]
7376
dev = [
7477
# tests
7578
"bump-my-version",
76-
"pytest-databases[azure-storage,bigquery,cockroachdb,dragonfly,elasticsearch7,elasticsearch8,keydb,mssql,mysql,mariadb,oracle,postgres,redis,spanner,minio]",
79+
"pytest-databases[azure-storage,bigquery,cockroachdb,dragonfly,elasticsearch7,elasticsearch8,keydb,mssql,mysql,mariadb,oracle,postgres,redis,spanner,minio,valkey]",
7780
"coverage[toml]>=6.2",
7881
"pytest",
7982
"pytest-cov",
@@ -83,7 +86,7 @@ dev = [
8386
"pytest-xdist",
8487
"pytest-sugar",
8588
"slotscheck",
86-
"psycopg-binary", # This fixes tests failing on M series CPUs.
89+
"psycopg-binary", # This fixes tests failing on M series CPUs.
8790
# lint
8891
"mypy",
8992
"ruff",

src/pytest_databases/_service.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from contextlib import AbstractContextManager, contextmanager
99
from typing import TYPE_CHECKING, Any, Callable
1010

11-
import docker
1211
import filelock
1312
import pytest
14-
from docker.errors import ImageNotFound
13+
from docker.errors import APIError, ImageNotFound
1514
from typing_extensions import Self
1615

16+
from docker import DockerClient
1717
from pytest_databases.helpers import get_xdist_worker_id
1818
from pytest_databases.types import ServiceContainer
1919

@@ -48,14 +48,14 @@ def get_docker_host() -> str:
4848
return next(context["DockerEndpoint"] for context in contexts if context["Current"] is True)
4949

5050

51-
def get_docker_client() -> docker.DockerClient:
51+
def get_docker_client() -> DockerClient:
5252
env = {**os.environ}
5353
if "DOCKER_HOST" not in env:
5454
env["DOCKER_HOST"] = get_docker_host()
55-
return docker.DockerClient.from_env(environment=env)
55+
return DockerClient.from_env(environment=env)
5656

5757

58-
def _stop_all_containers(client: docker.DockerClient) -> None:
58+
def _stop_all_containers(client: DockerClient) -> None:
5959
containers: list[Container] = client.containers.list(
6060
all=True,
6161
filters={"label": "pytest_databases"},
@@ -76,7 +76,7 @@ def _stop_all_containers(client: docker.DockerClient) -> None:
7676
class DockerService(AbstractContextManager):
7777
def __init__(
7878
self,
79-
client: docker.DockerClient,
79+
client: DockerClient,
8080
tmp_path: pathlib.Path,
8181
session: pytest.Session,
8282
) -> None:
@@ -221,16 +221,16 @@ def run(
221221
try:
222222
container.stop()
223223
container.remove(force=True)
224-
except docker.errors.APIError as exc: # pyright: ignore[reportAttributeAccessIssue]
224+
except APIError as exc: # pyright: ignore[reportAttributeAccessIssue]
225225
# '409 - Conflict' means removal is already in progress. this is the
226-
# safest way of delaiyng with it, since the API is a bit borked when it
226+
# safest way of delaying with it, since the API is a bit borked when it
227227
# comes to concurrent requests
228228
if exc.status_code not in {409, 404}:
229229
raise
230230

231231

232232
@pytest.fixture(scope="session")
233-
def docker_client() -> Generator[docker.DockerClient, None, None]:
233+
def docker_client() -> Generator[DockerClient, None, None]:
234234
client = get_docker_client()
235235
try:
236236
yield client
@@ -240,7 +240,7 @@ def docker_client() -> Generator[docker.DockerClient, None, None]:
240240

241241
@pytest.fixture(scope="session")
242242
def docker_service(
243-
docker_client: docker.DockerClient,
243+
docker_client: DockerClient,
244244
tmp_path_factory: pytest.TempPathFactory,
245245
request: pytest.FixtureRequest,
246246
) -> Generator[DockerService, None, None]:

src/pytest_databases/docker/alloydb_omni.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)