Skip to content

Commit

Permalink
setup formatter/linter in pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
becktob committed May 23, 2024
1 parent 3d65aa6 commit efecf60
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
source venv/bin/activate
pre-commit install

11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.2.1'
hooks:
- id: ruff
args: ['--fix']

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: 'v2.0.4'
hooks:
- id: autopep8
2 changes: 1 addition & 1 deletion http_request_recorder/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .http_request_recorder import HttpRequestRecorder # noqa: F401
from .http_request_recorder import HttpRequestRecorder # noqa: F401
11 changes: 7 additions & 4 deletions http_request_recorder/http_request_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from asyncio import Event
from itertools import tee
from logging import getLogger
from typing import Iterable, Union
from typing import Iterable
from collections.abc import Callable

from aiohttp import web
Expand Down Expand Up @@ -52,7 +52,8 @@ def __init__(self, matcher: Callable[[RecordedRequest], bool], responses: Respon
if hasattr(responses, "__len__"):
self.expected_count = sum(1 for _ in responses)
else:
raise TypeError("responses must be str | bytes | web.Response | Iterable[str] | Iterable[bytes] | Iterable[web.Response]")
raise TypeError(
"responses must be str | bytes | web.Response | Iterable[str] | Iterable[bytes] | Iterable[web.Response]")

self._recorded = []
self._next_for_response, self._next_to_return = tee(self.responses)
Expand Down Expand Up @@ -141,7 +142,8 @@ async def handle_request(self, request: BaseRequest):

recorded_request = await RecordedRequest.from_base_request(request)

matches = [exp for exp in self._expectations if exp.can_respond(recorded_request)]
matches = [exp for exp in self._expectations if exp.can_respond(
recorded_request)]
if len(matches) == 0:
self._logger.warning(f"{self} got unexpected {await self._request_string_for_log(request)}")
self._unexpected_requests.append(recorded_request)
Expand Down Expand Up @@ -188,7 +190,8 @@ def unexpected_requests(self) -> list[RecordedRequest]:
async def _request_string_for_log(request):
request_body = await request.read()

xml_rpc_method = re.search(b"<methodName>.*?</methodName>", request_body)
xml_rpc_method = re.search(
b"<methodName>.*?</methodName>", request_body)
if xml_rpc_method is not None:
return f"{request.method} - XmlRpc - {xml_rpc_method.group(0).decode('UTF-8')}"

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
aiohttp~=3.8.4
types-setuptools
types-setuptools
pre-commit
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
'aiohttp~=3.8.4',
],
zip_safe=False
)
)

0 comments on commit efecf60

Please sign in to comment.