Skip to content

Commit 3faf413

Browse files
tirkarthidaavoo
authored andcommitted
Use sorted output in test since order is not deterministic.
Co-authored-by: David de la Iglesia Castro <daviddelaiglesiacastro@gmail.com>
1 parent a326163 commit 3faf413

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

dvc/commands/dag.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ def _show_dot(G):
2323

2424
from networkx.drawing.nx_pydot import write_dot
2525

26-
G = G.reverse()
2726
dot_file = io.StringIO()
28-
write_dot(G, dot_file)
27+
write_dot(G.reverse(), dot_file)
2928
return dot_file.getvalue()
3029

3130

tests/unit/command/test_dag.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,29 @@ def test_show_ascii(repo):
135135

136136

137137
def test_show_dot(repo):
138-
assert _show_dot(repo.index.graph) == (
139-
"strict digraph {\n"
140-
"stage;\n"
141-
"stage;\n"
142-
"stage;\n"
143-
"stage;\n"
144-
"stage;\n"
145-
"stage;\n"
146-
"\"stage: 'b.dvc'\" -> \"stage: '2'\";\n"
147-
"\"stage: 'b.dvc'\" -> \"stage: '3'\";\n"
148-
"\"stage: 'a.dvc'\" -> \"stage: '1'\";\n"
149-
"\"stage: 'a.dvc'\" -> \"stage: '3'\";\n"
150-
"\"stage: 'a.dvc'\" -> \"stage: '4'\";\n"
151-
"\"stage: '3'\" -> \"stage: '4'\";\n"
152-
"}\n"
138+
# dot file rendering is not deterministic though graph
139+
# output doesn't depend upon order of lines. Use sorted values
140+
# https://github.com/iterative/dvc/pull/7725
141+
expected = [
142+
"\"stage: '3'\" -> \"stage: '4'\";",
143+
"\"stage: 'a.dvc'\" -> \"stage: '1'\";",
144+
"\"stage: 'a.dvc'\" -> \"stage: '3'\";",
145+
"\"stage: 'a.dvc'\" -> \"stage: '4'\";",
146+
"\"stage: 'b.dvc'\" -> \"stage: '2'\";",
147+
"\"stage: 'b.dvc'\" -> \"stage: '3'\";",
148+
"stage;",
149+
"stage;",
150+
"stage;",
151+
"stage;",
152+
"stage;",
153+
"stage;",
154+
"strict digraph {",
155+
"}",
156+
]
157+
actual = sorted(
158+
line.rstrip() for line in _show_dot(repo.index.graph).splitlines()
153159
)
160+
assert actual == expected
154161

155162

156163
def test_show_mermaid(repo):

0 commit comments

Comments
 (0)