Skip to content

Commit

Permalink
Merge pull request #22 from taskiq-python/feature/deps-update
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius authored Sep 29, 2024
2 parents c7ef231 + 34d5554 commit b2e6742
Show file tree
Hide file tree
Showing 8 changed files with 889 additions and 965 deletions.
133 changes: 0 additions & 133 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:

- id: ruff
name: Run ruff lints
entry: poetry run ruff
entry: poetry run ruff check
language: system
pass_filenames: false
types: [python]
Expand Down
1 change: 1 addition & 0 deletions aiohttp_deps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Project was generated using taskiq."""

from taskiq_dependencies import Depends

from aiohttp_deps.initializer import init
Expand Down
1,635 changes: 830 additions & 805 deletions poetry.lock

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ python = "^3.8.1"
aiohttp = ">=3.9.0,<4"
taskiq-dependencies = ">=1.3.1,<2"
pydantic = "^2"
deepmerge = "^1.1.0"
deepmerge = "^2"

[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
pytest = "^8"
mypy = "^1"
pre-commit = "^2.20.0"
coverage = "^6.4.2"
pytest-cov = "^3.0.0"
mock = "^4.0.3"
anyio = "^3.6.1"
pytest-xdist = { version = "^2.5.0", extras = ["psutil"] }
types-mock = "^4.0.15"
black = "^23.1.0"
pytest-aiohttp = "^1.0.4"
ruff = "^0.1.7"
pre-commit = "^3"
coverage = "^7"
pytest-cov = "^5.0.0"
mock = "^5"
anyio = "^4"
pytest-xdist = { version = "^3", extras = ["psutil"] }
types-mock = "^5"
black = "^24"
ruff = "^0.6"

[tool.mypy]
strict = true
Expand All @@ -60,7 +59,7 @@ multi_line_output = 3
[tool.ruff]
# List of enabled rulsets.
# See https://docs.astral.sh/ruff/rules/ for more information.
select = [
lint.select = [
"E", # Error
"F", # Pyflakes
"W", # Pycodestyle
Expand All @@ -87,7 +86,7 @@ select = [
"PL", # PyLint checks
"RUF", # Specific to Ruff checks
]
ignore = [
lint.ignore = [
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
"D212", # Multi-line docstring summary should start at the first line
Expand All @@ -103,10 +102,10 @@ ignore = [

]
exclude = [".venv/"]
mccabe = { max-complexity = 10 }
lint.mccabe = { max-complexity = 10 }
line-length = 88

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"S101", # Use of assert detected
"S301", # Use of pickle detected
Expand All @@ -116,14 +115,14 @@ line-length = 88
"D101", # Missing docstring in public class
]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "pep257"
ignore-decorators = ["typing.overload"]

[tool.ruff.pylint]
[tool.ruff.lint.pylint]
allow-magic-value-types = ["int", "str", "float"]

[tool.ruff.flake8-bugbear]
[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = [
"taskiq_dependencies.Depends",
"aiohttp_deps.Depends",
Expand Down
34 changes: 32 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Awaitable, Callable, Union
import asyncio
from typing import AsyncGenerator, Awaitable, Callable, Optional, Union

import pytest
from aiohttp import web
from aiohttp.test_utils import BaseTestServer, TestClient
from aiohttp.test_utils import BaseTestServer, TestClient, TestServer

from aiohttp_deps import init

Expand All @@ -28,3 +29,32 @@ def my_app() -> web.Application:
app = web.Application()
app.on_startup.append(init)
return app


@pytest.fixture
async def aiohttp_client() -> (
AsyncGenerator[Callable[[web.Application], Awaitable[TestClient]], None]
):
"""
Create a test client.
This function creates a TestServer
and a test client for the application.
:param app: current application.
:yield: ready to use client.
"""
client: Optional[TestClient] = None

async def inner(app: web.Application) -> TestClient:
nonlocal client
loop = asyncio.get_running_loop()
server = TestServer(app)
client = TestClient(server, loop=loop)
await client.start_server()
return client

yield inner

if client is not None:
await client.close()
8 changes: 5 additions & 3 deletions tests/test_form.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from io import BytesIO

import pydantic
import pytest
from aiohttp import web
Expand Down Expand Up @@ -27,7 +29,7 @@ async def handler(my_form: InputSchema = Depends(Form())) -> web.Response:
client = await aiohttp_client(my_app)
resp = await client.post(
"/",
data={"id": "1", "file": b"bytes"},
data={"id": "1", "file": BytesIO(file_data)},
)
assert resp.status == 200
assert await resp.content.read() == file_data
Expand Down Expand Up @@ -61,7 +63,7 @@ async def handler(_: InputSchema = Depends(Form())) -> None:
my_app.router.add_post("/", handler)

client = await aiohttp_client(my_app)
resp = await client.post("/", data={"id": "meme", "file": b""})
resp = await client.post("/", data={"id": "meme", "file": BytesIO(b"")})
assert resp.status == 400


Expand All @@ -77,6 +79,6 @@ async def handler(form=Depends(Form())) -> web.Response: # noqa: ANN001

form_data = b"meme"
client = await aiohttp_client(my_app)
resp = await client.post("/", data={"id": "meme", "file": form_data})
resp = await client.post("/", data={"id": "meme", "file": BytesIO(form_data)})
assert resp.status == 200
assert await resp.content.read() == form_data
4 changes: 2 additions & 2 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ async def my_handler(my_var=Depends(Form())) -> None: # noqa: ANN001
resp_json = await resp.json()
handler_info = resp_json["paths"]["/a"]["get"]
assert (
{}
== handler_info["requestBody"]["content"]["application/x-www-form-urlencoded"]
handler_info["requestBody"]["content"]["application/x-www-form-urlencoded"]
== {}
)


Expand Down

0 comments on commit b2e6742

Please sign in to comment.