Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import unittest
00035 from qt_dotgraph.pygraphvizfactory import PygraphvizFactory
00036
00037 class PygraphvizFactoryTest(unittest.TestCase):
00038
00039 def test_get_graph(self):
00040 fac = PygraphvizFactory()
00041 g = fac.get_graph()
00042 self.assertEquals('same', g.graph_attr['rank'])
00043 self.assertTrue(g.is_directed())
00044
00045 def test_add_node(self):
00046 fac = PygraphvizFactory()
00047 g = fac.get_graph()
00048 fac.add_node_to_graph(g, 'foo')
00049 self.assertEqual(1, len(g.nodes()))
00050 self.assertEqual('foo', g.nodes()[0].get_name())
00051 self.assertEqual('foo', g.nodes()[0].attr['label'])
00052
00053 def test_add_node_escape_name(self):
00054 fac = PygraphvizFactory()
00055 g = fac.get_graph()
00056 fac.add_node_to_graph(g, 'graph')
00057 self.assertEqual(1, len(g.nodes()))
00058 self.assertEqual('graph', g.nodes()[0].get_name())
00059 self.assertEqual('graph', g.nodes()[0].attr['label'])
00060
00061 def test_add_edge(self):
00062 fac = PygraphvizFactory()
00063 g = fac.get_graph()
00064 fac.add_node_to_graph(g, 'foo')
00065 fac.add_node_to_graph(g, 'bar')
00066 fac.add_edge_to_graph(g, 'foo', 'bar')
00067 self.assertEqual(2, len(g.nodes()))
00068 self.assertEqual(1, len(g.edges()))
00069 self.assertEqual('foo', g.edges()[0][0])
00070 self.assertEqual('bar', g.edges()[0][1])
00071
00072 def test_add_subgraph(self):
00073 fac = PygraphvizFactory()
00074 g = fac.get_graph()
00075 fac.add_subgraph_to_graph(g, 'foo')
00076 self.assertEqual(1, len(g.subgraphs()))
00077 self.assertEqual('cluster_foo', g.subgraphs()[0].get_name())
00078 self.assertEqual('foo', g.subgraphs()[0].graph_attr['label'])
00079
00080 def test_add_subgraph_escape_name(self):
00081 fac = PygraphvizFactory()
00082 g = fac.get_graph()
00083 fac.add_subgraph_to_graph(g, 'graph')
00084 self.assertEqual(1, len(g.subgraphs()))
00085 self.assertEqual('cluster_graph', g.subgraphs()[0].get_name())
00086 self.assertEqual('graph', g.subgraphs()[0].graph_attr['label'])
00087
00088 def test_create_dot(self):
00089 fac = PygraphvizFactory()
00090 g = fac.get_graph()
00091 fac.add_node_to_graph(g, 'foo')
00092 fac.add_node_to_graph(g, 'edge')
00093 fac.add_edge_to_graph(g, 'foo', 'edge')
00094 fac.add_subgraph_to_graph(g, 'graph')
00095 snippets = ['strict digraph {\n\tgraph',
00096 'foo',
00097 'label=foo',
00098 '"edge"',
00099 'label="edge"',
00100 'foo -> "edge"']
00101 result = fac.create_dot(g)
00102 for sn in snippets:
00103 self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))