Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(render, ['dot', 'pdf', 'nonfilepath']),
(pipe, ['dot', 'pdf', b'nongraph']),
(version, []),
])
def test_missing_executable(func, args):
with pytest.raises(ExecutableNotFound, match=r'execute'):
func(*args)
def test_render_format_unknown():
with pytest.raises(ValueError, match=r'unknown format'):
render('dot', '', 'nonfilepath')
def test_render_renderer_missing():
with pytest.raises(RequiredArgumentError, match=r'without renderer'):
render('dot', 'ps', 'nonfilepath', None, 'core')
def test_render_mocked(capsys, mocker, Popen, quiet): # noqa: N803
proc = Popen.return_value
proc.returncode = 0
proc.communicate.return_value = (b'stdout', b'stderr')
assert render('dot', 'pdf', 'nonfilepath', quiet=quiet) == 'nonfilepath.pdf'
Popen.assert_called_once_with(['dot', '-Tpdf', '-O', 'nonfilepath'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=None, startupinfo=mocker.ANY)
check_startupinfo(Popen.call_args.kwargs['startupinfo'])
proc.communicate.assert_called_once_with(None)
assert capsys.readouterr() == ('', '' if quiet else 'stderr')
subdir = tmpdir / 'subdir'
subdir.ensure(dir=True)
img_path = subdir / 'dot_red.png'
(filesdir / img_path.basename).copy(img_path)
assert img_path.size()
gv_path = subdir / 'img.gv'
rendered = gv_path.new(ext='%s.%s' % (gv_path.ext, format_))
gv_rel, rendered_rel = map(tmpdir.bestrelpath, (gv_path, rendered))
assert all(s.startswith('subdir') for s in (gv_rel, rendered_rel))
gv_path.write_text(u'graph { red_dot [image="%s"] }' % img_path.basename,
encoding='ascii')
with tmpdir.as_cwd():
assert render(engine, format_, gv_rel) == rendered_rel
assert rendered.size()
assert capsys.readouterr() == ('', '')
def test_render(capsys, tmpdir, engine, format_, renderer, formatter,
expected_suffix, filename='hello.gv',
data=b'digraph { hello -> world }'):
lpath = tmpdir / filename
lpath.write_binary(data)
rendered = lpath.new(ext='%s.%s' % (lpath.ext, expected_suffix))
assert render(engine, format_, str(lpath), renderer, formatter) == str(rendered)
assert rendered.size()
assert capsys.readouterr() == ('', '')
def test_render_engine_unknown():
with pytest.raises(ValueError, match=r'unknown engine'):
render('', 'pdf', 'nonfilepath')
def test_render_missing_file(quiet, engine='dot', format_='pdf'):
with pytest.raises(subprocess.CalledProcessError) as e:
render(engine, format_, '', quiet=quiet)
assert e.value.returncode == 2
def test_render_renderer_unknown():
with pytest.raises(ValueError, match=r'unknown renderer'):
render('dot', 'ps', 'nonfilepath', '', None)
ValueError: If ``format``, ``renderer``, or ``formatter`` are not known.
graphviz.RequiredArgumentError: If ``formatter`` is given but ``renderer`` is None.
graphviz.ExecutableNotFound: If the Graphviz executable is not found.
subprocess.CalledProcessError: If the exit status is non-zero.
RuntimeError: If viewer opening is requested but not supported.
The layout command is started from the directory of ``filepath``, so that
references to external files (e.g. ``[image=...]``) can be given as paths
relative to the DOT source file.
"""
filepath = self.save(filename, directory)
if format is None:
format = self._format
rendered = backend.render(self._engine, format, filepath,
renderer=renderer, formatter=formatter,
quiet=quiet)
if cleanup:
log.debug('delete %r', filepath)
os.remove(filepath)
if quiet_view or view:
self._view(rendered, self._format, quiet_view)
return rendered