|
1 | 1 | import platform
|
| 2 | +import random |
2 | 3 | import subprocess
|
3 | 4 | import sys
|
4 | 5 | from contextlib import contextmanager
|
5 | 6 | from itertools import chain
|
6 | 7 | from pathlib import Path
|
7 | 8 | from tempfile import NamedTemporaryFile
|
| 9 | +from textwrap import dedent |
8 | 10 |
|
9 | 11 | try:
|
10 | 12 | from unittest import mock
|
@@ -304,6 +306,52 @@ def test_render_text(capsys, list_all, reverse, expected_output):
|
304 | 306 | # Tests for graph outputs
|
305 | 307 |
|
306 | 308 |
|
| 309 | +def test_render_dot(capsys): |
| 310 | + # Extract the dependency graph from the package tree fixture and randomize it. |
| 311 | + randomized_graph = {} |
| 312 | + randomized_nodes = list(t._obj.keys()) |
| 313 | + random.shuffle(randomized_nodes) |
| 314 | + for node in randomized_nodes: |
| 315 | + edges = t._obj[node] |
| 316 | + random.shuffle(edges) |
| 317 | + randomized_graph[node] = edges |
| 318 | + assert set(randomized_graph) == set(t._obj) |
| 319 | + |
| 320 | + # Create a randomized package tree. |
| 321 | + randomized_dag = p.PackageDAG(randomized_graph) |
| 322 | + assert len(t) == len(randomized_dag) |
| 323 | + |
| 324 | + # Check both the sorted and randomized package tree produces the same sorted |
| 325 | + # graphviz output. |
| 326 | + for package_tree in (t, randomized_dag): |
| 327 | + output = p.dump_graphviz(package_tree, output_format="dot") |
| 328 | + p.print_graphviz(output) |
| 329 | + out, _ = capsys.readouterr() |
| 330 | + assert out == dedent( |
| 331 | + """\ |
| 332 | + digraph { |
| 333 | + \ta -> b [label=">=2.0.0"] |
| 334 | + \ta -> c [label=">=5.7.1"] |
| 335 | + \ta [label="a\\n3.4.0"] |
| 336 | + \tb -> d [label=">=2.30,<2.42"] |
| 337 | + \tb [label="b\\n2.3.1"] |
| 338 | + \tc -> d [label=">=2.30"] |
| 339 | + \tc -> e [label=">=0.12.1"] |
| 340 | + \tc [label="c\\n5.10.0"] |
| 341 | + \td -> e [label=">=0.9.0"] |
| 342 | + \td [label="d\\n2.35"] |
| 343 | + \te [label="e\\n0.12.1"] |
| 344 | + \tf -> b [label=">=2.1.0"] |
| 345 | + \tf [label="f\\n3.1"] |
| 346 | + \tg -> e [label=">=0.9.0"] |
| 347 | + \tg -> f [label=">=3.0.0"] |
| 348 | + \tg [label="g\\n6.8.3rc1"] |
| 349 | + } |
| 350 | +
|
| 351 | + """ |
| 352 | + ) |
| 353 | + |
| 354 | + |
307 | 355 | def test_render_pdf():
|
308 | 356 | output = p.dump_graphviz(t, output_format="pdf")
|
309 | 357 |
|
|
0 commit comments