Move betterproto/tests → tests
This commit is contained in:
committed by
Bouke Versteegh
parent
8864f4fdbd
commit
cebf9176a3
40
tests/mocks.py
Normal file
40
tests/mocks.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from typing import List
|
||||
|
||||
from grpclib.client import Channel
|
||||
|
||||
|
||||
class MockChannel(Channel):
|
||||
# noinspection PyMissingConstructor
|
||||
def __init__(self, responses=None) -> None:
|
||||
self.responses = responses if responses else []
|
||||
self.requests = []
|
||||
self._loop = None
|
||||
|
||||
def request(self, route, cardinality, request, response_type, **kwargs):
|
||||
self.requests.append(
|
||||
{
|
||||
"route": route,
|
||||
"cardinality": cardinality,
|
||||
"request": request,
|
||||
"response_type": response_type,
|
||||
}
|
||||
)
|
||||
return MockStream(self.responses)
|
||||
|
||||
|
||||
class MockStream:
|
||||
def __init__(self, responses: List) -> None:
|
||||
super().__init__()
|
||||
self.responses = responses
|
||||
|
||||
async def recv_message(self):
|
||||
return self.responses.pop(0)
|
||||
|
||||
async def send_message(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
return True
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
Reference in New Issue
Block a user