Skip to content

Commit

Permalink
Add flake8-requirements (#5934) (#7293)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot]
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit a29e9de)

<!-- Thank you for your contribution! -->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

## Are there changes in behavior for the user?

<!-- Outline any notable behaviour for the end users. -->

## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

## Checklist

- [ ] I think the code is well written
- [ ] Unit tests for the changes exist
- [ ] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
  * The format is &lt;Name&gt; &lt;Surname&gt;.
  * Please keep alphabetical order, the file is sorted by names.
- [ ] Add a new news fragment into the `CHANGES` folder
  * name it `<issue_id>.<type>` for example (588.bugfix)
* if you don't have an `issue_id` change it to the pr id after creating
the pr
  * ensure type is one of the following:
    * `.feature`: Signifying a new feature.
    * `.bugfix`: Signifying a bug fix.
    * `.doc`: Signifying a documentation improvement.
    * `.removal`: Signifying a deprecation or removal of public API.
* `.misc`: A ticket has been closed, but it is not of interest to users.
* Make sure to use full sentences with correct case and punctuation, for
example: "Fix issue with non-ascii contents in doctest text files."
  • Loading branch information
Dreamsorcerer authored May 16, 2023
1 parent 0f8f565 commit 9258d34
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ repos:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.6.0
- flake8-requirements==1.7.8
exclude: "^docs/"
- repo: https://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.1
Expand Down
1 change: 1 addition & 0 deletions CHANGES/5934.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add flake8-requirements to linting.
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ zip_ok = false
# TODO: don't disable D*, fix up issues instead
ignore = N801,N802,N803,E203,E226,E305,W504,E252,E301,E302,E704,W503,W504,F811,D1,D4
max-line-length = 88
per-file-ignores =
# I900: Shouldn't appear in requirements for examples.
examples/*:I900

# flake8-requirements
known-modules = proxy.py:[proxy]
requirements-file = requirements/test.txt
requirements-max-depth = 4

[isort]
line_length=88
Expand Down
Empty file added tests/__init__.py
Empty file.
9 changes: 1 addition & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,8 @@

pytest_plugins = ["aiohttp.pytest_plugin", "pytester"]


IS_HPUX = sys.platform.startswith("hp-ux")
"""Specifies whether the current runtime is HP-UX."""
IS_LINUX = sys.platform.startswith("linux")
"""Specifies whether the current runtime is HP-UX."""
IS_UNIX = hasattr(socket, "AF_UNIX")
"""Specifies whether the current runtime is *NIX."""

needs_unix = pytest.mark.skipif(not IS_UNIX, reason="requires UNIX sockets")


@pytest.fixture
Expand Down Expand Up @@ -99,7 +92,7 @@ def unix_sockname(tmp_path, tmp_path_factory):
Ref: https://github.com/aio-libs/aiohttp/issues/3572
"""
if not IS_UNIX:
if not hasattr(socket, "AF_UNIX"):
pytest.skip("requires UNIX sockets")

max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100
Expand Down
7 changes: 4 additions & 3 deletions tests/test_circular_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
""" # noqa: E501
import os
import pkgutil
import socket
import subprocess
import sys
from itertools import chain
Expand All @@ -22,8 +23,6 @@
if TYPE_CHECKING:
from _pytest.mark.structures import ParameterSet

from conftest import IS_UNIX # type: ignore[attr-defined]

import aiohttp


Expand All @@ -33,7 +32,9 @@ def _mark_aiohttp_worker_for_skipping(
return [
pytest.param(
importable,
marks=pytest.mark.skipif(not IS_UNIX, reason="It's a UNIX-only module"),
marks=pytest.mark.skipif(
not hasattr(socket, "AF_UNIX"), reason="It's a UNIX-only module"
),
)
if importable == "aiohttp.worker"
else importable
Expand Down
7 changes: 3 additions & 4 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from unittest import mock

import pytest
from conftest import needs_unix
from yarl import URL

import aiohttp
Expand Down Expand Up @@ -1914,16 +1913,16 @@ async def handler(request):
assert r.status == 200


@needs_unix
@pytest.mark.skipif(not hasattr(socket, "AF_UNIX"), reason="requires UNIX sockets")
async def test_unix_connector_not_found(loop) -> None:
connector = aiohttp.UnixConnector("/" + uuid.uuid4().hex, loop=loop)
connector = aiohttp.UnixConnector("/" + uuid.uuid4().hex)

req = ClientRequest("GET", URL("http://www.python.org"), loop=loop)
with pytest.raises(aiohttp.ClientConnectorError):
await connector.connect(req, None, ClientTimeout())


@needs_unix
@pytest.mark.skipif(not hasattr(socket, "AF_UNIX"), reason="requires UNIX sockets")
async def test_unix_connector_permission(loop) -> None:
loop.create_unix_connection = make_mocked_coro(raise_exception=PermissionError())
connector = aiohttp.UnixConnector("/" + uuid.uuid4().hex, loop=loop)
Expand Down
9 changes: 4 additions & 5 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
from uuid import uuid4

import pytest
from conftest import IS_UNIX, needs_unix

from aiohttp import ClientConnectorError, ClientSession, web
from aiohttp.test_utils import make_mocked_coro
from aiohttp.web_runner import BaseRunner

# Test for features of OS' socket support
if IS_UNIX:
if hasattr(socket, "AF_UNIX"):
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as _abstract_path_sock:
try:
_abstract_path_sock.bind(b"\x00" + uuid4().hex.encode("ascii"))
Expand All @@ -37,7 +36,7 @@
skip_if_no_abstract_paths = pytest.mark.skipif(
_abstract_path_failed, reason="Linux-style abstract paths are not supported."
)
del IS_UNIX, _abstract_path_failed
del _abstract_path_failed

HAS_IPV6 = socket.has_ipv6
if HAS_IPV6:
Expand Down Expand Up @@ -531,7 +530,7 @@ def test_run_app_https_unix_socket(patched_loop, unix_sockname) -> None:
assert f"https://unix:{unix_sockname}:" in printer.call_args[0][0]


@needs_unix
@pytest.mark.skipif(not hasattr(socket, "AF_UNIX"), reason="requires UNIX sockets")
@skip_if_no_abstract_paths
def test_run_app_abstract_linux_socket(patched_loop) -> None:
sock_path = b"\x00" + uuid4().hex.encode("ascii")
Expand Down Expand Up @@ -583,7 +582,7 @@ def test_run_app_preexisting_inet6_socket(patched_loop) -> None:
assert f"http://[::]:{port}" in printer.call_args[0][0]


@needs_unix
@pytest.mark.skipif(not hasattr(socket, "AF_UNIX"), reason="requires UNIX sockets")
def test_run_app_preexisting_unix_socket(patched_loop, mocker) -> None:
app = web.Application()

Expand Down
4 changes: 2 additions & 2 deletions tests/test_web_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ async def middleware(request):
continue
assert re.match(
"^old-style middleware "
'"<function test_old_style_middleware.<locals>.'
'"<function .*test_old_style_middleware.<locals>.'
'middleware_factory at 0x[0-9a-fA-F]+>" '
"deprecated, see #2252$",
msg,
Expand Down Expand Up @@ -460,7 +460,7 @@ async def middleware(request):
continue
assert re.match(
"^old-style middleware "
'"<test_web_middleware.test_old_style_middleware_class.'
'"<.*test_web_middleware.test_old_style_middleware_class.'
"<locals>.Middleware object "
'at 0x[0-9a-fA-F]+>" deprecated, see #2252$',
msg,
Expand Down

0 comments on commit 9258d34

Please sign in to comment.