pydot_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.pydotfactory import PydotFactory
36 
37 
38 class PyDotFactoryTest(unittest.TestCase):
39 
40  def test_get_graph(self):
41  fac = PydotFactory()
42  g = fac.get_graph()
43  self.assertEquals('same', g.get_rank())
44  self.assertEquals('digraph', g.get_graph_type())
45 
46  def test_add_node(self):
47  fac = PydotFactory()
48  g = fac.get_graph()
49  fac.add_node_to_graph(g, 'foo')
50  self.assertEqual(1, len(g.get_nodes()))
51  self.assertEqual('foo', g.get_nodes()[0].get_name())
52  self.assertEqual('foo', g.get_nodes()[0].get_label())
53 
55  fac = PydotFactory()
56  g = fac.get_graph()
57  fac.add_node_to_graph(g, 'graph')
58  self.assertEqual(1, len(g.get_nodes()))
59  self.assertEqual('graph_', g.get_nodes()[0].get_name())
60  self.assertEqual('graph_', g.get_nodes()[0].get_label())
61 
62  def test_add_edge(self):
63  fac = PydotFactory()
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.get_nodes()))
69  self.assertEqual(1, len(g.get_edges()))
70  self.assertEqual('foo', g.get_edges()[0].get_source())
71  self.assertEqual('bar', g.get_edges()[0].get_destination())
72 
73  def test_add_subgraph(self):
74  fac = PydotFactory()
75  g = fac.get_graph()
76  fac.add_subgraph_to_graph(g, 'foo')
77  self.assertEqual(1, len(g.get_subgraph_list()))
78  self.assertEqual('cluster_foo', g.get_subgraph_list()[0].get_name())
79  self.assertEqual('foo', g.get_subgraph_list()[0].get_label())
80 
82  fac = PydotFactory()
83  g = fac.get_graph()
84  fac.add_subgraph_to_graph(g, 'graph')
85  self.assertEqual(1, len(g.get_subgraph_list()))
86  self.assertEqual('cluster_graph_', g.get_subgraph_list()[0].get_name())
87  self.assertEqual('graph_', g.get_subgraph_list()[0].get_label())
88 
89  def test_create_dot(self):
90  fac = PydotFactory()
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, 'foo')
96  snippets = ['digraph graphname {\n\tgraph [',
97  'rankdir=TB',
98  'compound=True',
99  'rank=same',
100  'node [label="\\N"]',
101  'subgraph cluster_foo {\n\t\tgraph [',
102  'foo\t [',
103  'label=foo',
104  'shape=box',
105  'pos="',
106  'edge_\t [',
107  'label=edge_',
108  'foo -> edge_\t [',
109  '"];\n}\n']
110  result = fac.create_dot(g)
111  for sn in snippets:
112  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