未验证 提交 62d2311a 编写于 作者: HansBug's avatar HansBug 😆 提交者: GitHub

Merge pull request #51 from opendilab/fix/graph

fix(hansbug): try add the tempfile using back
......@@ -245,6 +245,6 @@ class TestEntryCliGraph:
f'The output is:\n{result.output}'
assert os.path.exists('test_graph.svg')
if OS.windows:
assert os.path.getsize('test_graph.svg') <= 2000
assert 5000 <= os.path.getsize('test_graph.svg') <= 6500
else:
assert os.path.getsize('test_graph.svg') <= 1000
assert 500 <= os.path.getsize('test_graph.svg') <= 1000
import codecs
import os
import shutil
import tempfile
import warnings
from collections import OrderedDict
from functools import partial
......@@ -58,8 +60,12 @@ def _save_source_code(g: Digraph, path: str):
file.write(g.source)
# Do not reopen an opened file in windows, it may cause PermissionDenied
# See: https://stackoverflow.com/a/23212515/6995899
def _save_image(g: Digraph, path: str, fmt: str):
g.render(path, format=fmt)
with tempfile.TemporaryDirectory() as tmpdir:
svg_file = g.render(os.path.join(tmpdir, 'source.gv'), format=fmt)
shutil.copy(svg_file, path)
_IMAGE_FMTS = {'svg', 'png'}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册