Add a simple sanity test for pydot outputting
Depends-On: Ia633ccd1dca94f70b05ae4376a1c3a3f252a9923 Related-Bug: #1561656 Change-Id: I930a1ee9c1d17a12328d920bbe02ea0b77947295
This commit is contained in:
@@ -98,6 +98,29 @@ class GraphTest(test.TestCase):
|
|||||||
g3 = graph.merge_graphs(g, g2)
|
g3 = graph.merge_graphs(g, g2)
|
||||||
self.assertEqual(3, len(g3))
|
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):
|
def test_merge_edges(self):
|
||||||
g = graph.DiGraph()
|
g = graph.DiGraph()
|
||||||
g.add_node("a")
|
g.add_node("a")
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class DiGraph(nx.DiGraph):
|
|||||||
|
|
||||||
def export_to_dot(self):
|
def export_to_dot(self):
|
||||||
"""Exports the graph to a dot format (requires pydot library)."""
|
"""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):
|
def is_directed_acyclic(self):
|
||||||
"""Returns if this graph is a DAG or not."""
|
"""Returns if this graph is a DAG or not."""
|
||||||
@@ -157,8 +157,20 @@ class DiGraph(nx.DiGraph):
|
|||||||
class OrderedDiGraph(DiGraph):
|
class OrderedDiGraph(DiGraph):
|
||||||
"""A directed graph subclass with useful utility functions.
|
"""A directed graph subclass with useful utility functions.
|
||||||
|
|
||||||
This derivative retains node, edge, insertation and iteration
|
This derivative retains node, edge, insertion and iteration
|
||||||
ordering (so that the iteration order matches the insertation
|
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).
|
order).
|
||||||
"""
|
"""
|
||||||
node_dict_factory = collections.OrderedDict
|
node_dict_factory = collections.OrderedDict
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ kazoo>=2.2 # Apache-2.0
|
|||||||
# Used for testing redis jobboards
|
# Used for testing redis jobboards
|
||||||
redis>=2.10.0 # MIT
|
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.
|
# Used for testing database persistence backends.
|
||||||
SQLAlchemy<1.1.0,>=1.0.10 # MIT
|
SQLAlchemy<1.1.0,>=1.0.10 # MIT
|
||||||
alembic>=0.8.0 # MIT
|
alembic>=0.8.0 # MIT
|
||||||
|
|||||||
Reference in New Issue
Block a user