pydot_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.pydotfactory import PydotFactory
00036 
00037 class PyDotFactoryTest(unittest.TestCase):
00038 
00039     def test_get_graph(self):
00040         fac = PydotFactory()
00041         g = fac.get_graph()
00042         self.assertEquals('same', g.get_rank())
00043         self.assertEquals('digraph', g.get_graph_type())
00044 
00045     def test_add_node(self):
00046         fac = PydotFactory()
00047         g = fac.get_graph()
00048         fac.add_node_to_graph(g, 'foo')
00049         self.assertEqual(1, len(g.get_nodes()))
00050         self.assertEqual('foo', g.get_nodes()[0].get_name())
00051         self.assertEqual('foo', g.get_nodes()[0].get_label())
00052 
00053     def test_add_node_escape_name(self):
00054         fac = PydotFactory()
00055         g = fac.get_graph()
00056         fac.add_node_to_graph(g, 'graph')
00057         self.assertEqual(1, len(g.get_nodes()))
00058         self.assertEqual('graph_', g.get_nodes()[0].get_name())
00059         self.assertEqual('graph_', g.get_nodes()[0].get_label())
00060         
00061     def test_add_edge(self):
00062         fac = PydotFactory()
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.get_nodes()))
00068         self.assertEqual(1, len(g.get_edges()))
00069         self.assertEqual('foo', g.get_edges()[0].get_source())
00070         self.assertEqual('bar', g.get_edges()[0].get_destination())
00071 
00072     def test_add_subgraph(self):
00073         fac = PydotFactory()
00074         g = fac.get_graph()
00075         fac.add_subgraph_to_graph(g, 'foo')
00076         self.assertEqual(1, len(g.get_subgraph_list()))
00077         self.assertEqual('cluster_foo', g.get_subgraph_list()[0].get_name())
00078         self.assertEqual('foo', g.get_subgraph_list()[0].get_label())
00079 
00080     def test_add_subgraph_escape_name(self):
00081         fac = PydotFactory()
00082         g = fac.get_graph()
00083         fac.add_subgraph_to_graph(g, 'graph')
00084         self.assertEqual(1, len(g.get_subgraph_list()))
00085         self.assertEqual('cluster_graph_', g.get_subgraph_list()[0].get_name())
00086         self.assertEqual('graph_', g.get_subgraph_list()[0].get_label())
00087 
00088     def test_create_dot(self):
00089         fac = PydotFactory()
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, 'foo')
00095         snippets = ['digraph graphname {\n\tgraph [rankdir=TB, rank=same];\n\tnode [label="\\N"];\n\tgraph [bb="', '"];\n\tsubgraph cluster_foo {\n\t\tgraph [',
00096                     '];\n\t}\n\tfoo [label=foo, shape=box, pos="',
00097                     'edge_ [label=edge_, shape=box, pos="',
00098                     'foo -> edge_',
00099                     '"];\n}\n']
00100         result = fac.create_dot(g)
00101         for sn in snippets:
00102             self.assertTrue(sn in result, '%s \nmissing in\n %s' % (sn, result))


qt_dotgraph
Author(s): Thibault Kruse
autogenerated on Mon Oct 6 2014 03:57:59