Skip to content

Commit a6256a6

Browse files
committed
fix tests, one not passing when using provide_session by bind_key
1 parent 2ca1def commit a6256a6

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

docs/examples/usage/test_configuration_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def test_sqlite_memory_db() -> None:
1111
# Use the database
1212
with spec.provide_session(db) as session:
1313
result = session.execute("SELECT 1")
14-
assert result.fetchone()[0] == 1
14+
assert result[0] == {"1": 1}

docs/examples/usage/test_configuration_19.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def test_binding_multiple_configs() -> None:
1414

1515
# Add multiple configurations
1616
sqlite_db = spec.add_config(SqliteConfig(pool_config={"database": tmp.name}))
17-
postgres_db = spec.add_config(AsyncpgConfig(pool_config={"dsn": "postgresql://..."}))
17+
spec.add_config(AsyncpgConfig(pool_config={"dsn": "postgresql://..."}))
1818

1919
# Use specific configuration
2020
with spec.provide_session(sqlite_db) as session:
2121
session.execute("SELECT 1")
2222

23-
assert sqlite_db.pool_config["database"] == tmp.name
24-
assert postgres_db.pool_config["dsn"] == "postgresql://..."
23+
assert spec.configs[SqliteConfig].pool_config["database"] == tmp.name
24+
assert spec.configs[AsyncpgConfig].pool_config["dsn"] == "postgresql://..."

docs/examples/usage/test_configuration_20.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def test_named_bindings() -> None:
1313
spec = SQLSpec()
1414

1515
# Add with bind keys
16-
cache_db = spec.add_config(SqliteConfig(pool_config={"database": tmp.name}), bind_key="cache_db")
17-
main_db = spec.add_config(AsyncpgConfig(pool_config={"dsn": "postgresql://..."}), bind_key="main_db")
16+
spec.add_config(SqliteConfig(pool_config={"database": tmp.name}, bind_key="cache_db"))
17+
spec.add_config(AsyncpgConfig(pool_config={"dsn": "postgresql://..."}, bind_key="main_db"))
1818

1919
# Access by bind key
2020
with spec.provide_session("cache_db") as session:
2121
session.execute("SELECT 1")
2222

23-
assert cache_db.pool_config["database"] == tmp.name
24-
assert main_db.pool_config["dsn"] == "postgresql://..."
23+
assert spec.configs[SqliteConfig].pool_config["database"] == tmp.name
24+
assert spec.configs[AsyncpgConfig].pool_config["dsn"] == "postgresql://..."

docs/examples/usage/test_configuration_26.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test configuration example: Best practice - Tune pool sizes."""
22

3+
34
def test_tune_pool_sizes_best_practice() -> None:
45
"""Test pool sizing best practices for different workloads."""
56

@@ -13,14 +14,15 @@ def test_tune_pool_sizes_best_practice() -> None:
1314
assert io_bound_pool_config["min_size"] == 20
1415
assert io_bound_pool_config["max_size"] == 50
1516

17+
1618
def test_disable_security_checks_best_practice() -> None:
1719
"""Test disabling security checks when necessary."""
1820

1921
from sqlspec.core.statement import StatementConfig
2022

2123
# Example: Disabling security checks for trusted internal queries
2224
statement_config = StatementConfig(
23-
dialect="postgres",
24-
enable_validation=False, # Skip security checks
25-
)
25+
dialect="postgres",
26+
enable_validation=False, # Skip security checks
27+
)
2628
assert statement_config.enable_validation is False

docs/examples/usage/test_configuration_27.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Test configuration example: Best practice - Clean up resources."""
22

3-
43
import pytest
54

65

docs/examples/usage/test_configuration_3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def test_memory_databases() -> None:
33

44
# In-memory database (isolated per connection)
55
config = SqliteConfig(pool_config={"database": ":memory:"})
6-
assert config.pool_config["database"] == ":memory:"
6+
assert ":memory_" in config.pool_config["database"]
77

88
# Shared memory database
99
shared_config = SqliteConfig(pool_config={"database": "file:memdb1?mode=memory&cache=shared", "uri": True})

docs/examples/usage/test_configuration_7.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def test_duckdb_config_setup() -> None:
22
from sqlspec.adapters.duckdb import DuckDBConfig
33

44
in_memory_config = DuckDBConfig()
5-
assert in_memory_config.pool_config == {}
5+
assert in_memory_config.pool_config.get("database") == ":memory:shared_db"
66

77
persistent_config = DuckDBConfig(pool_config={"database": "analytics.duckdb", "read_only": False})
88
assert persistent_config.pool_config["read_only"] is False

docs/examples/usage/test_configuration_9.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ def test_pool_lifecycle() -> None:
44

55
spec = SQLSpec()
66
db = spec.add_config(AsyncpgConfig(pool_config={"dsn": "postgresql://localhost/db"}))
7-
assert db.pool_config["dsn"] == "postgresql://localhost/db"
7+
assert spec.configs[AsyncpgConfig].pool_config["dsn"] == "postgresql://localhost/db"

0 commit comments

Comments
 (0)