Skip to content

Commit b85c152

Browse files
committed
linter issues
1 parent a6256a6 commit b85c152

File tree

8 files changed

+42
-18
lines changed

8 files changed

+42
-18
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
POOL_INSTANCE = 20
2+
3+
14
def test_manual_pool() -> None:
25
from sqlspec.adapters.asyncpg import AsyncpgConfig
36

4-
pool = {"dsn": "postgresql://localhost/db", "min_size": 10, "max_size": 20}
7+
pool = {"dsn": "postgresql://localhost/db", "min_size": 10, "max_size": POOL_INSTANCE}
58
db = AsyncpgConfig(pool_instance=pool)
6-
assert db.pool_instance["max_size"] == 20
9+
assert db.pool_instance["max_size"] == POOL_INSTANCE

docs/examples/usage/test_configuration_15.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Test configuration example: Global cache configuration."""
22

3+
SQL_CACHE_SIZE = 1000
4+
35

46
def test_global_cache_config() -> None:
57
"""Test global cache configuration."""
@@ -10,12 +12,12 @@ def test_global_cache_config() -> None:
1012
sql_cache_enabled=True, # Cache SQL strings
1113
fragment_cache_enabled=True, # Cache SQL fragments
1214
optimized_cache_enabled=True, # Cache optimized AST
13-
sql_cache_size=1000, # Maximum cached SQL items
15+
sql_cache_size=SQL_CACHE_SIZE, # Maximum cached SQL items
1416
)
1517

1618
# Update global cache configuration
1719
update_cache_config(cache_config)
1820

1921
# Verify config applied
2022
assert cache_config.sql_cache_enabled is True
21-
assert cache_config.sql_cache_size == 1000
23+
assert cache_config.sql_cache_size == SQL_CACHE_SIZE

docs/examples/usage/test_configuration_23.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def test_extension_config() -> None:
3232
}
3333

3434

35+
POSTGRES_PORT = 5433
36+
37+
3538
@pytest.mark.skipif(os.getenv("TEST_ASYNCPG", "0") != "1", reason="AsyncPG integration tests disabled")
3639
def test_environment_based_configuration() -> None:
3740
"""Test environment-based configuration pattern."""
@@ -59,7 +62,7 @@ def test_environment_based_configuration() -> None:
5962
)
6063

6164
assert config.pool_config["host"] == "testhost"
62-
assert config.pool_config["port"] == 5433
65+
assert config.pool_config["port"] == POSTGRES_PORT
6366
assert config.pool_config["user"] == "testuser"
6467
assert config.pool_config["password"] == "testpass"
6568
assert config.pool_config["database"] == "testdb"

docs/examples/usage/test_configuration_24.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import pytest
44

5+
MIN_POOL_SIZE = 10
6+
MAX_POOL_SIZE = 20
7+
58

69
@pytest.mark.skipif(
710
not pytest.importorskip("asyncpg", reason="AsyncPG not installed"), reason="AsyncPG integration tests disabled"
@@ -10,8 +13,10 @@ def test_connection_pooling_best_practice() -> None:
1013
"""Test connection pooling best practice configuration."""
1114
from sqlspec.adapters.asyncpg import AsyncpgConfig
1215

13-
config = AsyncpgConfig(pool_config={"dsn": "postgresql://localhost/db", "min_size": 10, "max_size": 20})
16+
config = AsyncpgConfig(
17+
pool_config={"dsn": "postgresql://localhost/db", "min_size": MIN_POOL_SIZE, "max_size": MAX_POOL_SIZE}
18+
)
1419

15-
assert config.pool_config["min_size"] == 10
16-
assert config.pool_config["max_size"] == 20
20+
assert config.pool_config["min_size"] == MIN_POOL_SIZE
21+
assert config.pool_config["max_size"] == MAX_POOL_SIZE
1722
assert config.supports_connection_pooling is True

docs/examples/usage/test_configuration_26.py

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

3+
MIN_POOL_SIZE_CPU = 5
4+
MAX_POOL_SIZE_CPU = 10
5+
MIN_IO_BOUND_POOL_SIZE = 20
6+
MAX_IO_BOUND_POOL_SIZE = 50
7+
38

49
def test_tune_pool_sizes_best_practice() -> None:
510
"""Test pool sizing best practices for different workloads."""
611

712
# CPU-bound workload - smaller pool
8-
cpu_bound_pool_config = {"min_size": 5, "max_size": 10}
9-
assert cpu_bound_pool_config["min_size"] == 5
10-
assert cpu_bound_pool_config["max_size"] == 10
13+
cpu_bound_pool_config = {"min_size": MIN_POOL_SIZE_CPU, "max_size": MAX_POOL_SIZE_CPU}
14+
assert cpu_bound_pool_config["min_size"] == MIN_POOL_SIZE_CPU
15+
assert cpu_bound_pool_config["max_size"] == MAX_POOL_SIZE_CPU
1116

1217
# I/O-bound workload - larger pool
13-
io_bound_pool_config = {"min_size": 20, "max_size": 50}
14-
assert io_bound_pool_config["min_size"] == 20
15-
assert io_bound_pool_config["max_size"] == 50
18+
io_bound_pool_config = {"min_size": MIN_IO_BOUND_POOL_SIZE, "max_size": MAX_IO_BOUND_POOL_SIZE}
19+
assert io_bound_pool_config["min_size"] == MIN_IO_BOUND_POOL_SIZE
20+
assert io_bound_pool_config["max_size"] == MAX_IO_BOUND_POOL_SIZE
1621

1722

1823
def test_disable_security_checks_best_practice() -> None:
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
MYSQL_PORT = 3306
2+
3+
14
def test_asyncmy_config_setup() -> None:
25
from sqlspec.adapters.asyncmy import AsyncmyConfig
36

47
config = AsyncmyConfig(
58
pool_config={
69
"host": "localhost",
7-
"port": 3306,
10+
"port": MYSQL_PORT,
811
"user": "myuser",
912
"password": "mypassword",
1013
"database": "mydb",
@@ -14,4 +17,4 @@ def test_asyncmy_config_setup() -> None:
1417
"pool_recycle": 3600,
1518
}
1619
)
17-
assert config.pool_config["port"] == 3306
20+
assert config.pool_config["port"] == MYSQL_PORT

docs/examples/usage/test_configuration_8.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
MIN_POOL_SIZE = 10
2+
3+
14
def test_asyncpg_pool_setup() -> None:
25
from sqlspec.adapters.asyncpg import AsyncpgConfig
36

@@ -10,4 +13,4 @@ def test_asyncpg_pool_setup() -> None:
1013
"max_inactive_connection_lifetime": 300.0,
1114
}
1215
)
13-
assert config.pool_config["min_size"] == 10
16+
assert config.pool_config["min_size"] == MIN_POOL_SIZE

docs/examples/usage/test_configuration_9.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ def test_pool_lifecycle() -> None:
33
from sqlspec.adapters.asyncpg import AsyncpgConfig
44

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

0 commit comments

Comments
 (0)