Skip to content

Commit 1566544

Browse files
lesnik512claude
andcommitted
style(tests): extract status-code constants in test_middleware.py
Replace three `# noqa: PLR2004` suppressions with named constants. Matches the constant-extraction pattern already used in test_errors.py. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 635de95 commit 1566544

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎tests/test_middleware.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ def _make_request(url: str = "https://example.test/x") -> httpx2.Request:
1919
return httpx2.Request("GET", url)
2020

2121

22-
def _make_response(status: int = 200, *, request: httpx2.Request | None = None) -> httpx2.Response:
22+
_STATUS_OK = 200
23+
_STATUS_UPGRADED = 299
24+
_STATUS_SERVICE_UNAVAILABLE = 503
25+
26+
27+
def _make_response(status: int = _STATUS_OK, *, request: httpx2.Request | None = None) -> httpx2.Response:
2328
if request is None:
2429
request = _make_request()
2530
return httpx2.Response(status, request=request)
@@ -43,7 +48,7 @@ async def terminal(request: httpx2.Request) -> httpx2.Response:
4348
dispatch = compose((), terminal)
4449
request = _make_request()
4550
response = await dispatch(request)
46-
assert response.status_code == 200 # noqa: PLR2004
51+
assert response.status_code == _STATUS_OK
4752
assert seen == [request]
4853

4954

@@ -95,7 +100,7 @@ async def terminal(request: httpx2.Request) -> httpx2.Response:
95100

96101
dispatch = compose((upgrade_status,), terminal)
97102
response = await dispatch(_make_request())
98-
assert response.status_code == 299 # noqa: PLR2004
103+
assert response.status_code == _STATUS_UPGRADED
99104

100105

101106
async def test_on_error_decorator_can_translate_exception() -> None:
@@ -111,7 +116,7 @@ async def terminal(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
111116

112117
dispatch = compose((swallow,), terminal)
113118
response = await dispatch(_make_request())
114-
assert response.status_code == 503 # noqa: PLR2004
119+
assert response.status_code == _STATUS_SERVICE_UNAVAILABLE
115120

116121

117122
async def test_on_error_returns_none_reraises() -> None:

0 commit comments

Comments
 (0)