Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename a shadowed test and re-enable F811 to catch future cases (#8139) #8148

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
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)
Copy link
Member

@webknjaz webknjaz Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dreamsorcerer did you miss that this removes an unrelated test in a test module that the original commit didn't even touch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexmac it seems like the conflict resolution hasn't been completed correctly and this removed a legit test. Why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexmac was it exactly identical to the other test? It'd be useful to have in a PR description. And perhaps, do such things in separate PRs. Backports must never include changes that aren't directly related to resolving conflicts with the original patch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see the same test still exists, though the diff makes it a bit awkward to tell. The flake8 rule found this duplicate test that only existed on the 3.x branches. Could have been removed in another PR, but I don't think it makes any real difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I managed to find that. It'd be much more obvious (== less mental overhead) if this was explained explicitly.

As for a separate PR — this is the way. Patchback would also work to port from 3.10 to 3.9. The thing is that the git cherry-pick -x is supposed to contain a copy of another change, it even generates a reference (cherry picked from commit xxxxxx). By making arbitrary changes, that makes it hard to track, breaking transparency of the updates to Git. Atomic commits/PRs is a convention that is designed around certain expectations/promises. Breaking them hurts future git paleontology, making the introspection harder. This effect is often not visible/obvious to the commit authors, making it a hard sell, but is quite important for keeping sane history.

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
Loading