test_lazy.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ###############################################################################
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2016, JSK Lab, University of Tokyo.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/o2r other materials provided
17 # with the distribution.
18 # * Neither the name of the JSK Lab nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 ###############################################################################
35 
36 __author__ = 'Kentaro Wada <www.kentaro.wada@gmail.com>'
37 
38 import os
39 import sys
40 
41 import unittest
42 
43 import rosgraph
44 import rospy
45 import rosmsg
46 import roslib
47 
48 
49 PKG = 'test_nodelet_topic_tools'
50 NAME = 'test_lazy'
51 
52 
53 class TestConnection(unittest.TestCase):
54 
55  def __init__(self, *args):
56  super(TestConnection, self).__init__(*args)
57  rospy.init_node(NAME)
58  self.master = rosgraph.Master(NAME)
59 
61  check_connected_topics = rospy.get_param('~check_connected_topics')
62  # Check assumed topics are not there
63  _, subscriptions, _ = self.master.getSystemState()
64  for check_topic in check_connected_topics:
65  for topic, sub_node in subscriptions:
66  if topic == rospy.get_namespace() + check_topic:
67  raise ValueError('Found topic: {}'.format(check_topic))
68 
70  topic_type = rospy.get_param('~input_topic_type')
71  check_connected_topics = rospy.get_param('~check_connected_topics')
72  wait_time = rospy.get_param('~wait_for_connection', 0)
73  msg_class = roslib.message.get_message_class(topic_type)
74  # Subscribe topic and bond connection
75  sub = rospy.Subscriber('~input', msg_class,
77  print('Waiting for connection for {} sec.'.format(wait_time))
78  rospy.sleep(wait_time)
79  # Check assumed topics are there
80  _, subscriptions, _ = self.master.getSystemState()
81  for check_topic in check_connected_topics:
82  for topic, sub_node in subscriptions:
83  if topic == rospy.get_namespace() + check_topic:
84  break
85  else:
86  raise ValueError('Not found topic: {}'.format(check_topic))
87 
88  sub.unregister()
89  rospy.sleep(1) # wait for disconnection
90 
91  # Check specified topics do not exist
92  _, subscriptions, _ = self.master.getSystemState()
93  for check_topic in check_connected_topics:
94  for topic, sub_node in subscriptions:
95  if topic == rospy.get_namespace() + check_topic:
96  raise ValueError('Found topic: {}'.format(check_topic))
97 
99  pass
100 
101 
102 if __name__ == "__main__":
103  import rostest
104  rostest.rosrun(PKG, NAME, TestConnection)
def __init__(self, args)
Definition: test_lazy.py:55
def _cb_test_subscriber_appears(self, msg)
Definition: test_lazy.py:98
def test_subscriber_appears(self)
Definition: test_lazy.py:69
def test_no_subscribers(self)
Definition: test_lazy.py:60


test_nodelet_topic_tools
Author(s): Radu Bogdan Rusu, Tully Foote
autogenerated on Sat Jul 18 2020 03:17:59