Coverage for tests/test_param_cancellable.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 01:12 +0000

1import warnings 1klmno

2 

3import anyio 1klmno

4import pytest 1klmno

5from asyncer import asyncify 1klmno

6 

7 

8def test_cancellable_warns(): 1klmno

9 def do_async_work(): 1abcde

10 return "Hello World!" 1abcde

11 

12 async def main(): 1abcde

13 result = await asyncify(do_async_work, cancellable=True)() 1abcde

14 return result 1abcde

15 

16 with pytest.warns(DeprecationWarning) as record: 1abcde

17 result = anyio.run(main) 1abcde

18 assert isinstance(record[0].message, Warning) 1abcde

19 assert ( 1abcde

20 "The `cancellable=` keyword argument to `asyncer.asyncify()` is " 

21 "deprecated since Asyncer 0.0.8" in record[0].message.args[0] 

22 ) 

23 assert result == "Hello World!" 1abcde

24 

25 

26def test_abandon_on_cancel_no(): 1klmno

27 def do_async_work(): 1fghij

28 return "Hello World!" 1fghij

29 

30 async def main(): 1fghij

31 result = await asyncify(do_async_work, abandon_on_cancel=True)() 1fghij

32 return result 1fghij

33 

34 with warnings.catch_warnings(): 1fghij

35 warnings.simplefilter("error") 1fghij

36 result = anyio.run(main) 1fghij

37 assert result == "Hello World!" 1fghij