Skip to content

Commit

Permalink
rename a shadowed test and re-enable F811 to catch future cases (#8139)…
Browse files Browse the repository at this point in the history
… (#8148)

(cherry picked from commit 3c0f1eb)
  • Loading branch information
alexmac authored Feb 8, 2024
1 parent b3e5376 commit 1dc8a07
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGES/8139.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Two definitions for "test_invalid_route_name" existed, only one was being run. Refactored them into a single parameterized test. Enabled lint rule to prevent regression. -- by :user:`alexmac`.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ zip_ok = false
[flake8]
extend-select = B950
# TODO: don't disable D*, fix up issues instead
ignore = N801,N802,N803,E203,E226,E305,W504,E252,E301,E302,E501,E704,W503,W504,F811,D1,D4
ignore = N801,N802,N803,E203,E226,E305,W504,E252,E301,E302,E501,E704,W503,W504,D1,D4
max-line-length = 88
per-file-ignores =
# I900: Shouldn't appear in requirements for examples.
Expand Down
26 changes: 0 additions & 26 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,7 @@ async def unknown_addrinfo(*args: Any, **kwargs: Any) -> List[Any]:


async def test_close_for_threaded_resolver(loop) -> None:
resolver = ThreadedResolver(loop=loop)
await resolver.close()


async def test_threaded_negative_lookup_with_unknown_result() -> None:
loop = Mock()

# If compile CPython with `--disable-ipv6` option,
# we will get an (int, bytes) tuple, instead of a Exception.
async def unknown_addrinfo(*args: Any, **kwargs: Any) -> List[Any]:
return [
(
socket.AF_INET6,
socket.SOCK_STREAM,
6,
"",
(10, b"\x01\xbb\x00\x00\x00\x00*\x04NB\x00\x1a\x00\x00"),
)
]

loop.getaddrinfo = unknown_addrinfo
resolver = ThreadedResolver()
resolver._loop = loop
with patch("socket.has_ipv6", False):
res = await resolver.resolve("www.python.org")
assert len(res) == 0

await resolver.close()


Expand Down
16 changes: 9 additions & 7 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,14 +1130,16 @@ def test_subapp_iter(app) -> None:
assert list(resource) == [r1, r2]


def test_invalid_route_name(router) -> None:
with pytest.raises(ValueError):
router.add_get("/", make_handler(), name="invalid name")


def test_invalid_route_name(router) -> None:
@pytest.mark.parametrize(
"route_name",
(
"invalid name",
"class",
),
)
def test_invalid_route_name(router, route_name: str) -> None:
with pytest.raises(ValueError):
router.add_get("/", make_handler(), name="class") # identifier
router.add_get("/", make_handler(), name=route_name)


def test_frozen_router(router) -> None:
Expand Down

0 comments on commit 1dc8a07

Please sign in to comment.