Skip to content

Commit

Permalink
Merge branch 'main' into ci-pedantry
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Dec 24, 2024
2 parents 90f2b75 + 3260974 commit c479af6
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/autodeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true
persist-credentials: true # credentials are needed to push commits
- name: Setup python
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.8.4
hooks:
- id: ruff
types: [file]
Expand Down
2 changes: 1 addition & 1 deletion src/trio/_core/_tests/test_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def after_run(self) -> NoReturn:
raise ValueError("oops")

async def main() -> None:
with pytest.raises(ValueError, match="^oops$"):
with pytest.raises(ValueError, match=r"^oops$"):
_core.add_instrument(EvilInstrument())

# Make sure the instrument is fully removed from the per-method lists
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_core/_tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ async def reset_check() -> None:
t2.reset(token2)
assert t2.get() == "dogfish"

with pytest.raises(ValueError, match="^token has already been used$"):
with pytest.raises(ValueError, match=r"^token has already been used$"):
t2.reset(token2)

token3 = t3.set("basculin")
assert t3.get() == "basculin"

with pytest.raises(ValueError, match="^token is not for us$"):
with pytest.raises(ValueError, match=r"^token is not for us$"):
t1.reset(token3)

run(reset_check)
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_core/_tests/test_mock_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ def test_mock_clock() -> None:
assert c.current_time() == 0
c.jump(1.2)
assert c.current_time() == 1.2
with pytest.raises(ValueError, match="^time can't go backwards$"):
with pytest.raises(ValueError, match=r"^time can't go backwards$"):
c.jump(-1)
assert c.current_time() == 1.2
assert c.deadline_to_sleep_time(1.1) == 0
assert c.deadline_to_sleep_time(1.2) == 0
assert c.deadline_to_sleep_time(1.3) > 999999

with pytest.raises(ValueError, match="^rate must be >= 0$"):
with pytest.raises(ValueError, match=r"^rate must be >= 0$"):
c.rate = -1
assert c.rate == 0

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_core/_tests/test_parking_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ async def test_parking_lot_breaker_register_exited_task() -> None:
# trying to register an exited task as lot breaker errors
with pytest.raises(
trio.BrokenResourceError,
match="^Attempted to add already exited task as lot breaker.$",
match=r"^Attempted to add already exited task as lot breaker.$",
):
add_parking_lot_breaker(child_task, lot)

Expand Down
30 changes: 15 additions & 15 deletions src/trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_initial_task_error() -> None:
async def main(x: object) -> NoReturn:
raise ValueError(x)

with pytest.raises(ValueError, match="^17$") as excinfo:
with pytest.raises(ValueError, match=r"^17$") as excinfo:
_core.run(main, 17)
assert excinfo.value.args == (17,)

Expand Down Expand Up @@ -246,7 +246,7 @@ async def child2() -> None:
t2 = _core.current_task()
_core.reschedule(not_none(t1), outcome.Value(0))
print("child2 sleep")
with pytest.raises(ValueError, match="^error message$"):
with pytest.raises(ValueError, match=r"^error message$"):
await sleep_forever()
print("child2 successful exit")

Expand Down Expand Up @@ -369,26 +369,26 @@ async def test_cancel_scope_repr(mock_clock: _core.MockClock) -> None:
async def test_cancel_scope_validation() -> None:
with pytest.raises(
ValueError,
match="^Cannot specify both a deadline and a relative deadline$",
match=r"^Cannot specify both a deadline and a relative deadline$",
):
_core.CancelScope(deadline=7, relative_deadline=3)

with pytest.raises(ValueError, match="^deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^deadline must not be NaN$"):
_core.CancelScope(deadline=nan)
with pytest.raises(ValueError, match="^relative deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^relative deadline must not be NaN$"):
_core.CancelScope(relative_deadline=nan)

with pytest.raises(ValueError, match="^timeout must be non-negative$"):
with pytest.raises(ValueError, match=r"^timeout must be non-negative$"):
_core.CancelScope(relative_deadline=-3)

scope = _core.CancelScope()

with pytest.raises(ValueError, match="^deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^deadline must not be NaN$"):
scope.deadline = nan
with pytest.raises(ValueError, match="^relative deadline must not be NaN$"):
with pytest.raises(ValueError, match=r"^relative deadline must not be NaN$"):
scope.relative_deadline = nan

with pytest.raises(ValueError, match="^relative deadline must be non-negative$"):
with pytest.raises(ValueError, match=r"^relative deadline must be non-negative$"):
scope.relative_deadline = -3
scope.relative_deadline = 5
assert scope.relative_deadline == 5
Expand Down Expand Up @@ -1063,7 +1063,7 @@ async def child1() -> None:
async with seq(0):
pass # we don't yield until seq(2) below
record.append("child1 raise")
with pytest.raises(ValueError, match="^child1$") as excinfo:
with pytest.raises(ValueError, match=r"^child1$") as excinfo:
try:
raise ValueError("child1")
except ValueError:
Expand Down Expand Up @@ -1360,7 +1360,7 @@ async def main() -> None:
token.run_sync_soon(lambda: record.append("sync-cb"))
raise ValueError("error text")

with pytest.raises(ValueError, match="^error text$"):
with pytest.raises(ValueError, match=r"^error text$"):
_core.run(main)

assert record == ["sync-cb"]
Expand Down Expand Up @@ -1724,12 +1724,12 @@ async def async_gen(arg: T) -> AsyncGenerator[T, None]: # pragma: no cover
# different ways
with pytest.raises(
TypeError,
match="^Trio was expecting an async function, but instead it got a coroutine object <.*>",
match=r"^Trio was expecting an async function, but instead it got a coroutine object <.*>",
):
bad_call_run(f()) # type: ignore[arg-type]
with pytest.raises(
TypeError,
match="expected an async function but got an async generator",
match=r"expected an async function but got an async generator",
):
bad_call_run(async_gen, 0) # type: ignore

Expand Down Expand Up @@ -2655,7 +2655,7 @@ def run_main() -> None:
# mypy doesn't like kwarg magic
_core.run(main, **_create_kwargs(run_strict)) # type: ignore[arg-type]

matcher = Matcher(RuntimeError, "^test error$")
matcher = Matcher(RuntimeError, r"^test error$")

if multiple_exceptions:
with RaisesGroup(matcher, matcher):
Expand All @@ -2666,7 +2666,7 @@ def run_main() -> None:
with RaisesGroup(matcher):
run_main()
else:
with pytest.raises(RuntimeError, match="^test error$"):
with pytest.raises(RuntimeError, match=r"^test error$"):
run_main()


Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
async def test_channel() -> None:
with pytest.raises(TypeError):
open_memory_channel(1.0)
with pytest.raises(ValueError, match="^max_buffer_size must be >= 0$"):
with pytest.raises(ValueError, match=r"^max_buffer_size must be >= 0$"):
open_memory_channel(-1)

s, r = open_memory_channel[Union[int, str, None]](2)
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_tests/test_dtls.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def test_smoke(ipv6: bool) -> None:

with pytest.raises(
ValueError,
match="^openssl doesn't support sending empty DTLS packets$",
match=r"^openssl doesn't support sending empty DTLS packets$",
):
await client_channel.send(b"")

Expand Down Expand Up @@ -299,7 +299,7 @@ async def null_handler(_: object) -> None: # pragma: no cover

async def test_dtls_over_dgram_only() -> None:
with trio.socket.socket() as s:
with pytest.raises(ValueError, match="^DTLS requires a SOCK_DGRAM socket$"):
with pytest.raises(ValueError, match=r"^DTLS requires a SOCK_DGRAM socket$"):
DTLSEndpoint(s)


Expand Down
26 changes: 15 additions & 11 deletions src/trio/_tests/test_fakenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def test_recv_methods() -> None:
assert await s1.sendto(b"ghi", s2.getsockname()) == 3
buf = bytearray(10)

with pytest.raises(NotImplementedError, match="^partial recvfrom_into$"):
with pytest.raises(NotImplementedError, match=r"^partial recvfrom_into$"):
(nbytes, addr) = await s2.recvfrom_into(buf, nbytes=2)

(nbytes, addr) = await s2.recvfrom_into(buf)
Expand All @@ -121,14 +121,18 @@ async def test_recv_methods() -> None:
with pytest.raises(OSError, match=ENOTCONN_MSG) as exc:
await s2.send(b"mno")
assert exc.value.errno == errno.ENOTCONN
with pytest.raises(NotImplementedError, match="^FakeNet send flags must be 0, not"):
with pytest.raises(
NotImplementedError, match=r"^FakeNet send flags must be 0, not"
):
await s2.send(b"mno", flags)

# sendto errors
# it's successfully used earlier
with pytest.raises(NotImplementedError, match="^FakeNet send flags must be 0, not"):
with pytest.raises(
NotImplementedError, match=r"^FakeNet send flags must be 0, not"
):
await s2.sendto(b"mno", flags, s1.getsockname())
with pytest.raises(TypeError, match="wrong number of arguments$"):
with pytest.raises(TypeError, match=r"wrong number of arguments$"):
await s2.sendto(b"mno", flags, s1.getsockname(), "extra arg") # type: ignore[call-overload]


Expand Down Expand Up @@ -184,7 +188,7 @@ async def test_nonwindows_functionality() -> None:

with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'share'$",
match=r"^'FakeSocket' object has no attribute 'share'$",
):
await s1.share(0) # type: ignore[attr-defined]

Expand All @@ -202,17 +206,17 @@ async def test_windows_functionality() -> None:
await s1.bind(("127.0.0.1", 0))
with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'sendmsg'$",
match=r"^'FakeSocket' object has no attribute 'sendmsg'$",
):
await s1.sendmsg([b"jkl"], (), 0, s2.getsockname()) # type: ignore[attr-defined]
with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'recvmsg'$",
match=r"^'FakeSocket' object has no attribute 'recvmsg'$",
):
s2.recvmsg(0) # type: ignore[attr-defined]
with pytest.raises(
AttributeError,
match="^'FakeSocket' object has no attribute 'recvmsg_into'$",
match=r"^'FakeSocket' object has no attribute 'recvmsg_into'$",
):
s2.recvmsg_into([]) # type: ignore[attr-defined]
with pytest.raises(NotImplementedError):
Expand All @@ -239,7 +243,7 @@ async def test_not_implemented_functions() -> None:
# setsockopt
with pytest.raises(
NotImplementedError,
match="^FakeNet always has IPV6_V6ONLY=True$",
match=r"^FakeNet always has IPV6_V6ONLY=True$",
):
s1.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
with pytest.raises(
Expand All @@ -257,7 +261,7 @@ async def test_not_implemented_functions() -> None:
s1.set_inheritable(False)
with pytest.raises(
NotImplementedError,
match="^FakeNet can't make inheritable sockets$",
match=r"^FakeNet can't make inheritable sockets$",
):
s1.set_inheritable(True)

Expand All @@ -276,7 +280,7 @@ async def test_getpeername() -> None:

with pytest.raises(
AssertionError,
match="^This method seems to assume that self._binding has a remote UDPEndpoint$",
match=r"^This method seems to assume that self._binding has a remote UDPEndpoint$",
):
s1.getpeername()

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def aclose(self) -> NoReturn:

stapled = StapledStream(BrokenSendStream(), BrokenReceiveStream())

with pytest.raises(ValueError, match="^(send|recv) error$") as excinfo:
with pytest.raises(ValueError, match=r"^(send|recv) error$") as excinfo:
await stapled.aclose()
assert isinstance(excinfo.value.__context__, ValueError)

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_open_tcp_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def test_open_tcp_listeners_rebind() -> None:
probe.setsockopt(stdlib_socket.SOL_SOCKET, stdlib_socket.SO_REUSEADDR, 1)
with pytest.raises(
OSError,
match="(Address (already )?in use|An attempt was made to access a socket in a way forbidden by its access permissions)$",
match=r"(Address (already )?in use|An attempt was made to access a socket in a way forbidden by its access permissions)$",
):
probe.bind(sockaddr1)

Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_open_tcp_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def test_open_tcp_stream_real_socket_smoketest() -> None:


async def test_open_tcp_stream_input_validation() -> None:
with pytest.raises(ValueError, match="^host must be str or bytes, not None$"):
with pytest.raises(ValueError, match=r"^host must be str or bytes, not None$"):
await open_tcp_stream(None, 80) # type: ignore[arg-type]
with pytest.raises(TypeError):
await open_tcp_stream("127.0.0.1", b"80") # type: ignore[arg-type]
Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_highlevel_open_unix_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ async def test_open_unix_socket() -> None:
async def test_error_on_no_unix() -> None:
with pytest.raises(
RuntimeError,
match="^Unix sockets are not supported on this platform$",
match=r"^Unix sockets are not supported on this platform$",
):
await open_unix_socket("")
6 changes: 3 additions & 3 deletions src/trio/_tests/test_highlevel_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_SocketStream_basics() -> None:
with tsocket.socket(type=tsocket.SOCK_DGRAM) as sock:
with pytest.raises(
ValueError,
match="^SocketStream requires a SOCK_STREAM socket$",
match=r"^SocketStream requires a SOCK_STREAM socket$",
):
# TODO: does not raise an error?
SocketStream(sock)
Expand Down Expand Up @@ -169,7 +169,7 @@ async def test_SocketListener() -> None:
await s.bind(("127.0.0.1", 0))
with pytest.raises(
ValueError,
match="^SocketListener requires a SOCK_STREAM socket$",
match=r"^SocketListener requires a SOCK_STREAM socket$",
) as excinfo:
SocketListener(s)
excinfo.match(r".*SOCK_STREAM")
Expand All @@ -181,7 +181,7 @@ async def test_SocketListener() -> None:
await s.bind(("127.0.0.1", 0))
with pytest.raises(
ValueError,
match="^SocketListener requires a listening socket$",
match=r"^SocketListener requires a listening socket$",
) as excinfo:
SocketListener(s)
excinfo.match(r".*listen")
Expand Down
2 changes: 1 addition & 1 deletion src/trio/_tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def test_open_signal_receiver_restore_handler_after_one_bad_signal() -> No
orig = signal.getsignal(signal.SIGILL)
with pytest.raises(
ValueError,
match="(signal number out of range|invalid signal value)$",
match=r"(signal number out of range|invalid signal value)$",
):
with open_signal_receiver(signal.SIGILL, 1234567):
pass # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions src/trio/_tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ async def test_run() -> None:
await run_process(CAT, stderr=subprocess.PIPE)
with pytest.raises(
ValueError,
match="^can't specify both stdout and capture_stdout$",
match=r"^can't specify both stdout and capture_stdout$",
):
await run_process(CAT, capture_stdout=True, stdout=subprocess.DEVNULL)
with pytest.raises(
ValueError,
match="^can't specify both stderr and capture_stderr$",
match=r"^can't specify both stderr and capture_stderr$",
):
await run_process(CAT, capture_stderr=True, stderr=None)

Expand Down
Loading

0 comments on commit c479af6

Please sign in to comment.