You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					38 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					38 lines
				
				1.1 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								import types
							 | 
						||
| 
								 | 
							
								from abc import ABCMeta, abstractmethod
							 | 
						||
| 
								 | 
							
								from typing import Any, Awaitable, Callable, Dict, Optional, Type, TypeVar
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								_T = TypeVar("_T")
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class TestRunner(metaclass=ABCMeta):
							 | 
						||
| 
								 | 
							
								    """
							 | 
						||
| 
								 | 
							
								    Encapsulates a running event loop. Every call made through this object will use the same event
							 | 
						||
| 
								 | 
							
								    loop.
							 | 
						||
| 
								 | 
							
								    """
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    def __enter__(self) -> 'TestRunner':
							 | 
						||
| 
								 | 
							
								        return self
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    def __exit__(self, exc_type: Optional[Type[BaseException]],
							 | 
						||
| 
								 | 
							
								                 exc_val: Optional[BaseException],
							 | 
						||
| 
								 | 
							
								                 exc_tb: Optional[types.TracebackType]) -> Optional[bool]:
							 | 
						||
| 
								 | 
							
								        self.close()
							 | 
						||
| 
								 | 
							
								        return None
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @abstractmethod
							 | 
						||
| 
								 | 
							
								    def close(self) -> None:
							 | 
						||
| 
								 | 
							
								        """Close the event loop."""
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    @abstractmethod
							 | 
						||
| 
								 | 
							
								    def call(self, func: Callable[..., Awaitable[_T]],
							 | 
						||
| 
								 | 
							
								             *args: object, **kwargs: Dict[str, Any]) -> _T:
							 | 
						||
| 
								 | 
							
								        """
							 | 
						||
| 
								 | 
							
								        Call the given function within the backend's event loop.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        :param func: a callable returning an awaitable
							 | 
						||
| 
								 | 
							
								        :param args: positional arguments to call ``func`` with
							 | 
						||
| 
								 | 
							
								        :param kwargs: keyword arguments to call ``func`` with
							 | 
						||
| 
								 | 
							
								        :return: the return value of ``func``
							 | 
						||
| 
								 | 
							
								        """
							 |