Skip to content

fix(hansbug): try add the tempfile using back #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/entry/cli/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,6 @@ def test_file_with_invalid_permission(self):
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
8 changes: 7 additions & 1 deletion treevalue/entry/cli/graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import codecs
import os
import shutil
import tempfile
import warnings
from collections import OrderedDict
from functools import partial
Expand Down Expand Up @@ -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'}
Expand Down