test_master_api.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, 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 ## Integration test for empty services to test serializers
35 ## and transport
36 
37 PKG='test_rosmaster'
38 NAME = 'test_master'
39 
40 import sys
41 import unittest
42 
43 import rospy
44 
45 from master import MasterApiTestCase, set_node_name
46 
47 # Due to the need to have a fresh master for each of these test cases,
48 # we have to go through the pain of exposing each of the test cases one-by-one
49 
50 class MasterSimpleApi(MasterApiTestCase):
51  def testGetPid(self):
52  self._testGetPid()
53  def testGetUri(self):
54  self._testGetUri()
55 
56 class MasterRegisterServiceSuccess(MasterApiTestCase):
58  self._testRegisterServiceSuccess()
59 
60 class MasterRegisterPublisherSuccess(MasterApiTestCase):
62  self._testRegisterPublisherSuccess()
63 class MasterRegisterPublisherTypes(MasterApiTestCase):
64  ## #591: this test may change if we make registering '*' unsupported
66  self._testRegisterPublisherTypes()
67 
68 class MasterRegisterSubscriberSimpleSuccess(MasterApiTestCase):
70  self._testRegisterSubscriberSimpleSuccess()
71 
72 
73 class MasterUnregisterServiceSuccess(MasterApiTestCase):
75  self._testUnregisterServiceSuccess()
76 
77 class MasterUnregisterPublisherSuccess(MasterApiTestCase):
79  self._testUnregisterPublisherSuccess()
80 
81 class MasterUnregisterSubscriberSuccess(MasterApiTestCase):
83  self._testUnregisterSubscriberSuccess()
84 
85 class MasterRegisterServiceInvalid(MasterApiTestCase):
87  self._testRegisterServiceInvalid()
88 
89 class MasterRegisterPublisherInvalid(MasterApiTestCase):
91  self._testRegisterPublisherInvalid()
92 
93 class MasterRegisterSubscriberInvalid(MasterApiTestCase):
95  self._testRegisterSubscriberInvalid()
96 
97 
98 class MasterUnregisterServiceInvalid(MasterApiTestCase):
100  self._testUnregisterServiceInvalid()
101 
102 class MasterUnregisterPublisherInvalid(MasterApiTestCase):
104  self._testUnregisterPublisherInvalid()
105 
106 class MasterUnregisterSubscriberInvalid(MasterApiTestCase):
108  self._testUnregisterSubscriberInvalid()
109 
110 
111 
112 if __name__ == '__main__':
113  # this is terribly complicated on the account that we want a fresh master for each test, so we cannot
114  # run all the tests as a single test node. instead, we have to have a separate test node per test.
115 
116  import optparse
117  from optparse import OptionParser
118  parser = OptionParser(usage="usage: %prog [options] topic", prog=NAME)
119 
120  # have to redeclare --text/--cov options, which are standard rostest options
121  parser.add_option("--text",dest="text_ignore", default=False,
122  action="store_true", help="rostest standard option")
123  parser.add_option("--cov",dest="cov_ignore", default=False,
124  action="store_true", help="rostest standard option")
125 
126  parser.add_option("--simple",dest="simple", default=False,
127  action="store_true", help="MasterSimpleApi")
128 
129  parser.add_option("--gtest_output",dest="gtest_output", default='',
130  help="xml output file")
131 
132  parser.add_option("--regsrvsuccess", dest="regsrvsuccess", default=False,
133  action="store_true", help="MasterRegisterServiceSuccess")
134  parser.add_option("--regpubsuccess", dest="regpubsuccess", default=False,
135  action="store_true", help="MasterRegisterPublisherSuccess")
136  parser.add_option("--regpubtypes", dest="regpubtypes", default=False,
137  action="store_true", help="MasterRegisterPublisherTypes")
138  parser.add_option("--regsubsimplesuccess", dest="regsubsimplesuccess", default=False,
139  action="store_true", help="MasterRegisterSubscriberSimpleSuccess")
140 
141 
142  parser.add_option("--unregsrvsuccess", dest="unregsrvsuccess", default=False,
143  action="store_true", help="MasterUnregisterServiceSuccess")
144  parser.add_option("--unregpubsuccess", dest="unregpubsuccess", default=False,
145  action="store_true", help="MasterUnregisterPublisherSuccess")
146  parser.add_option("--unregsubsuccess", dest="unregsubsuccess", default=False,
147  action="store_true", help="MasterUnregisterSubscriberSuccess")
148 
149  parser.add_option("--regsrvinvalid", dest="regsrvinvalid", default=False,
150  action="store_true", help="MasterRegisterServiceInvalid")
151  parser.add_option("--regsubinvalid", dest="regsubinvalid", default=False,
152  action="store_true", help="MasterRegisterSubscriberInvalid")
153  parser.add_option("--regpubinvalid", dest="regpubinvalid", default=False,
154  action="store_true", help="MasterRegisterPublisherInvalid")
155 
156  parser.add_option("--unregsrvinvalid", dest="unregsrvinvalid", default=False,
157  action="store_true", help="MasterUnregisterServiceInvalid")
158  parser.add_option("--unregsubinvalid", dest="unregsubinvalid", default=False,
159  action="store_true", help="MasterUnregisterSubscriberInvalid")
160  parser.add_option("--unregpubinvalid", dest="unregpubinvalid", default=False,
161  action="store_true", help="MasterUnregisterPublisherInvalid")
162 
163 
164  (options, args) = parser.parse_args()
165  if options.simple:
166  cls = MasterSimpleApi
167 
168  elif options.regsrvsuccess:
169  cls = MasterRegisterServiceSuccess
170  elif options.regpubsuccess:
171  cls = MasterRegisterPublisherSuccess
172  elif options.regpubtypes:
173  cls = MasterRegisterPublisherTypes
174  elif options.regsubsimplesuccess:
175  cls = MasterRegisterSubscriberSimpleSuccess
176 
177  elif options.unregsrvsuccess:
178  cls = MasterUnregisterServiceSuccess
179  elif options.unregpubsuccess:
180  cls = MasterUnregisterPublisherSuccess
181  elif options.unregsubsuccess:
182  cls = MasterUnregisterSubscriberSuccess
183 
184  elif options.regsrvinvalid:
185  cls = MasterRegisterServiceInvalid
186  elif options.regpubinvalid:
187  cls = MasterRegisterPublisherInvalid
188  elif options.regsubinvalid:
189  cls = MasterRegisterSubscriberInvalid
190 
191  elif options.unregsrvinvalid:
192  cls = MasterUnregisterServiceInvalid
193  elif options.unregpubinvalid:
194  cls = MasterUnregisterPublisherInvalid
195  elif options.unregsubinvalid:
196  cls = MasterUnregisterSubscriberInvalid
197 
198  if not cls:
199  parser.error("you must specify a test to run with an [options] flag")
200 
201  set_node_name(NAME)
202  rospy.init_node(NAME, disable_rostime=True)
203  import rostest
204  rostest.rosrun(PKG, NAME, cls, sys.argv)
def set_node_name(name)
set_node_name() must be called prior to the unit test so that the test harness knows its ROS name...
Definition: master.py:54
def testRegisterPublisherTypes(self)
#591: this test may change if we make registering '*' unsupported


test_rosmaster
Author(s): Ken Conley
autogenerated on Sun Feb 3 2019 03:30:20