Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ruff for linting #278

Merged
merged 23 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c62e20a
ruff: initialize in pre-commit-config, .vscode, pyproject.toml
csernazs Feb 17, 2024
3186a32
ruff: add to pyproject + update poetry.lock
csernazs Feb 17, 2024
a8014c5
ruff: add future import annotations, exclude files
csernazs Feb 17, 2024
9266102
ruff: add exclude to pyproject.toml
csernazs Feb 17, 2024
f959d06
ruff: add noqa FBT001
csernazs Feb 17, 2024
ee928ec
ruff: use TYPE_CHECKING for ssl and werkzeug
csernazs Feb 17, 2024
9367682
ruff: type annotations fixes
csernazs Feb 17, 2024
183e60a
ruff: exclude rules
csernazs Feb 17, 2024
0a027d7
ruff: remove pass statements
csernazs Feb 17, 2024
d9e3ecb
ruff: add noqa for exceptions f-string
csernazs Feb 17, 2024
9963713
ruff: rename callable to func
csernazs Feb 17, 2024
37e868e
ruff: add noqa for unused arguments
csernazs Feb 17, 2024
f2feac5
ruff: use kwarg for boolean calling
csernazs Feb 17, 2024
d9985ce
ruff: use in/not in instead of complex logical expression
csernazs Feb 17, 2024
2489956
ruff: fix string formatting
csernazs Feb 17, 2024
3edeaa7
ruff: fix pytest.fixture decorator
csernazs Feb 17, 2024
2c7e522
ruff: fix assert 1 == 2
csernazs Feb 17, 2024
650dc6b
ruff: add noqa for assert False
csernazs Feb 17, 2024
8baeff6
ruff: add noqa for pytest.raises
csernazs Feb 17, 2024
ddc7fb4
ruff: fix pytest.mark.parametrize
csernazs Feb 17, 2024
67c0548
ruff: add noqa for tarball extractall
csernazs Feb 17, 2024
b91f876
ruff: upgrade config in pyproject.toml
csernazs Feb 17, 2024
bbf66f9
releasenotes: add release note for #278
csernazs Feb 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Loading