Merge branch 'feature/mermaid_suffixes' into 'mgx_ops'

feat: mermaid_to_file + suffixes

See merge request pub/MetaGPT!328
This commit is contained in:
林义章 2024-08-20 02:19:16 +00:00
commit efa28c8523
7 changed files with 91 additions and 43 deletions

View file

@ -8,28 +8,32 @@
import pytest
from metagpt.utils.common import check_cmd_exists
from metagpt.const import DEFAULT_WORKSPACE_ROOT
from metagpt.utils.common import check_cmd_exists, new_transaction_id
from metagpt.utils.mermaid import MMC1, mermaid_to_file
@pytest.mark.asyncio
@pytest.mark.parametrize("engine", ["nodejs", "ink"]) # TODO: playwright and pyppeteer
async def test_mermaid(engine, context, mermaid_mocker):
@pytest.mark.parametrize(
("engine", "suffixes"), [("nodejs", None), ("nodejs", ["png", "svg", "pdf"]), ("ink", None)]
) # TODO: playwright and pyppeteer
async def test_mermaid(engine, suffixes, context, mermaid_mocker):
# nodejs prerequisites: npm install -g @mermaid-js/mermaid-cli
# ink prerequisites: connected to internet
# playwright prerequisites: playwright install --with-deps chromium
assert check_cmd_exists("npm") == 0
save_to = context.git_repo.workdir / f"{engine}/1"
await mermaid_to_file(engine, MMC1, save_to)
save_to = DEFAULT_WORKSPACE_ROOT / f"{new_transaction_id()}/{engine}/1"
await mermaid_to_file(engine, MMC1, save_to, suffixes=suffixes)
# ink does not support pdf
exts = ["." + i for i in suffixes] if suffixes else [".png"]
if engine == "ink":
for ext in [".svg", ".png"]:
for ext in exts:
assert save_to.with_suffix(ext).exists()
save_to.with_suffix(ext).unlink(missing_ok=True)
else:
for ext in [".pdf", ".svg", ".png"]:
for ext in exts:
assert save_to.with_suffix(ext).exists()
save_to.with_suffix(ext).unlink(missing_ok=True)