Skip to content

Commit 8d2c24c

Browse files
committed
Refactor example configurations and tests
- Deleted outdated test configuration examples for asyncpg and psycopg. - Added new example configurations for SQLite, asyncpg, psycopg, asyncmy, and DuckDB. - Introduced environment-based configuration examples for better flexibility. - Updated documentation references to point to the new example files. - Enhanced test cases to cover various best practices, including connection pooling, caching, and resource cleanup. - Improved clarity and organization of configuration examples for better usability.
1 parent 5c5d60d commit 8d2c24c

39 files changed

+297
-189
lines changed

AGENTS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ This summary documents the small documentation and example maintenance
524524
performed on the configuration usage guide and can be expanded into a
525525
longer changelog entry if desired.
526526

527-
528527
```python
529528
def parse_user_input(content: str, source: str) -> "dict[str, Result]":
530529
"""Parse user input with two-tier error handling.

docs/examples/usage/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Generator
4+
5+
import pytest
6+
from pytest_databases.docker.postgres import PostgresService
7+
8+
pytest_plugins = ["pytest_databases.docker.postgres"]
9+
10+
11+
@pytest.fixture(scope="session", autouse=True)
12+
def usage_postgres_env(postgres_service: PostgresService) -> Generator[None, None, None]:
13+
"""Expose Postgres connection settings via env vars for docs examples."""
14+
15+
patcher = pytest.MonkeyPatch()
16+
dsn = (
17+
f"postgresql://{postgres_service.user}:{postgres_service.password}"
18+
f"@{postgres_service.host}:{postgres_service.port}/{postgres_service.database}"
19+
)
20+
patcher.setenv("SQLSPEC_USAGE_PG_DSN", dsn)
21+
patcher.setenv("SQLSPEC_USAGE_PG_HOST", postgres_service.host)
22+
patcher.setenv("SQLSPEC_USAGE_PG_PORT", str(postgres_service.port))
23+
patcher.setenv("SQLSPEC_USAGE_PG_USER", postgres_service.user)
24+
patcher.setenv("SQLSPEC_USAGE_PG_PASSWORD", postgres_service.password)
25+
patcher.setenv("SQLSPEC_USAGE_PG_DATABASE", postgres_service.database)
26+
yield
27+
patcher.undo()

docs/examples/usage/test_configuration_19.py

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

docs/examples/usage/test_configuration_20.py

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

docs/examples/usage/test_configuration_23.py

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

docs/examples/usage/test_configuration_4.py

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

docs/examples/usage/test_configuration_5.py

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

docs/examples/usage/test_configuration_9.py

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

docs/examples/usage/test_configuration_1.py renamed to docs/examples/usage/usage_configuration_1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ def test_sqlite_memory_db() -> None:
33
from sqlspec.adapters.sqlite import SqliteConfig
44

55
# Create SQLSpec instance
6-
spec = SQLSpec()
6+
db_manager = SQLSpec()
77

88
# Add database configuration
9-
db = spec.add_config(SqliteConfig(pool_config={"database": ":memory:"}))
9+
db = db_manager.add_config(SqliteConfig(pool_config={"database": ":memory:"}))
1010

1111
# Use the database
12-
with spec.provide_session(db) as session:
12+
with db_manager.provide_session(db) as session:
1313
result = session.execute("SELECT 1")
1414
assert result[0] == {"1": 1}

docs/examples/usage/test_configuration_10.py renamed to docs/examples/usage/usage_configuration_10.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33

44
def test_manual_pool() -> None:
5+
import os
6+
57
from sqlspec.adapters.asyncpg import AsyncpgConfig
68

7-
pool = {"dsn": "postgresql://localhost/db", "min_size": 10, "max_size": POOL_INSTANCE}
9+
dsn = os.getenv("SQLSPEC_USAGE_PG_DSN", "postgresql://localhost/db")
10+
pool = {"dsn": dsn, "min_size": 10, "max_size": POOL_INSTANCE}
811
db = AsyncpgConfig(pool_instance=pool)
912
assert db.pool_instance["max_size"] == POOL_INSTANCE

0 commit comments

Comments
 (0)