diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-05-31 00:13:58 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-05-31 00:13:58 +0000 |
commit | 8d1fb6fe1659494a48b16a184f11590ad459ed76 (patch) | |
tree | 6eeba141a01749cf0c3de19a02444dafc9b4682d | |
parent | 459b0a2c6a546d190f26de966f247d9e200b9d5c (diff) | |
parent | 8c2d73bc23fb377f6640494770efa115907d228e (diff) | |
download | taskflow-8d1fb6fe1659494a48b16a184f11590ad459ed76.tar.gz |
Merge "Add a simple sanity test for pydot outputting"
-rw-r--r-- | taskflow/tests/unit/test_types.py | 23 | ||||
-rw-r--r-- | taskflow/types/graph.py | 18 | ||||
-rw-r--r-- | test-requirements.txt | 3 |
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 8f676d7..e57fda1 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.4 # MIT |