summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2016-03-25 10:36:01 -0700
committerJoshua Harlow <harlowja@gmail.com>2016-05-20 22:29:12 -0700
commit8c2d73bc23fb377f6640494770efa115907d228e (patch)
treee5e01f70a60ddbd672c6307cd7382a0f66a061de
parent720ee3792dc45f514d82108f217bb99e538ef98b (diff)
downloadtaskflow-8c2d73bc23fb377f6640494770efa115907d228e.tar.gz
Add a simple sanity test for pydot outputting
Depends-On: Ia633ccd1dca94f70b05ae4376a1c3a3f252a9923 Related-Bug: #1561656 Change-Id: I930a1ee9c1d17a12328d920bbe02ea0b77947295
-rw-r--r--taskflow/tests/unit/test_types.py23
-rw-r--r--taskflow/types/graph.py18
-rw-r--r--test-requirements.txt3
3 files changed, 41 insertions, 3 deletions
diff --git a/taskflow/tests/unit/test_types.py b/taskflow/tests/unit/test_types.py
index b676719..8a9e316 100644
--- a/taskflow/tests/unit/test_types.py
+++ b/taskflow/tests/unit/test_types.py
@@ -98,6 +98,29 @@ class GraphTest(test.TestCase):
g3 = graph.merge_graphs(g, g2)
self.assertEqual(3, len(g3))
+ def test_pydot_output(self):
+ # NOTE(harlowja): ensure we use the ordered types here, otherwise
+ # the expected output will vary based on randomized hashing and then
+ # the test will fail randomly...
+ for graph_cls, kind, edge in [(graph.OrderedDiGraph, 'digraph', '->'),
+ (graph.OrderedGraph, 'graph', '--')]:
+ g = graph_cls(name='test')
+ g.add_node("a")
+ g.add_node("b")
+ g.add_node("c")
+ g.add_edge("a", "b")
+ g.add_edge("b", "c")
+ expected = """
+strict %(kind)s "test" {
+a;
+b;
+c;
+a %(edge)s b;
+b %(edge)s c;
+}
+""" % ({'kind': kind, 'edge': edge})
+ self.assertEqual(expected.lstrip(), g.export_to_dot())
+
def test_merge_edges(self):
g = graph.DiGraph()
g.add_node("a")
diff --git a/taskflow/types/graph.py b/taskflow/types/graph.py
index 4bd1e60..aebbf7b 100644
--- a/taskflow/types/graph.py
+++ b/taskflow/types/graph.py
@@ -115,7 +115,7 @@ class DiGraph(nx.DiGraph):
def export_to_dot(self):
"""Exports the graph to a dot format (requires pydot library)."""
- return nx.to_pydot(self).to_string()
+ return nx_pydot.to_pydot(self).to_string()
def is_directed_acyclic(self):
"""Returns if this graph is a DAG or not."""
@@ -157,8 +157,20 @@ class DiGraph(nx.DiGraph):
class OrderedDiGraph(DiGraph):
"""A directed graph subclass with useful utility functions.
- This derivative retains node, edge, insertation and iteration
- ordering (so that the iteration order matches the insertation
+ This derivative retains node, edge, insertion and iteration
+ ordering (so that the iteration order matches the insertion
+ order).
+ """
+ node_dict_factory = collections.OrderedDict
+ adjlist_dict_factory = collections.OrderedDict
+ edge_attr_dict_factory = collections.OrderedDict
+
+
+class OrderedGraph(Graph):
+ """A graph subclass with useful utility functions.
+
+ This derivative retains node, edge, insertion and iteration
+ ordering (so that the iteration order matches the insertion
order).
"""
node_dict_factory = collections.OrderedDict
diff --git a/test-requirements.txt b/test-requirements.txt
index 10eeba7..10078b3 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -21,6 +21,9 @@ kazoo>=2.2 # Apache-2.0
# Used for testing redis jobboards
redis>=2.10.0 # MIT
+# Used for making sure pydot is still working
+pydotplus>=2.0.2 # MIT License
+
# Used for testing database persistence backends.
SQLAlchemy<1.1.0,>=1.0.10 # MIT
alembic>=0.8.0 # MIT