dotcode_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 import rospkg
36 
37 import os
38 from rqt_graph.dotcode import RosGraphDotcodeGenerator
39 
40 PKG = 'rqt_graph'
41 
42 
43 class DotcodeTest(unittest.TestCase):
44 
47  inc, exc = gen._split_filter_string('')
48  self.assertEqual(['.*'], inc)
49  self.assertEqual(0, len(exc))
50  inc, exc = gen._split_filter_string('/')
51  self.assertEqual(['.*'], inc)
52  self.assertEqual(0, len(exc))
53 
56  inc, exc = gen._split_filter_string('foo')
57  self.assertEqual(['foo'], inc)
58  self.assertEqual(0, len(exc))
59  inc, exc = gen._split_filter_string('foo,bar')
60  self.assertEqual(['foo', 'bar'], inc)
61  self.assertEqual(0, len(exc))
62 
65  inc, exc = gen._split_filter_string('-foo')
66  self.assertEqual(['.*'], inc)
67  self.assertEqual(['foo'], exc)
68  inc, exc = gen._split_filter_string('-foo,-bar')
69  self.assertEqual(['.*'], inc)
70  self.assertEqual(['foo', 'bar'], exc)
71 
74  inc, exc = gen._split_filter_string('-foo , bar ,baz, -bam')
75  self.assertEqual(['bar', 'baz'], inc)
76  self.assertEqual(['foo', 'bam'], exc)
77 
78  class MockEdge():
79 
80  def __init__(self, start, end):
81  self.start = start
82  self.end = end
83 
86  e1 = self.MockEdge('foo', 'bar')
87  nmap = gen._get_node_edge_map([e1])
88  self.assertEqual(2, len(nmap))
89  self.assertTrue('foo' in nmap)
90  self.assertTrue('bar' in nmap)
91  self.assertEqual([], nmap['foo'].incoming)
92  self.assertEqual([e1], nmap['foo'].outgoing)
93  self.assertEqual([e1], nmap['bar'].incoming)
94  self.assertEqual([], nmap['bar'].outgoing)
95 
98  e1 = self.MockEdge('foo', 'bar')
99  e2 = self.MockEdge('bar', 'foo')
100  e3 = self.MockEdge('foo', 'pam')
101  nmap = gen._get_node_edge_map([e1, e2, e3])
102  self.assertEqual(3, len(nmap))
103  self.assertTrue('foo' in nmap)
104  self.assertTrue('bar' in nmap)
105  self.assertTrue('pam' in nmap)
106  self.assertEqual([e2], nmap['foo'].incoming)
107  self.assertEqual([e1, e3], nmap['foo'].outgoing)
108  self.assertEqual([e1], nmap['bar'].incoming)
109  self.assertEqual([e2], nmap['bar'].outgoing)
110 
113  topic_nodes = ['foo', 'bar', 'pam', 'boo']
114  e1 = self.MockEdge('n1', 'foo')
115  e2 = self.MockEdge('n2', 'foo')
116  e3 = self.MockEdge('n3', 'bar')
117  e4 = self.MockEdge('bar', 'n4')
118  e5 = self.MockEdge('n5', 'pam')
119  e6 = self.MockEdge('boo', 'n6')
120  edges = [e1, e2, e3, e4, e5, e6]
121  node_connections = gen._get_node_edge_map(edges)
122  print(node_connections)
123  hide_single_connection_topics = True
124  hide_dead_end_topics = False
125  rnodes, redges = gen._filter_leaf_topics(topic_nodes,
126  edges,
127  node_connections,
128  hide_single_connection_topics,
129  hide_dead_end_topics
130  )
131  self.assertEqual(['foo', 'bar'], rnodes)
132  self.assertEqual([e1, e2, e3, e4], redges)
133  self.assertEqual(['foo', 'bar', 'pam', 'boo'], topic_nodes)
134  self.assertEqual([e1, e2, e3, e4, e5, e6], edges)
135 
138  topic_nodes = ['foo', 'bar', 'pam', 'boo']
139  e1 = self.MockEdge('n1', 'foo')
140  e2 = self.MockEdge('n2', 'foo')
141  e3 = self.MockEdge('n3', 'bar')
142  e4 = self.MockEdge('bar', 'n4')
143  e5 = self.MockEdge('n5', 'pam')
144  e6 = self.MockEdge('boo', 'n6')
145  edges = [e1, e2, e3, e4, e5, e6]
146  node_connections = gen._get_node_edge_map(edges)
147  print(node_connections)
148  hide_single_connection_topics = False
149  hide_dead_end_topics = True
150  rnodes, redges = gen._filter_leaf_topics(topic_nodes,
151  edges,
152  node_connections,
153  hide_single_connection_topics,
154  hide_dead_end_topics
155  )
156  self.assertEqual(['bar', 'boo'], rnodes)
157  self.assertEqual([e3, e4, e6], redges)
158  self.assertEqual(['foo', 'bar', 'pam', 'boo'], topic_nodes)
159  self.assertEqual([e1, e2, e3, e4, e5, e6], edges)
160 
163  topic_nodes = ['foo', 'bar', 'pam', 'boo']
164  e1 = self.MockEdge('n1', 'foo')
165  e2 = self.MockEdge('n2', 'foo')
166  e3 = self.MockEdge('n3', 'bar')
167  e4 = self.MockEdge('bar', 'n4')
168  e5 = self.MockEdge('n5', 'pam')
169  e6 = self.MockEdge('boo', 'n6')
170  edges = [e1, e2, e3, e4, e5, e6]
171  node_connections = gen._get_node_edge_map(edges)
172  print(node_connections)
173  hide_single_connection_topics = True
174  hide_dead_end_topics = True
175  rnodes, redges = gen._filter_leaf_topics(topic_nodes,
176  edges,
177  node_connections,
178  hide_single_connection_topics,
179  hide_dead_end_topics
180  )
181  self.assertEqual(['bar'], rnodes)
182  self.assertEqual([e3, e4], redges)
183  self.assertEqual(['foo', 'bar', 'pam', 'boo'], topic_nodes)
184  self.assertEqual([e1, e2, e3, e4, e5, e6], edges)
185 
188  topic_nodes = ['foo/feedback', 'foo/goal', 'foo/cancel', 'foo/result', 'foo/status', 'bar']
189  e1 = self.MockEdge('n1', 'foo/feedback')
190  e2 = self.MockEdge('n1', 'foo/goal')
191  e3 = self.MockEdge('n1', 'foo/cancel')
192  e4 = self.MockEdge('n1', 'foo/result')
193  e5 = self.MockEdge('n1', 'foo/status')
194  e6 = self.MockEdge('n2', 'bar')
195  edges = [e1, e2, e3, e4, e5, e6]
196  node_connections = gen._get_node_edge_map(edges)
197  rnodes, redges, raction_nodes = gen._accumulate_action_topics(
198  topic_nodes, edges, node_connections)
199  self.assertEqual(1, len(rnodes)) # node 'bar'
200  self.assertEqual(1, len(redges))
201  self.assertEqual(1, len(raction_nodes))
202  self.assertEqual(
203  ['foo/feedback', 'foo/goal', 'foo/cancel', 'foo/result', 'foo/status', 'bar'], topic_nodes)
204  self.assertEqual([e1, e2, e3, e4, e5, e6], edges)
205 
206 
207 if __name__ == '__main__':
208  import rosunit
209  rosunit.unitrun(PKG, 'dotcode_test', DotcodeTest)
def test_get_node_edge_map(self)
Definition: dotcode_test.py:84
def __init__(self, start, end)
Definition: dotcode_test.py:80
def test_filter_leaf_topics_both(self)
def test_split_filter_both(self)
Definition: dotcode_test.py:72
def test_filter_leaf_topics_dead_end(self)
def test_get_node_edge_map2(self)
Definition: dotcode_test.py:96
def test_accumulate_action_topics(self)
def test_filter_leaf_topics_single_connection(self)
def test_split_filter_excludes(self)
Definition: dotcode_test.py:63
def test_split_filter_empty(self)
Definition: dotcode_test.py:45
def test_split_filter_includes(self)
Definition: dotcode_test.py:54


rqt_graph
Author(s): Dirk Thomas , Aaron Blasdel
autogenerated on Mon Oct 19 2020 03:41:30