Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ repos:
- flake8-no-implicit-concat==0.3.4
- flake8-requirements==1.7.8
- repo: https://github.com/PyCQA/isort
rev: '7.0.0'
rev: '8.0.1'
hooks:
- id: isort
- repo: https://github.com/psf/black-pre-commit-mirror
rev: '25.9.0'
rev: '26.3.1'
hooks:
- id: black
language_version: python3 # Should be a command that runs python
Expand Down Expand Up @@ -99,7 +99,7 @@ repos:
- id: detect-private-key
exclude: ^examples/
- repo: https://github.com/asottile/pyupgrade
rev: 'v3.21.0'
rev: 'v3.21.2'
hooks:
- id: pyupgrade
args: ['--py37-plus']
Expand All @@ -121,7 +121,7 @@ repos:
exclude: >-
^CHANGES\.rst$
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
rev: v2.4.2
hooks:
- id: codespell
additional_dependencies:
Expand Down
1 change: 1 addition & 0 deletions examples/background_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Example of aiohttp.web.Application.on_startup signal handler"""

import asyncio
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager, suppress
Expand Down
6 changes: 2 additions & 4 deletions examples/web_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@


async def intro(request: web.Request) -> web.StreamResponse:
txt = textwrap.dedent(
"""\
txt = textwrap.dedent("""\
Type {url}/hello/John {url}/simple or {url}/change_body
in browser url bar
"""
).format(url="127.0.0.1:8080")
""").format(url="127.0.0.1:8080")
binary = txt.encode("utf8")
resp = web.StreamResponse()
resp.content_length = len(binary)
Expand Down
6 changes: 2 additions & 4 deletions examples/web_srv_route_deco.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

@routes.get("/")
async def intro(request: web.Request) -> web.StreamResponse:
txt = textwrap.dedent(
"""\
txt = textwrap.dedent("""\
Type {url}/hello/John {url}/simple or {url}/change_body
in browser url bar
"""
).format(url="127.0.0.1:8080")
""").format(url="127.0.0.1:8080")
binary = txt.encode("utf8")
resp = web.StreamResponse()
resp.content_length = len(binary)
Expand Down
6 changes: 2 additions & 4 deletions examples/web_srv_route_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@


async def intro(request: web.Request) -> web.StreamResponse:
txt = textwrap.dedent(
"""\
txt = textwrap.dedent("""\
Type {url}/hello/John {url}/simple or {url}/change_body
in browser url bar
"""
).format(url="127.0.0.1:8080")
""").format(url="127.0.0.1:8080")
binary = txt.encode("utf8")
resp = web.StreamResponse()
resp.content_length = len(binary)
Expand Down
12 changes: 4 additions & 8 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ def test_invalid_character(
max_field_size=8190,
)
text = b"POST / HTTP/1.1\r\nHost: localhost:8080\r\nSet-Cookie: abc\x01def\r\n\r\n"
error_detail = re.escape(
r""":
error_detail = re.escape(r""":

b'Set-Cookie: abc\x01def'
^"""
)
^""")
with pytest.raises(http_exceptions.BadHttpMessage, match=error_detail):
parser.feed_data(text)

Expand All @@ -189,12 +187,10 @@ def test_invalid_linebreak(
max_field_size=8190,
)
text = b"GET /world HTTP/1.1\r\nHost: 127.0.0.1\n\r\n"
error_detail = re.escape(
r""":
error_detail = re.escape(r""":

b'Host: 127.0.0.1\n'
^"""
)
^""")
with pytest.raises(http_exceptions.BadHttpMessage, match=error_detail):
parser.feed_data(text)

Expand Down
12 changes: 4 additions & 8 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@

def test___all__(pytester: pytest.Pytester) -> None:
"""See https://github.com/aio-libs/aiohttp/issues/6197"""
pytester.makepyfile(
test_a="""
pytester.makepyfile(test_a="""
from aiohttp import *
assert 'GunicornWebWorker' in globals()
"""
)
""")
result = pytester.runpytest("-vv")
result.assert_outcomes(passed=0, errors=0)


def test_web___all__(pytester: pytest.Pytester) -> None:
pytester.makepyfile(
test_b="""
pytester.makepyfile(test_b="""
from aiohttp.web import *
"""
)
""")
result = pytester.runpytest("-vv")
result.assert_outcomes(passed=0, errors=0)

Expand Down
43 changes: 14 additions & 29 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@


def test_aiohttp_plugin(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""\
testdir.makepyfile("""\
import pytest
from unittest import mock

Expand Down Expand Up @@ -117,16 +116,14 @@ async def test_custom_port_test_server(aiohttp_server, aiohttp_unused_port):
port = aiohttp_unused_port()
server = await aiohttp_server(app, port=port)
assert server.port == port
"""
)
""")
testdir.makeconftest(CONFTEST)
result = testdir.runpytest("-p", "no:sugar", "--aiohttp-loop=pyloop")
result.assert_outcomes(passed=8)


def test_warning_checks(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""\
testdir.makepyfile("""\

async def foobar():
return 123
Expand All @@ -137,8 +134,7 @@ async def test_good() -> None:

async def test_bad() -> None:
foobar()
"""
)
""")
testdir.makeconftest(CONFTEST)
result = testdir.runpytest(
"-p", "no:sugar", "-s", "-W", "default", "--aiohttp-loop=pyloop"
Expand All @@ -155,8 +151,7 @@ async def test_bad() -> None:
def test_aiohttp_plugin_async_fixture(
testdir: pytest.Testdir, capsys: pytest.CaptureFixture[str]
) -> None:
testdir.makepyfile(
"""\
testdir.makepyfile("""\
import pytest

from aiohttp import web
Expand Down Expand Up @@ -205,8 +200,7 @@ def test_foo_without_loop(foo) -> None:

def test_bar(loop, bar) -> None:
assert bar is test_bar
"""
)
""")
testdir.makeconftest(CONFTEST)
result = testdir.runpytest("-p", "no:sugar", "--aiohttp-loop=pyloop")
result.assert_outcomes(passed=3, errors=1)
Expand All @@ -217,8 +211,7 @@ def test_bar(loop, bar) -> None:


def test_aiohttp_plugin_async_gen_fixture(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""\
testdir.makepyfile("""\
import pytest
from unittest import mock

Expand Down Expand Up @@ -251,8 +244,7 @@ async def test_hello(cli) -> None:

def test_finalized() -> None:
assert canary.called is True
"""
)
""")
testdir.makeconftest(CONFTEST)
result = testdir.runpytest("-p", "no:sugar", "--aiohttp-loop=pyloop")
result.assert_outcomes(passed=2)
Expand All @@ -268,8 +260,7 @@ def test_warnings_propagated(recwarn: pytest.WarningsRecorder) -> None:


def test_aiohttp_client_cls_fixture_custom_client_used(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""
testdir.makepyfile("""
import pytest
from aiohttp.web import Application
from aiohttp.test_utils import TestClient
Expand All @@ -288,26 +279,21 @@ async def test_hello(aiohttp_client) -> None:
client = await aiohttp_client(Application())
assert isinstance(client, CustomClient)

"""
)
""")
testdir.makeconftest(CONFTEST)
result = testdir.runpytest()
result.assert_outcomes(passed=1)


def test_aiohttp_client_cls_fixture_factory(testdir: pytest.Testdir) -> None:
testdir.makeconftest(
CONFTEST
+ """
testdir.makeconftest(CONFTEST + """

def pytest_configure(config):
config.addinivalue_line("markers", "rest: RESTful API tests")
config.addinivalue_line("markers", "graphql: GraphQL API tests")

"""
)
testdir.makepyfile(
"""
""")
testdir.makepyfile("""
import pytest
from aiohttp.web import Application
from aiohttp.test_utils import TestClient
Expand Down Expand Up @@ -341,7 +327,6 @@ async def test_graphql(aiohttp_client) -> None:
client = await aiohttp_client(Application())
assert isinstance(client, GraphQLClient)

"""
)
""")
result = testdir.runpytest()
result.assert_outcomes(passed=2)
6 changes: 2 additions & 4 deletions tests/test_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,14 @@ async def test_server_make_url_yarl_compatibility(
def test_testcase_no_app(
testdir: pytest.Testdir, loop: asyncio.AbstractEventLoop
) -> None:
testdir.makepyfile(
"""
testdir.makepyfile("""
from aiohttp.test_utils import AioHTTPTestCase


class InvalidTestCase(AioHTTPTestCase):
def test_noop(self) -> None:
pass
"""
)
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*TypeError*"])

Expand Down
Loading