Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/anyio/abc/_testing.py: 91%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

23 statements  

1from __future__ import annotations 

2 

3import sys 

4import types 

5from abc import ABCMeta, abstractmethod 

6from collections.abc import AsyncGenerator, Callable, Coroutine, Iterable 

7from typing import Any, TypeVar 

8 

9if sys.version_info >= (3, 11): 

10 from typing import Self 

11else: 

12 from typing_extensions import Self 

13 

14_T = TypeVar("_T") 

15 

16 

17class TestRunner(metaclass=ABCMeta): 

18 """ 

19 Encapsulates a running event loop. Every call made through this object will use the 

20 same event loop. 

21 """ 

22 

23 def __enter__(self) -> Self: 

24 return self 

25 

26 @abstractmethod 

27 def __exit__( 

28 self, 

29 exc_type: type[BaseException] | None, 

30 exc_val: BaseException | None, 

31 exc_tb: types.TracebackType | None, 

32 ) -> bool | None: ... 

33 

34 @abstractmethod 

35 def run_asyncgen_fixture( 

36 self, 

37 fixture_func: Callable[..., AsyncGenerator[_T, Any]], 

38 kwargs: dict[str, Any], 

39 ) -> Iterable[_T]: 

40 """ 

41 Run an async generator fixture. 

42 

43 :param fixture_func: the fixture function 

44 :param kwargs: keyword arguments to call the fixture function with 

45 :return: an iterator yielding the value yielded from the async generator 

46 """ 

47 

48 @abstractmethod 

49 def run_fixture( 

50 self, 

51 fixture_func: Callable[..., Coroutine[Any, Any, _T]], 

52 kwargs: dict[str, Any], 

53 ) -> _T: 

54 """ 

55 Run an async fixture. 

56 

57 :param fixture_func: the fixture function 

58 :param kwargs: keyword arguments to call the fixture function with 

59 :return: the return value of the fixture function 

60 """ 

61 

62 @abstractmethod 

63 def run_test( 

64 self, test_func: Callable[..., Coroutine[Any, Any, Any]], kwargs: dict[str, Any] 

65 ) -> None: 

66 """ 

67 Run an async test function. 

68 

69 :param test_func: the test function 

70 :param kwargs: keyword arguments to call the test function with 

71 """ 

72 

73 @abstractmethod 

74 def is_running(self) -> bool: 

75 """ 

76 Check if the test runner is running. 

77 

78 :return: ``True`` if the coroutine is currently being run, ``False`` otherwise. 

79 """