pygraphviz_factory_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2009, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage, Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 import unittest
35 from qt_dotgraph.pygraphvizfactory import PygraphvizFactory
36 
37 
38 class PygraphvizFactoryTest(unittest.TestCase):
39 
40  def test_get_graph(self):
41  fac = PygraphvizFactory()
42  g = fac.get_graph()
43  self.assertEquals('same', g.graph_attr['rank'])
44  self.assertTrue(g.is_directed())
45 
46  def test_add_node(self):
47  fac = PygraphvizFactory()
48  g = fac.get_graph()
49  fac.add_node_to_graph(g, 'foo')
50  self.assertEqual(1, len(g.nodes()))
51  self.assertEqual('foo', g.nodes()[0].get_name())
52  self.assertEqual('foo', g.nodes()[0].attr['label'])
53 
55  fac = PygraphvizFactory()
56  g = fac.get_graph()
57  fac.add_node_to_graph(g, 'graph')
58  self.assertEqual(1, len(g.nodes()))
59  self.assertEqual('graph', g.nodes()[0].get_name())
60  self.assertEqual('graph', g.nodes()[0].attr['label'])
61 
62  def test_add_edge(self):
63  fac = PygraphvizFactory()
64  g = fac.get_graph()
65  fac.add_node_to_graph(g, 'foo')
66  fac.add_node_to_graph(g, 'bar')
67  fac.add_edge_to_graph(g, 'foo', 'bar')
68  self.assertEqual(2, len(g.nodes()))
69  self.assertEqual(1, len(g.edges()))
70  self.assertEqual('foo', g.edges()[0][0])
71  self.assertEqual('bar', g.edges()[0][1])
72 
73  def test_add_subgraph(self):
74  fac = PygraphvizFactory()
75  g = fac.get_graph()
76  fac.add_subgraph_to_graph(g, 'foo')
77  self.assertEqual(1, len(g.subgraphs()))
78  self.assertEqual('cluster_foo', g.subgraphs()[0].get_name())
79  self.assertEqual('foo', g.subgraphs()[0].graph_attr['label'])
80 
82  fac = PygraphvizFactory()
83  g = fac.get_graph()
84  fac.add_subgraph_to_graph(g, 'graph')
85  self.assertEqual(1, len(g.subgraphs()))
86  self.assertEqual('cluster_graph', g.subgraphs()[0].get_name())
87  self.assertEqual('graph', g.subgraphs()[0].graph_attr['label'])
88 
89  def test_create_dot(self):
90  fac = PygraphvizFactory()
91  g = fac.get_graph()
92  fac.add_node_to_graph(g, 'foo')
93  fac.add_node_to_graph(g, 'edge')
94  fac.add_edge_to_graph(g, 'foo', 'edge')
95  fac.add_subgraph_to_graph(g, 'graph')
96  snippets = ['strict digraph {\n\tgraph',
97  'foo',
98  'label=foo',
99  '"edge"',
100  'label="edge"',
101  'foo -> "edge"']
102  result = fac.create_dot(g)
103  for sn in snippets:
104  self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))


qt_dotgraph
Author(s): Thibault Kruse
autogenerated on Thu Jun 6 2019 19:54:25