Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/anyio/abc/_testing.py: 84%
19 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:12 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:12 +0000
1import types
2from abc import ABCMeta, abstractmethod
3from collections.abc import AsyncGenerator, Iterable
4from typing import Any, Callable, Coroutine, Dict, Optional, Type, TypeVar
6_T = TypeVar("_T")
9class TestRunner(metaclass=ABCMeta):
10 """
11 Encapsulates a running event loop. Every call made through this object will use the same event
12 loop.
13 """
15 def __enter__(self) -> "TestRunner":
16 return self
18 def __exit__(
19 self,
20 exc_type: Optional[Type[BaseException]],
21 exc_val: Optional[BaseException],
22 exc_tb: Optional[types.TracebackType],
23 ) -> Optional[bool]:
24 self.close()
25 return None
27 @abstractmethod
28 def close(self) -> None:
29 """Close the event loop."""
31 @abstractmethod
32 def run_asyncgen_fixture(
33 self,
34 fixture_func: Callable[..., "AsyncGenerator[_T, Any]"],
35 kwargs: Dict[str, Any],
36 ) -> "Iterable[_T]":
37 """
38 Run an async generator fixture.
40 :param fixture_func: the fixture function
41 :param kwargs: keyword arguments to call the fixture function with
42 :return: an iterator yielding the value yielded from the async generator
43 """
45 @abstractmethod
46 def run_fixture(
47 self,
48 fixture_func: Callable[..., Coroutine[Any, Any, _T]],
49 kwargs: Dict[str, Any],
50 ) -> _T:
51 """
52 Run an async fixture.
54 :param fixture_func: the fixture function
55 :param kwargs: keyword arguments to call the fixture function with
56 :return: the return value of the fixture function
57 """
59 @abstractmethod
60 def run_test(
61 self, test_func: Callable[..., Coroutine[Any, Any, Any]], kwargs: Dict[str, Any]
62 ) -> None:
63 """
64 Run an async test function.
66 :param test_func: the test function
67 :param kwargs: keyword arguments to call the test function with
68 """