mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-26 15:49:42 +02:00
add ut mocker for mermaid ink
This commit is contained in:
parent
7c3ac6a350
commit
88b9bf9151
4 changed files with 60 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ class MockAioResponse:
|
|||
check_funcs: dict[tuple[str, str], Callable[[dict], str]] = {}
|
||||
rsp_cache: dict[str, str] = {}
|
||||
name = "aiohttp"
|
||||
status = 200
|
||||
|
||||
def __init__(self, session, method, url, **kwargs) -> None:
|
||||
fn = self.check_funcs.get((method, url))
|
||||
|
|
@ -21,6 +22,7 @@ class MockAioResponse:
|
|||
async def __aenter__(self):
|
||||
if self.response:
|
||||
await self.response.__aenter__()
|
||||
self.status = self.response.status
|
||||
elif self.mng:
|
||||
self.response = await self.mng.__aenter__()
|
||||
return self
|
||||
|
|
@ -39,3 +41,14 @@ class MockAioResponse:
|
|||
data = await self.response.json(*args, **kwargs)
|
||||
self.rsp_cache[self.key] = data
|
||||
return data
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
return self
|
||||
|
||||
async def read(self):
|
||||
if self.key in self.rsp_cache:
|
||||
return eval(self.rsp_cache[self.key])
|
||||
data = await self.response.content.read()
|
||||
self.rsp_cache[self.key] = str(data)
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue