From 3faf413288c8f6f24462ea1d34bd069b57d8b383 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Wed, 11 May 2022 16:34:53 +0530 Subject: [PATCH] Use sorted output in test since order is not deterministic. Co-authored-by: David de la Iglesia Castro --- dvc/commands/dag.py | 3 +-- tests/unit/command/test_dag.py | 37 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/dvc/commands/dag.py b/dvc/commands/dag.py index 585e870ca..bbf4ac2fa 100644 --- a/dvc/commands/dag.py +++ b/dvc/commands/dag.py @@ -23,9 +23,8 @@ def _show_dot(G): from networkx.drawing.nx_pydot import write_dot - G = G.reverse() dot_file = io.StringIO() - write_dot(G, dot_file) + write_dot(G.reverse(), dot_file) return dot_file.getvalue() diff --git a/tests/unit/command/test_dag.py b/tests/unit/command/test_dag.py index d5ea26a23..3e3a8daca 100644 --- a/tests/unit/command/test_dag.py +++ b/tests/unit/command/test_dag.py @@ -135,22 +135,29 @@ def test_show_ascii(repo): def test_show_dot(repo): - assert _show_dot(repo.index.graph) == ( - "strict digraph {\n" - "stage;\n" - "stage;\n" - "stage;\n" - "stage;\n" - "stage;\n" - "stage;\n" - "\"stage: 'b.dvc'\" -> \"stage: '2'\";\n" - "\"stage: 'b.dvc'\" -> \"stage: '3'\";\n" - "\"stage: 'a.dvc'\" -> \"stage: '1'\";\n" - "\"stage: 'a.dvc'\" -> \"stage: '3'\";\n" - "\"stage: 'a.dvc'\" -> \"stage: '4'\";\n" - "\"stage: '3'\" -> \"stage: '4'\";\n" - "}\n" + # dot file rendering is not deterministic though graph + # output doesn't depend upon order of lines. Use sorted values + # https://github.com/iterative/dvc/pull/7725 + expected = [ + "\"stage: '3'\" -> \"stage: '4'\";", + "\"stage: 'a.dvc'\" -> \"stage: '1'\";", + "\"stage: 'a.dvc'\" -> \"stage: '3'\";", + "\"stage: 'a.dvc'\" -> \"stage: '4'\";", + "\"stage: 'b.dvc'\" -> \"stage: '2'\";", + "\"stage: 'b.dvc'\" -> \"stage: '3'\";", + "stage;", + "stage;", + "stage;", + "stage;", + "stage;", + "stage;", + "strict digraph {", + "}", + ] + actual = sorted( + line.rstrip() for line in _show_dot(repo.index.graph).splitlines() ) + assert actual == expected def test_show_mermaid(repo):