Debian Codegraph @

src/trio/_tests/test_deprecate_strict_exception_groups_false.py

raw
1 from collections.abc import Awaitable, Callable
2
3 import pytest
4
5 import trio
6
7
8 async def test_deprecation_warning_open_nursery() -> None:
9 with pytest.warns(
10 trio.TrioDeprecationWarning,
11 match="strict_exception_groups=False",
12 ) as record:
13 async with trio.open_nursery(strict_exception_groups=False):
14 ...
15 assert len(record) == 1
16 async with trio.open_nursery(strict_exception_groups=True):
17 ...
18 async with trio.open_nursery():
19 ...
20
21
22 def test_deprecation_warning_run() -> None:
23 async def foo() -> None: ...
24
25 async def foo_nursery() -> None:
26 # this should not raise a warning, even if it's implied loose
27 async with trio.open_nursery():
28 ...
29
30 async def foo_loose_nursery() -> None:
31 # this should raise a warning, even if specifying the parameter is redundant
32 async with trio.open_nursery(strict_exception_groups=False):
33 ...
34
35 def helper(fun: Callable[[], Awaitable[None]], num: int) -> None:
36 with pytest.warns(
37 trio.TrioDeprecationWarning,
38 match="strict_exception_groups=False",
39 ) as record:
40 trio.run(fun, strict_exception_groups=False)
41 assert len(record) == num
42
43 helper(foo, 1)
44 helper(foo_nursery, 1)
45 helper(foo_loose_nursery, 2)
46
47
48 def test_deprecation_warning_start_guest_run() -> None:
49 # "The simplest possible "host" loop."
50 from .._core._tests.test_guest_mode import trivial_guest_run
51
52 async def trio_return(in_host: object) -> str:
53 await trio.lowlevel.checkpoint()
54 return "ok"
55
56 with pytest.warns(
57 trio.TrioDeprecationWarning,
58 match="strict_exception_groups=False",
59 ) as record:
60 trivial_guest_run(
61 trio_return,
62 strict_exception_groups=False,
63 )
64 assert len(record) == 1