Skip to content

Commit

Permalink
Merge pull request #278 from csernazs/ruff-new
Browse files Browse the repository at this point in the history
use ruff for linting
  • Loading branch information
csernazs committed Feb 17, 2024
2 parents 1c885e1 + bbf66f9 commit f6a0d95
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 126 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
Expand All @@ -23,12 +29,6 @@ repos:
name: isort (python)
args: ['--force-single-line-imports', '--profile', 'black']

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args: [ '--max-line-length', '120', '--max-doc-length', '120' ]

- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Enabled": false,
"python.linting.pylintEnabled": false,
"python.linting.flake8Path": "${workspaceFolder}/.venv/bin/flake8",
"python.testing.pytestArgs": [
"tests"
],
Expand Down
28 changes: 27 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ coverage = ">=6.4.4,<8.0.0"
types-toml = "^0.10.8"
toml = "^0.10.2"
black = "^23.1.0"
ruff = "^0.2.1"


[tool.poetry.group.doc]
Expand Down Expand Up @@ -88,3 +89,55 @@ markers = [
[tool.mypy]
files = ["pytest_httpserver", "scripts", "tests", "doc"]
implicit_reexport = false


[tool.black]
line-length = 120
safe = true

[tool.ruff]
lint.select = ["ALL"]
lint.ignore = [
"I",
"D",

"ANN",
"ARG005",
"B011",
"B904",
"C408",
"C901",
"COM812",
"EM101",
"EM103",
"FBT002",
"FIX002",
"INP001",
"PGH003",
"PLR0912",
"PLR0913",
"PLR2004",
"PLW2901",
"PT004",
"PT012",
"PT013",
"PTH118",
"PTH120",
"RET504",
"RET505",
"RET506",
"RUF005",
"S101",
"S113",
"S603",
"S607",
"SIM108",
"T201",
"TD002",
"TD003",
"TRY003",
"UP032",
]
line-length = 120
target-version = "py38"
exclude = ["doc", "example*.py", "tests/examples/*.py"]
34 changes: 18 additions & 16 deletions pytest_httpserver/blocking_httpserver.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from __future__ import annotations

from queue import Empty
from queue import Queue
from ssl import SSLContext
from typing import TYPE_CHECKING
from typing import Any
from typing import Dict
from typing import Mapping
from typing import Optional
from typing import Pattern
from typing import Union

from werkzeug.wrappers import Request
from werkzeug.wrappers import Response

from pytest_httpserver.httpserver import METHOD_ALL
from pytest_httpserver.httpserver import UNDEFINED
Expand All @@ -19,6 +15,12 @@
from pytest_httpserver.httpserver import RequestHandlerBase
from pytest_httpserver.httpserver import URIPattern

if TYPE_CHECKING:
from ssl import SSLContext

from werkzeug.wrappers import Request
from werkzeug.wrappers import Response


class BlockingRequestHandler(RequestHandlerBase):
"""
Expand Down Expand Up @@ -59,23 +61,23 @@ def __init__(
self,
host=DEFAULT_LISTEN_HOST,
port=DEFAULT_LISTEN_PORT,
ssl_context: Optional[SSLContext] = None,
ssl_context: SSLContext | None = None,
timeout: int = 30,
):
super().__init__(host, port, ssl_context)
self.timeout = timeout
self.request_queue: Queue[Request] = Queue()
self.request_handlers: Dict[Request, Queue[BlockingRequestHandler]] = {}
self.request_handlers: dict[Request, Queue[BlockingRequestHandler]] = {}

def assert_request(
self,
uri: Union[str, URIPattern, Pattern[str]],
uri: str | URIPattern | Pattern[str],
method: str = METHOD_ALL,
data: Union[str, bytes, None] = None,
data: str | bytes | None = None,
data_encoding: str = "utf-8",
headers: Optional[Mapping[str, str]] = None,
query_string: Union[None, QueryMatcher, str, bytes, Mapping] = None,
header_value_matcher: Optional[HeaderValueMatcher] = None,
headers: Mapping[str, str] | None = None,
query_string: None | QueryMatcher | str | bytes | Mapping = None,
header_value_matcher: HeaderValueMatcher | None = None,
json: Any = UNDEFINED,
timeout: int = 30,
) -> BlockingRequestHandler:
Expand Down Expand Up @@ -127,7 +129,7 @@ def assert_request(
try:
request = self.request_queue.get(timeout=timeout)
except Empty:
raise AssertionError(f"Waiting for request {matcher} timed out")
raise AssertionError(f"Waiting for request {matcher} timed out") # noqa: EM102

diff = matcher.difference(request)

Expand All @@ -137,7 +139,7 @@ def assert_request(

if diff:
request_handler.respond_with_response(self.respond_nohandler(request))
raise AssertionError(f"Request {matcher} does not match: {diff}")
raise AssertionError(f"Request {matcher} does not match: {diff}") # noqa: EM102

return request_handler

Expand Down

0 comments on commit f6a0d95

Please sign in to comment.