提交 23f98edd 编写于 作者: HansBug's avatar HansBug 😆

fix(hansbug): try simplify the saving of the images

上级 835d2268
...@@ -7,7 +7,7 @@ import zlib ...@@ -7,7 +7,7 @@ import zlib
import pytest import pytest
from click.testing import CliRunner from click.testing import CliRunner
from hbutils.testing import cmdv from hbutils.testing import cmdv, OS
from treevalue import FastTreeValue, dump, graphics from treevalue import FastTreeValue, dump, graphics
from treevalue.entry.cli import treevalue_cli from treevalue.entry.cli import treevalue_cli
...@@ -244,4 +244,7 @@ class TestEntryCliGraph: ...@@ -244,4 +244,7 @@ class TestEntryCliGraph:
assert result.exit_code == 0, f'Runtime Error (exitcode {result.exit_code}), ' \ assert result.exit_code == 0, f'Runtime Error (exitcode {result.exit_code}), ' \
f'The output is:\n{result.output}' f'The output is:\n{result.output}'
assert os.path.exists('test_graph.svg') assert os.path.exists('test_graph.svg')
assert os.path.getsize('test_graph.svg') <= 1000 if OS.windows:
assert os.path.getsize('test_graph.svg') <= 2000
else:
assert os.path.getsize('test_graph.svg') <= 1000
import codecs import codecs
import os import os
import shutil
import tempfile
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
from functools import partial from functools import partial
...@@ -61,10 +59,7 @@ def _save_source_code(g: Digraph, path: str): ...@@ -61,10 +59,7 @@ def _save_source_code(g: Digraph, path: str):
def _save_image(g: Digraph, path: str, fmt: str): def _save_image(g: Digraph, path: str, fmt: str):
with tempfile.TemporaryDirectory() as tmpdir: g.render(path, format=fmt)
with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile:
svg_file = g.render(tmpfile.name, format=fmt)
shutil.copy(svg_file, path)
_IMAGE_FMTS = {'svg', 'png'} _IMAGE_FMTS = {'svg', 'png'}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册