Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_render_pdf():
output = dump_graphviz(tree, output_format='pdf')
@contextmanager
def redirect_stdout(new_target):
old_target, sys.stdout = sys.stdout, new_target
try:
yield new_target
finally:
sys.stdout = old_target
f = NamedTemporaryFile(delete=False)
with redirect_stdout(f):
print_graphviz(output)
with open(f.name, 'rb') as rf:
out = rf.read()
os.remove(f.name)
assert out[:4] == b'%PDF'
def test_render_svg(capsys):
output = dump_graphviz(tree, output_format='svg')
print_graphviz(output)
out, _ = capsys.readouterr()
assert out.startswith('')
def test_render_json(capsys):
output = render_json(tree, indent=4)
print_graphviz(output)
out, _ = capsys.readouterr()
assert out.startswith('[\n {\n "')
assert out.strip().endswith('}\n]')
data = json.loads(out)
assert 'package' in data[0]
assert 'dependencies' in data[0]