Skip to content

Commit f6a0d95

Browse files
authored
Merge pull request #278 from csernazs/ruff-new
use ruff for linting
2 parents 1c885e1 + bbf66f9 commit f6a0d95

15 files changed

Lines changed: 210 additions & 126 deletions

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.2.1
4+
hooks:
5+
- id: ruff
6+
args: [--fix, --exit-non-zero-on-fix]
7+
28
- repo: https://github.com/psf/black
39
rev: 23.1.0
410
hooks:
@@ -23,12 +29,6 @@ repos:
2329
name: isort (python)
2430
args: ['--force-single-line-imports', '--profile', 'black']
2531

26-
- repo: https://github.com/pycqa/flake8
27-
rev: 6.0.0
28-
hooks:
29-
- id: flake8
30-
args: [ '--max-line-length', '120', '--max-doc-length', '120' ]
31-
3232
- repo: https://github.com/asottile/blacken-docs
3333
rev: 1.13.0
3434
hooks:

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"python.linting.enabled": true,
3-
"python.linting.flake8Enabled": true,
3+
"python.linting.flake8Enabled": false,
44
"python.linting.pylintEnabled": false,
5-
"python.linting.flake8Path": "${workspaceFolder}/.venv/bin/flake8",
65
"python.testing.pytestArgs": [
76
"tests"
87
],

poetry.lock

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ coverage = ">=6.4.4,<8.0.0"
5151
types-toml = "^0.10.8"
5252
toml = "^0.10.2"
5353
black = "^23.1.0"
54+
ruff = "^0.2.1"
5455

5556

5657
[tool.poetry.group.doc]
@@ -88,3 +89,55 @@ markers = [
8889
[tool.mypy]
8990
files = ["pytest_httpserver", "scripts", "tests", "doc"]
9091
implicit_reexport = false
92+
93+
94+
[tool.black]
95+
line-length = 120
96+
safe = true
97+
98+
[tool.ruff]
99+
lint.select = ["ALL"]
100+
lint.ignore = [
101+
"I",
102+
"D",
103+
104+
"ANN",
105+
"ARG005",
106+
"B011",
107+
"B904",
108+
"C408",
109+
"C901",
110+
"COM812",
111+
"EM101",
112+
"EM103",
113+
"FBT002",
114+
"FIX002",
115+
"INP001",
116+
"PGH003",
117+
"PLR0912",
118+
"PLR0913",
119+
"PLR2004",
120+
"PLW2901",
121+
"PT004",
122+
"PT012",
123+
"PT013",
124+
"PTH118",
125+
"PTH120",
126+
"RET504",
127+
"RET505",
128+
"RET506",
129+
"RUF005",
130+
"S101",
131+
"S113",
132+
"S603",
133+
"S607",
134+
"SIM108",
135+
"T201",
136+
"TD002",
137+
"TD003",
138+
"TRY003",
139+
"UP032",
140+
]
141+
line-length = 120
142+
target-version = "py38"
143+
exclude = ["doc", "example*.py", "tests/examples/*.py"]

pytest_httpserver/blocking_httpserver.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
from __future__ import annotations
2+
13
from queue import Empty
24
from queue import Queue
3-
from ssl import SSLContext
5+
from typing import TYPE_CHECKING
46
from typing import Any
5-
from typing import Dict
67
from typing import Mapping
7-
from typing import Optional
88
from typing import Pattern
9-
from typing import Union
10-
11-
from werkzeug.wrappers import Request
12-
from werkzeug.wrappers import Response
139

1410
from pytest_httpserver.httpserver import METHOD_ALL
1511
from pytest_httpserver.httpserver import UNDEFINED
@@ -19,6 +15,12 @@
1915
from pytest_httpserver.httpserver import RequestHandlerBase
2016
from pytest_httpserver.httpserver import URIPattern
2117

18+
if TYPE_CHECKING:
19+
from ssl import SSLContext
20+
21+
from werkzeug.wrappers import Request
22+
from werkzeug.wrappers import Response
23+
2224

2325
class BlockingRequestHandler(RequestHandlerBase):
2426
"""
@@ -59,23 +61,23 @@ def __init__(
5961
self,
6062
host=DEFAULT_LISTEN_HOST,
6163
port=DEFAULT_LISTEN_PORT,
62-
ssl_context: Optional[SSLContext] = None,
64+
ssl_context: SSLContext | None = None,
6365
timeout: int = 30,
6466
):
6567
super().__init__(host, port, ssl_context)
6668
self.timeout = timeout
6769
self.request_queue: Queue[Request] = Queue()
68-
self.request_handlers: Dict[Request, Queue[BlockingRequestHandler]] = {}
70+
self.request_handlers: dict[Request, Queue[BlockingRequestHandler]] = {}
6971

7072
def assert_request(
7173
self,
72-
uri: Union[str, URIPattern, Pattern[str]],
74+
uri: str | URIPattern | Pattern[str],
7375
method: str = METHOD_ALL,
74-
data: Union[str, bytes, None] = None,
76+
data: str | bytes | None = None,
7577
data_encoding: str = "utf-8",
76-
headers: Optional[Mapping[str, str]] = None,
77-
query_string: Union[None, QueryMatcher, str, bytes, Mapping] = None,
78-
header_value_matcher: Optional[HeaderValueMatcher] = None,
78+
headers: Mapping[str, str] | None = None,
79+
query_string: None | QueryMatcher | str | bytes | Mapping = None,
80+
header_value_matcher: HeaderValueMatcher | None = None,
7981
json: Any = UNDEFINED,
8082
timeout: int = 30,
8183
) -> BlockingRequestHandler:
@@ -127,7 +129,7 @@ def assert_request(
127129
try:
128130
request = self.request_queue.get(timeout=timeout)
129131
except Empty:
130-
raise AssertionError(f"Waiting for request {matcher} timed out")
132+
raise AssertionError(f"Waiting for request {matcher} timed out") # noqa: EM102
131133

132134
diff = matcher.difference(request)
133135

@@ -137,7 +139,7 @@ def assert_request(
137139

138140
if diff:
139141
request_handler.respond_with_response(self.respond_nohandler(request))
140-
raise AssertionError(f"Request {matcher} does not match: {diff}")
142+
raise AssertionError(f"Request {matcher} does not match: {diff}") # noqa: EM102
141143

142144
return request_handler
143145

0 commit comments

Comments
 (0)