Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

38 строки
1.1 KiB

  1. import types
  2. from abc import ABCMeta, abstractmethod
  3. from typing import Any, Awaitable, Callable, Dict, Optional, Type, TypeVar
  4. _T = TypeVar("_T")
  5. class TestRunner(metaclass=ABCMeta):
  6. """
  7. Encapsulates a running event loop. Every call made through this object will use the same event
  8. loop.
  9. """
  10. def __enter__(self) -> 'TestRunner':
  11. return self
  12. def __exit__(self, exc_type: Optional[Type[BaseException]],
  13. exc_val: Optional[BaseException],
  14. exc_tb: Optional[types.TracebackType]) -> Optional[bool]:
  15. self.close()
  16. return None
  17. @abstractmethod
  18. def close(self) -> None:
  19. """Close the event loop."""
  20. @abstractmethod
  21. def call(self, func: Callable[..., Awaitable[_T]],
  22. *args: object, **kwargs: Dict[str, Any]) -> _T:
  23. """
  24. Call the given function within the backend's event loop.
  25. :param func: a callable returning an awaitable
  26. :param args: positional arguments to call ``func`` with
  27. :param kwargs: keyword arguments to call ``func`` with
  28. :return: the return value of ``func``
  29. """