Skip to content

Commit f491edf

Browse files
style: apply ruff format to source and test files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent da2f650 commit f491edf

File tree

6 files changed

+22
-65
lines changed

6 files changed

+22
-65
lines changed

src/dqliteclient/connection.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ def _parse_address(address: str) -> tuple[str, int]:
3030
)
3131
bracket_end = address.index("]")
3232
host = address[1:bracket_end]
33-
port_str = address[bracket_end + 2:] # Skip ']:
33+
port_str = address[bracket_end + 2 :] # Skip ']:
3434
else:
3535
if ":" not in address:
36-
raise ValueError(
37-
f"Invalid address format: expected 'host:port', got {address!r}"
38-
)
36+
raise ValueError(f"Invalid address format: expected 'host:port', got {address!r}")
3937
host, port_str = address.rsplit(":", 1)
4038

4139
try:
@@ -101,13 +99,9 @@ async def connect(self) -> None:
10199
timeout=self._timeout,
102100
)
103101
except TimeoutError as e:
104-
raise DqliteConnectionError(
105-
f"Connection to {self._address} timed out"
106-
) from e
102+
raise DqliteConnectionError(f"Connection to {self._address} timed out") from e
107103
except OSError as e:
108-
raise DqliteConnectionError(
109-
f"Failed to connect to {self._address}: {e}"
110-
) from e
104+
raise DqliteConnectionError(f"Failed to connect to {self._address}: {e}") from e
111105

112106
self._protocol = DqliteProtocol(reader, writer, timeout=self._timeout)
113107

src/dqliteclient/pool.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def __init__(
3737
if max_size < 1:
3838
raise ValueError(f"max_size must be at least 1, got {max_size}")
3939
if min_size > max_size:
40-
raise ValueError(
41-
f"min_size ({min_size}) must not exceed max_size ({max_size})"
42-
)
40+
raise ValueError(f"min_size ({min_size}) must not exceed max_size ({max_size})")
4341
if timeout <= 0:
4442
raise ValueError(f"timeout must be positive, got {timeout}")
4543

@@ -122,9 +120,7 @@ async def acquire(self) -> AsyncIterator[DqliteConnection]:
122120
f"(max_size={self._max_size}, timeout={self._timeout}s)"
123121
)
124122
try:
125-
conn = await asyncio.wait_for(
126-
self._pool.get(), timeout=min(remaining, 0.5)
127-
)
123+
conn = await asyncio.wait_for(self._pool.get(), timeout=min(remaining, 0.5))
128124
except TimeoutError:
129125
# Don't fail yet — loop back to re-check _size
130126
continue

src/dqliteclient/protocol.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ async def exec_sql(
164164
raise OperationalError(response.code, response.message)
165165

166166
if not isinstance(response, ResultResponse):
167-
raise ProtocolError(
168-
f"Expected ResultResponse, got {type(response).__name__}"
169-
)
167+
raise ProtocolError(f"Expected ResultResponse, got {type(response).__name__}")
170168

171169
last_insert_id = response.last_insert_id
172170
rows_affected += response.rows_affected
@@ -220,13 +218,9 @@ async def query_sql(
220218
async def _read_data(self) -> bytes:
221219
"""Read data from the stream with timeout."""
222220
try:
223-
data = await asyncio.wait_for(
224-
self._reader.read(4096), timeout=self._timeout
225-
)
221+
data = await asyncio.wait_for(self._reader.read(4096), timeout=self._timeout)
226222
except TimeoutError:
227-
raise DqliteConnectionError(
228-
f"Server read timed out after {self._timeout}s"
229-
) from None
223+
raise DqliteConnectionError(f"Server read timed out after {self._timeout}s") from None
230224
if not data:
231225
raise DqliteConnectionError("Connection closed by server")
232226
return data

tests/integration/test_single_node.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ async def test_connect_and_query(self, cluster_address: str) -> None:
2323
async def test_create_table_and_insert(self, cluster_address: str) -> None:
2424
async with await connect(cluster_address) as conn:
2525
await conn.execute("DROP TABLE IF EXISTS test_single")
26-
await conn.execute(
27-
"CREATE TABLE test_single (id INTEGER PRIMARY KEY, name TEXT)"
28-
)
26+
await conn.execute("CREATE TABLE test_single (id INTEGER PRIMARY KEY, name TEXT)")
2927
await conn.execute("INSERT INTO test_single (name) VALUES (?)", ["test"])
3028

3129
rows = await conn.fetch("SELECT * FROM test_single WHERE name = ?", ["test"])
@@ -35,9 +33,7 @@ async def test_create_table_and_insert(self, cluster_address: str) -> None:
3533
async def test_transaction_commit(self, cluster_address: str) -> None:
3634
async with await connect(cluster_address) as conn:
3735
await conn.execute("DROP TABLE IF EXISTS test_tx")
38-
await conn.execute(
39-
"CREATE TABLE test_tx (id INTEGER PRIMARY KEY, val TEXT)"
40-
)
36+
await conn.execute("CREATE TABLE test_tx (id INTEGER PRIMARY KEY, val TEXT)")
4137

4238
async with conn.transaction():
4339
await conn.execute("INSERT INTO test_tx (val) VALUES (?)", ["committed"])
@@ -48,9 +44,7 @@ async def test_transaction_commit(self, cluster_address: str) -> None:
4844
async def test_transaction_rollback(self, cluster_address: str) -> None:
4945
async with await connect(cluster_address) as conn:
5046
await conn.execute("DROP TABLE IF EXISTS test_rollback")
51-
await conn.execute(
52-
"CREATE TABLE test_rollback (id INTEGER PRIMARY KEY, val TEXT)"
53-
)
47+
await conn.execute("CREATE TABLE test_rollback (id INTEGER PRIMARY KEY, val TEXT)")
5448

5549
try:
5650
async with conn.transaction():
@@ -61,18 +55,14 @@ async def test_transaction_rollback(self, cluster_address: str) -> None:
6155
except ValueError:
6256
pass
6357

64-
rows = await conn.fetch(
65-
"SELECT * FROM test_rollback WHERE val = ?", ["rollback_test"]
66-
)
58+
rows = await conn.fetch("SELECT * FROM test_rollback WHERE val = ?", ["rollback_test"])
6759
assert len(rows) == 0
6860

6961
async def test_unicode_text(self, cluster_address: str) -> None:
7062
"""Test Unicode text handling including emojis, CJK, RTL."""
7163
async with await connect(cluster_address) as conn:
7264
await conn.execute("DROP TABLE IF EXISTS test_unicode")
73-
await conn.execute(
74-
"CREATE TABLE test_unicode (id INTEGER PRIMARY KEY, val TEXT)"
75-
)
65+
await conn.execute("CREATE TABLE test_unicode (id INTEGER PRIMARY KEY, val TEXT)")
7666

7767
unicode_values = [
7868
# Emojis (4-byte UTF-8)
@@ -109,9 +99,7 @@ async def test_binary_blob(self, cluster_address: str) -> None:
10999
"""Test binary blob handling including null bytes."""
110100
async with await connect(cluster_address) as conn:
111101
await conn.execute("DROP TABLE IF EXISTS test_blob")
112-
await conn.execute(
113-
"CREATE TABLE test_blob (id INTEGER PRIMARY KEY, data BLOB)"
114-
)
102+
await conn.execute("CREATE TABLE test_blob (id INTEGER PRIMARY KEY, data BLOB)")
115103

116104
blob_values = [
117105
b"simple",
@@ -126,9 +114,7 @@ async def test_binary_blob(self, cluster_address: str) -> None:
126114
await conn.execute("INSERT INTO test_blob (data) VALUES (?)", [val])
127115

128116
# Retrieve and verify
129-
rows = await conn.fetch(
130-
"SELECT data FROM test_blob ORDER BY id DESC LIMIT 1"
131-
)
117+
rows = await conn.fetch("SELECT data FROM test_blob ORDER BY id DESC LIMIT 1")
132118
assert len(rows) == 1
133119
assert rows[0]["data"] == val, f"Mismatch for blob: {repr(val)}"
134120

@@ -172,9 +158,7 @@ async def test_boolean_values(self, cluster_address: str) -> None:
172158
"""Test boolean handling (SQLite uses INTEGER 0/1)."""
173159
async with await connect(cluster_address) as conn:
174160
await conn.execute("DROP TABLE IF EXISTS test_bool")
175-
await conn.execute(
176-
"CREATE TABLE test_bool (id INTEGER PRIMARY KEY, flag INTEGER)"
177-
)
161+
await conn.execute("CREATE TABLE test_bool (id INTEGER PRIMARY KEY, flag INTEGER)")
178162

179163
# Insert True and False as integers (SQLite doesn't have native BOOLEAN)
180164
await conn.execute("INSERT INTO test_bool (flag) VALUES (?)", [1])
@@ -190,21 +174,16 @@ async def test_datetime_as_text(self, cluster_address: str) -> None:
190174
async with await connect(cluster_address) as conn:
191175
await conn.execute("DROP TABLE IF EXISTS test_datetime")
192176
await conn.execute(
193-
"CREATE TABLE test_datetime "
194-
"(id INTEGER PRIMARY KEY, created_at TEXT)"
177+
"CREATE TABLE test_datetime (id INTEGER PRIMARY KEY, created_at TEXT)"
195178
)
196179

197180
# Store datetime as ISO8601 string
198181
now = datetime.datetime.now()
199182
iso_string = now.isoformat()
200183

201-
await conn.execute(
202-
"INSERT INTO test_datetime (created_at) VALUES (?)", [iso_string]
203-
)
184+
await conn.execute("INSERT INTO test_datetime (created_at) VALUES (?)", [iso_string])
204185

205-
rows = await conn.fetch(
206-
"SELECT created_at FROM test_datetime ORDER BY id DESC LIMIT 1"
207-
)
186+
rows = await conn.fetch("SELECT created_at FROM test_datetime ORDER BY id DESC LIMIT 1")
208187
assert len(rows) == 1
209188
assert rows[0]["created_at"] == iso_string
210189

tests/test_pool.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ async def test_acquire_timeout_when_pool_exhausted(self) -> None:
187187
async with pool.acquire():
188188
pass
189189

190-
191190
async def test_close_during_acquire_does_not_corrupt_size(self) -> None:
192191
"""Closing the pool while connections are in-use must not make _size negative."""
193192
import asyncio
@@ -430,7 +429,6 @@ async def test_close_then_return_closes_connection(self) -> None:
430429
# The connection should have been closed on return (not put back in queue)
431430
mock_conn.close.assert_called()
432431

433-
434432
async def test_user_exception_preserves_healthy_connection(self) -> None:
435433
"""A user-code exception should not destroy a healthy connection."""
436434
pool = ConnectionPool(["localhost:9001"], max_size=2)

tests/test_protocol.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ async def test_handshake_caps_heartbeat_timeout(
3838

3939
# Server sends an absurdly large heartbeat timeout (e.g., corrupted value)
4040
huge_timeout_ms = 10_000_000 # 10000 seconds
41-
mock_reader.read.return_value = WelcomeResponse(
42-
heartbeat_timeout=huge_timeout_ms
43-
).encode()
41+
mock_reader.read.return_value = WelcomeResponse(heartbeat_timeout=huge_timeout_ms).encode()
4442

4543
protocol = DqliteProtocol(mock_reader, mock_writer, timeout=10.0)
4644
await protocol.handshake()
@@ -265,9 +263,7 @@ async def test_prepare(
265263
) -> None:
266264
from dqlitewire.messages import StmtResponse
267265

268-
mock_reader.read.return_value = StmtResponse(
269-
db_id=1, stmt_id=1, num_params=2
270-
).encode()
266+
mock_reader.read.return_value = StmtResponse(db_id=1, stmt_id=1, num_params=2).encode()
271267

272268
stmt_id, num_params = await protocol.prepare(1, "INSERT INTO t VALUES (?, ?)")
273269

0 commit comments

Comments
 (0)