Skip to content

Commit d223821

Browse files
authored
Update ruff config (#33)
1 parent 6df3de3 commit d223821

File tree

8 files changed

+48
-80
lines changed

8 files changed

+48
-80
lines changed

Justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ run-artemis:
1818
docker compose up
1919

2020
run-consumer:
21-
uv -q run python testing/consumer.py
21+
ARTEMIS_HOST=0.0.0.0 uv -q run python testing/consumer.py
2222

2323
run-producer:
24-
uv -q run python testing/producer.py
24+
ARTEMIS_HOST=0.0.0.0 uv -q run python testing/producer.py
2525

2626
test-integration *args:
2727
#!/bin/bash

pyproject.toml

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ build-backend = "hatchling.build"
3737
[tool.hatch.version]
3838
source = "vcs"
3939

40+
4041
[tool.mypy]
4142
python_version = "3.11"
4243
warn_unused_ignores = true
@@ -51,32 +52,8 @@ line-length = 120
5152
[tool.ruff.lint]
5253
preview = true
5354
select = ["ALL"]
54-
ignore = [
55-
"EM",
56-
"FBT",
57-
"TRY003",
58-
"D1",
59-
"D203",
60-
"D213",
61-
"G004",
62-
"FA",
63-
"ANN101",
64-
"ANN102",
65-
"COM812",
66-
"ISC001",
67-
"S101",
68-
"SLF001",
69-
"CPY001",
70-
"S104",
71-
]
72-
extend-per-file-ignores = { "tests/*" = [
73-
"ARG002",
74-
"ARG003",
75-
"PLR6301",
76-
"ANN401",
77-
"PLC2801",
78-
] }
79-
55+
ignore = ["D1", "D203", "D213", "COM812", "ISC001", "CPY001"]
56+
extend-per-file-ignores = { "tests/*" = ["S101", "SLF001", "ARG"] }
8057

8158
[tool.pytest.ini_options]
8259
addopts = "--cov -s"

stompman/client.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ def from_pydantic_multihost_hosts(cls, hosts: list[MultiHostHostLike]) -> list[S
9090
servers: list[Self] = []
9191
for host in hosts:
9292
if host["host"] is None:
93-
raise ValueError("host must be set")
93+
msg = "host must be set"
94+
raise ValueError(msg)
9495
if host["port"] is None:
95-
raise ValueError("port must be set")
96+
msg = "port must be set"
97+
raise ValueError(msg)
9698
if host["username"] is None:
97-
raise ValueError("username must be set")
99+
msg = "username must be set"
100+
raise ValueError(msg)
98101
if host["password"] is None:
99-
raise ValueError("password must be set")
102+
msg = "password must be set"
103+
raise ValueError(msg)
104+
100105
servers.append(cls(host=host["host"], port=host["port"], login=host["username"], passcode=host["password"]))
101106
return servers
102107

@@ -277,7 +282,8 @@ async def listen(self) -> AsyncIterator["AnyListeningEvent"]:
277282
case HeartbeatFrame():
278283
yield HeartbeatEvent(_client=self, _frame=frame)
279284
case ConnectedFrame() | ReceiptFrame():
280-
raise AssertionError("Should be unreachable! Report the issue.", frame)
285+
msg = "Should be unreachable! Report the issue."
286+
raise AssertionError(msg, frame)
281287

282288

283289
@dataclass
@@ -290,9 +296,9 @@ def __post_init__(self) -> None:
290296
self.body = self._frame.body
291297

292298
async def ack(self) -> None:
293-
if self._client._connection.active:
299+
if self._client._connection.active: # noqa: SLF001
294300
with suppress(ConnectionLostError):
295-
await self._client._connection.write_frame(
301+
await self._client._connection.write_frame( # noqa: SLF001
296302
AckFrame(
297303
headers={
298304
"id": self._frame.headers["message-id"],
@@ -302,9 +308,9 @@ async def ack(self) -> None:
302308
)
303309

304310
async def nack(self) -> None:
305-
if self._client._connection.active:
311+
if self._client._connection.active: # noqa: SLF001
306312
with suppress(ConnectionLostError):
307-
await self._client._connection.write_frame(
313+
await self._client._connection.write_frame( # noqa: SLF001
308314
NackFrame(
309315
headers={
310316
"id": self._frame.headers["message-id"],

testing/consumer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import asyncio
22

33
import stompman
4+
from tests.integration import CONNECTION_PARAMETERS
45

56

67
async def main() -> None:
78
async with (
8-
stompman.Client(servers=[stompman.ConnectionParameters("0.0.0.0", 61616, "admin", "=123")]) as client,
9+
stompman.Client(servers=[CONNECTION_PARAMETERS]) as client,
910
client.subscribe("DLQ"),
1011
):
1112
async for event in client.listen():

testing/producer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import asyncio
22

33
import stompman
4+
from tests.integration import CONNECTION_PARAMETERS
45

56

67
async def main() -> None:
78
async with (
8-
stompman.Client(servers=[stompman.ConnectionParameters("0.0.0.0", 61616, "admin", "admin")]) as client,
9+
stompman.Client(servers=[CONNECTION_PARAMETERS]) as client,
910
client.enter_transaction() as transaction,
1011
):
1112
for _ in range(10):

tests/integration.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections.abc import AsyncGenerator, Callable
44
from contextlib import asynccontextmanager
55
from itertools import starmap
6+
from typing import Final
67
from uuid import uuid4
78

89
import pytest
@@ -23,13 +24,16 @@
2324

2425
pytestmark = pytest.mark.anyio
2526

27+
CONNECTION_PARAMETERS: Final = stompman.ConnectionParameters(
28+
host=os.environ["ARTEMIS_HOST"], port=61616, login="admin", passcode="%3D123"
29+
)
30+
2631

2732
@asynccontextmanager
2833
async def create_client() -> AsyncGenerator[stompman.Client, None]:
29-
server = stompman.ConnectionParameters(
30-
host=os.environ["ARTEMIS_HOST"], port=61616, login="admin", passcode="%3D123"
31-
)
32-
async with stompman.Client(servers=[server], read_timeout=10, connection_confirmation_timeout=10) as client:
34+
async with stompman.Client(
35+
servers=[CONNECTION_PARAMETERS], read_timeout=10, connection_confirmation_timeout=10
36+
) as client:
3337
yield client
3438

3539

tests/test_client.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,15 @@
4444
@dataclass
4545
class BaseMockConnection(AbstractConnection):
4646
@classmethod
47-
async def connect(
48-
cls,
49-
host: str,
50-
port: int,
51-
timeout: int,
52-
) -> Self | None:
47+
async def connect(cls, host: str, port: int, timeout: int) -> Self | None:
5348
return cls()
5449

5550
async def close(self) -> None: ...
5651
def write_heartbeat(self) -> None: ...
5752
async def write_frame(self, frame: AnyClientFrame) -> None: ...
53+
@staticmethod
5854
async def read_frames(
59-
self,
60-
max_chunk_size: int,
61-
timeout: int,
55+
max_chunk_size: int, timeout: int
6256
) -> AsyncGenerator[AnyServerFrame, None]: # pragma: no cover
6357
await asyncio.Future()
6458
yield # type: ignore[misc]
@@ -69,14 +63,12 @@ def create_spying_connection(
6963
) -> tuple[type[AbstractConnection], list[AnyClientFrame | AnyServerFrame | HeartbeatFrame]]:
7064
@dataclass
7165
class BaseCollectingConnection(BaseMockConnection):
72-
async def write_frame(self, frame: AnyClientFrame) -> None:
66+
@staticmethod
67+
async def write_frame(frame: AnyClientFrame) -> None:
7368
collected_frames.append(frame)
7469

75-
async def read_frames(
76-
self,
77-
max_chunk_size: int,
78-
timeout: int,
79-
) -> AsyncGenerator[AnyServerFrame, None]:
70+
@staticmethod
71+
async def read_frames(max_chunk_size: int, timeout: int) -> AsyncGenerator[AnyServerFrame, None]:
8072
for frame in next(read_frames_iterator):
8173
collected_frames.append(frame)
8274
yield frame
@@ -149,12 +141,7 @@ async def connect(cls, host: str, port: int, timeout: int) -> Self | None:
149141
async def test_client_connect_to_one_server_fails() -> None:
150142
class MockConnection(BaseMockConnection):
151143
@classmethod
152-
async def connect(
153-
cls,
154-
host: str,
155-
port: int,
156-
timeout: int,
157-
) -> Self | None:
144+
async def connect(cls, host: str, port: int, timeout: int) -> Self | None:
158145
return None
159146

160147
client = EnrichedClient(connection_class=MockConnection)
@@ -187,12 +174,7 @@ async def connect(cls, host: str, port: int, timeout: int) -> Self | None:
187174
async def test_client_connect_to_any_server_fails() -> None:
188175
class MockConnection(BaseMockConnection):
189176
@classmethod
190-
async def connect(
191-
cls,
192-
host: str,
193-
port: int,
194-
timeout: int,
195-
) -> Self | None:
177+
async def connect(cls, host: str, port: int, timeout: int) -> Self | None:
196178
return None
197179

198180
client = EnrichedClient(
@@ -245,7 +227,7 @@ class MockConnection(connection_class): # type: ignore[valid-type, misc]
245227

246228

247229
async def test_client_lifespan_connection_not_confirmed(monkeypatch: pytest.MonkeyPatch) -> None:
248-
async def timeout(future: Awaitable[Any], timeout: float) -> Any:
230+
async def timeout(future: Awaitable[Any], timeout: float) -> object:
249231
assert timeout == client.connection_confirmation_timeout
250232
return await original_wait_for(future, 0)
251233

@@ -254,7 +236,7 @@ async def timeout(future: Awaitable[Any], timeout: float) -> Any:
254236

255237
client = EnrichedClient(connection_class=BaseMockConnection)
256238
with pytest.raises(ConnectionConfirmationTimeoutError) as exc_info:
257-
await client.__aenter__()
239+
await client.__aenter__() # noqa: PLC2801
258240

259241
assert exc_info.value == ConnectionConfirmationTimeoutError(client.connection_confirmation_timeout)
260242

@@ -267,7 +249,7 @@ async def test_client_lifespan_unsupported_protocol_version() -> None:
267249

268250
client = EnrichedClient(connection_class=connection_class)
269251
with pytest.raises(UnsupportedProtocolVersionError) as exc_info:
270-
await client.__aenter__()
252+
await client.__aenter__() # noqa: PLC2801
271253

272254
assert exc_info.value == UnsupportedProtocolVersionError(
273255
given_version=given_version, supported_version=client.PROTOCOL_VERSION
@@ -399,7 +381,8 @@ async def test_ack_nack_connection_lost_error() -> None:
399381
connection_class, _ = create_spying_connection(get_read_frames_with_lifespan([[message_frame]]))
400382

401383
class MockConnection(connection_class): # type: ignore[valid-type, misc]
402-
async def write_frame(self, frame: AnyClientFrame) -> None:
384+
@staticmethod
385+
async def write_frame(frame: AnyClientFrame) -> None:
403386
if isinstance(frame, AckFrame | NackFrame):
404387
raise ConnectionLostError
405388

tests/test_connection.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,15 @@ async def make_connection() -> Connection | None:
2525
return await Connection.connect(host="localhost", port=12345, timeout=2)
2626

2727

28-
async def make_mocked_connection(
29-
monkeypatch: pytest.MonkeyPatch,
30-
reader: Any,
31-
writer: Any,
32-
) -> Connection:
28+
async def make_mocked_connection(monkeypatch: pytest.MonkeyPatch, reader: object, writer: object) -> Connection:
3329
monkeypatch.setattr("asyncio.open_connection", mock.AsyncMock(return_value=(reader, writer)))
3430
connection = await make_connection()
3531
assert connection
3632
return connection
3733

3834

3935
def mock_wait_for(monkeypatch: pytest.MonkeyPatch) -> None:
40-
async def mock_impl(future: Awaitable[Any], timeout: int) -> Any: # noqa: ARG001
36+
async def mock_impl(future: Awaitable[Any], timeout: int) -> object:
4137
return await original_wait_for(future, timeout=0)
4238

4339
original_wait_for = asyncio.wait_for

0 commit comments

Comments
 (0)