test_rqt_plugins.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import unittest
5 
6 import rosgraph
7 import rospy
8 import rosunit
9 # from sensor_msgs.msg import Image
10 from std_msgs.msg import Bool
11 from std_msgs.msg import Float32
12 # from std_msgs.msg import String
13 from std_msgs.msg import Time
14 # from std_msgs.msg import UInt8
15 
16 from jsk_recognition_msgs.msg import HistogramWithRange
17 from jsk_recognition_msgs.msg import PlotData
18 
19 NAME = "test_rqt_plugins"
20 WAIT_TIMEOUT = 10.0 # sec
21 
22 
23 class TestRqtPlugins(unittest.TestCase):
24 
25  def __init__(self, *args):
26  unittest.TestCase.__init__(self, *args)
27  rospy.init_node(NAME)
28 
29  def is_subscribed(self, topic_name, topic_type, sub_node_name):
30  try:
31  rospy.wait_for_message(topic_name, topic_type, WAIT_TIMEOUT)
32  except rospy.ROSException:
33  self.assertTrue(
34  False, 'Could not subscribe topic ({}) in {} seconds'.
35  format(topic_name, WAIT_TIMEOUT))
36  subs = []
37  i = 0
38  while subs == [] and i < 10:
39  pubs, subs, _ = rosgraph.Master('/rostopic').getSystemState()
40  subs = [x[1] for x in subs if x[0] == topic_name]
41  rospy.sleep(1.0)
42  i = i + 1
43  if subs == []:
44  self.assertTrue(
45  False, 'No node subscribes topic ({})'.format(topic_name))
46  if sub_node_name not in subs[0]:
47  self.assertTrue(
48  False, 'Node ({}) does not subscribe topic ({}), but {} does'.
49  format(sub_node_name, topic_name, subs))
50  return True
51 
52  def test_rqt_2d_plot(self):
53  self.assertTrue(
54  self.is_subscribed(
55  '/pub_sample_2d_data/output', PlotData, '/rqt_2d_plot'))
56 
57  def test_rqt_3d_plot(self):
58  self.assertTrue(
59  self.is_subscribed(
60  '/pub_sample_3d_data/output1', Float32, '/rqt_3d_plot'))
61 
63  self.assertTrue(
64  self.is_subscribed('/drc_2015_environment/is_disabled', Bool,
65  '/rqt_drc_mini_maxwell'))
66  self.assertTrue(
67  self.is_subscribed('/drc_2015_environment/is_blackout', Bool,
68  '/rqt_drc_mini_maxwell'))
69  self.assertTrue(
70  self.is_subscribed(
71  '/drc_2015_environment/next_whiteout_time', Time,
72  '/rqt_drc_mini_maxwell'))
73 
75  self.assertTrue(
76  self.is_subscribed('/range_array', HistogramWithRange,
77  '/rqt_histogram_plot'))
78 
80  # FIXME: Load settings to read topic: /pub_sample_image/image_raw
81  # in default.
82  # self.assertTrue(
83  # self.is_subscribed('/pub_sample_image/image_raw/marked', Image,
84  # '/rqt_image_view2'))
85  pass
86 
88  # FIXME: Add some test here
89  pass
90 
92  # FIXME: Load settings to read topic: /sample_status in default.
93  # self.assertTrue(
94  # self.is_subscribed('/sample_status', UInt8, '/rqt_status_light'))
95  pass
96 
98  # FIXME: Load settings to read topic: /sample_string in default.
99  # self.assertTrue(
100  # self.is_subscribed('/sample_string', String,
101  # '/rqt_string_label'))
102  pass
103 
104  def test_rqt_yn_btn(self):
105  try:
106  rospy.wait_for_service('rqt_yn_btn', WAIT_TIMEOUT)
107  self.assertTrue(True)
108  except rospy.ROSException:
109  self.assertTrue(False, 'Could not find service (rqt_yn_btn)')
110 
111 
112 if __name__ == '__main__':
113  rosunit.unitrun(NAME, sys.argv[0], TestRqtPlugins)
def is_subscribed(self, topic_name, topic_type, sub_node_name)


jsk_rqt_plugins
Author(s):
autogenerated on Fri Feb 5 2021 04:03:20