pygraphviz_factory_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2009, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
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))


qt_dotgraph
Author(s): Thibault Kruse
autogenerated on Fri Aug 28 2015 12:15:47