提交 63a43aa3 编写于 作者: HansBug's avatar HansBug 😆

fix(hansbug): remove named temporary file when rendering images

上级 49c17d92
......@@ -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
......@@ -60,9 +60,11 @@ 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):
with tempfile.NamedTemporaryFile() as tmpfile:
svg_file = g.render(tmpfile.name, format=fmt)
with tempfile.TemporaryDirectory() as tmpdir:
svg_file = g.render(os.path.join(tmpdir, 'source.gv'), format=fmt)
shutil.copy(svg_file, path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册