test_master_api.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, 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 ## Integration test for empty services to test serializers
00035 ## and transport
00036 
00037 PKG='test_rosmaster'
00038 NAME = 'test_master'
00039 
00040 import sys
00041 import unittest
00042 
00043 import rospy
00044 
00045 from master import MasterApiTestCase, set_node_name
00046 
00047 # Due to the need to have a fresh master for each of these test cases,
00048 # we have to go through the pain of exposing each of the test cases one-by-one
00049 
00050 class MasterSimpleApi(MasterApiTestCase):
00051     def testGetPid(self):
00052         self._testGetPid()
00053     def testGetUri(self):
00054         self._testGetUri()
00055 
00056 class MasterRegisterServiceSuccess(MasterApiTestCase):
00057     def testRegisterServiceSuccess(self):
00058         self._testRegisterServiceSuccess()
00059         
00060 class MasterRegisterPublisherSuccess(MasterApiTestCase):        
00061     def testRegisterPublisherSuccess(self):
00062         self._testRegisterPublisherSuccess()
00063 class MasterRegisterPublisherTypes(MasterApiTestCase):
00064     ## #591: this test may change if we make registering '*' unsupported
00065     def testRegisterPublisherTypes(self):
00066         self._testRegisterPublisherTypes()
00067 
00068 class MasterRegisterSubscriberSimpleSuccess(MasterApiTestCase):     
00069     def testRegisterSubscriberSimpleSuccess(self):
00070         self._testRegisterSubscriberSimpleSuccess()
00071 
00072 
00073 class MasterUnregisterServiceSuccess(MasterApiTestCase):
00074     def testUnregisterServiceSuccess(self):
00075         self._testUnregisterServiceSuccess()
00076 
00077 class MasterUnregisterPublisherSuccess(MasterApiTestCase):     
00078     def testUnregisterPublisherSuccess(self):
00079         self._testUnregisterPublisherSuccess()
00080 
00081 class MasterUnregisterSubscriberSuccess(MasterApiTestCase):     
00082     def testUnregisterSubscriberSuccess(self):
00083         self._testUnregisterSubscriberSuccess()
00084 
00085 class MasterRegisterServiceInvalid(MasterApiTestCase):
00086     def testRegisterServiceInvalid(self):
00087         self._testRegisterServiceInvalid()
00088 
00089 class MasterRegisterPublisherInvalid(MasterApiTestCase):
00090     def testRegisterPublisherInvalid(self):
00091         self._testRegisterPublisherInvalid()
00092 
00093 class MasterRegisterSubscriberInvalid(MasterApiTestCase):     
00094     def testRegisterSubscriberInvalid(self):
00095         self._testRegisterSubscriberInvalid()
00096 
00097 
00098 class MasterUnregisterServiceInvalid(MasterApiTestCase):
00099     def testUnregisterServiceInvalid(self):
00100         self._testUnregisterServiceInvalid()
00101 
00102 class MasterUnregisterPublisherInvalid(MasterApiTestCase):
00103     def testUnregisterPublisherInvalid(self):
00104         self._testUnregisterPublisherInvalid()
00105 
00106 class MasterUnregisterSubscriberInvalid(MasterApiTestCase):     
00107     def testUnregisterSubscriberInvalid(self):
00108         self._testUnregisterSubscriberInvalid()
00109 
00110 
00111         
00112 if __name__ == '__main__':
00113     # this is terribly complicated on the account that we want a fresh master for each test, so we cannot
00114     # run all the tests as a single test node. instead, we have to have a separate test node per test.
00115     
00116     import optparse
00117     from optparse import OptionParser
00118     parser = OptionParser(usage="usage: %prog [options] topic", prog=NAME)
00119 
00120     # have to redeclare --text/--cov options, which are standard rostest options
00121     parser.add_option("--text",dest="text_ignore", default=False,
00122                       action="store_true", help="rostest standard option")
00123     parser.add_option("--cov",dest="cov_ignore", default=False,
00124                       action="store_true", help="rostest standard option")
00125     
00126     parser.add_option("--simple",dest="simple", default=False,
00127                       action="store_true", help="MasterSimpleApi")
00128 
00129     parser.add_option("--gtest_output",dest="gtest_output", default='',
00130                       help="xml output file")
00131 
00132     parser.add_option("--regsrvsuccess", dest="regsrvsuccess", default=False,
00133                       action="store_true", help="MasterRegisterServiceSuccess")
00134     parser.add_option("--regpubsuccess", dest="regpubsuccess", default=False,
00135                       action="store_true", help="MasterRegisterPublisherSuccess")
00136     parser.add_option("--regpubtypes", dest="regpubtypes", default=False,
00137                       action="store_true", help="MasterRegisterPublisherTypes")
00138     parser.add_option("--regsubsimplesuccess", dest="regsubsimplesuccess", default=False,
00139                       action="store_true", help="MasterRegisterSubscriberSimpleSuccess")
00140 
00141 
00142     parser.add_option("--unregsrvsuccess", dest="unregsrvsuccess", default=False,
00143                       action="store_true", help="MasterUnregisterServiceSuccess")
00144     parser.add_option("--unregpubsuccess", dest="unregpubsuccess", default=False,
00145                       action="store_true", help="MasterUnregisterPublisherSuccess")
00146     parser.add_option("--unregsubsuccess", dest="unregsubsuccess", default=False,
00147                       action="store_true", help="MasterUnregisterSubscriberSuccess")
00148 
00149     parser.add_option("--regsrvinvalid", dest="regsrvinvalid", default=False,
00150                       action="store_true", help="MasterRegisterServiceInvalid")
00151     parser.add_option("--regsubinvalid", dest="regsubinvalid", default=False,
00152                       action="store_true", help="MasterRegisterSubscriberInvalid")
00153     parser.add_option("--regpubinvalid", dest="regpubinvalid", default=False,
00154                       action="store_true", help="MasterRegisterPublisherInvalid")
00155 
00156     parser.add_option("--unregsrvinvalid", dest="unregsrvinvalid", default=False,
00157                       action="store_true", help="MasterUnregisterServiceInvalid")
00158     parser.add_option("--unregsubinvalid", dest="unregsubinvalid", default=False,
00159                       action="store_true", help="MasterUnregisterSubscriberInvalid")
00160     parser.add_option("--unregpubinvalid", dest="unregpubinvalid", default=False,
00161                       action="store_true", help="MasterUnregisterPublisherInvalid")
00162 
00163 
00164     (options, args) = parser.parse_args()
00165     if options.simple:
00166         cls = MasterSimpleApi
00167 
00168     elif options.regsrvsuccess:
00169         cls = MasterRegisterServiceSuccess
00170     elif options.regpubsuccess:
00171         cls = MasterRegisterPublisherSuccess
00172     elif options.regpubtypes:
00173         cls = MasterRegisterPublisherTypes
00174     elif options.regsubsimplesuccess:
00175         cls = MasterRegisterSubscriberSimpleSuccess
00176 
00177     elif options.unregsrvsuccess:
00178         cls = MasterUnregisterServiceSuccess
00179     elif options.unregpubsuccess:
00180         cls = MasterUnregisterPublisherSuccess
00181     elif options.unregsubsuccess:
00182         cls = MasterUnregisterSubscriberSuccess     
00183 
00184     elif options.regsrvinvalid:
00185         cls = MasterRegisterServiceInvalid
00186     elif options.regpubinvalid:
00187         cls = MasterRegisterPublisherInvalid
00188     elif options.regsubinvalid:
00189         cls = MasterRegisterSubscriberInvalid
00190 
00191     elif options.unregsrvinvalid:
00192         cls = MasterUnregisterServiceInvalid
00193     elif options.unregpubinvalid:
00194         cls = MasterUnregisterPublisherInvalid
00195     elif options.unregsubinvalid:
00196         cls = MasterUnregisterSubscriberInvalid
00197 
00198     if not cls:
00199         parser.error("you must specify a test to run with an [options] flag")
00200         
00201     set_node_name(NAME)
00202     rospy.init_node(NAME, disable_rostime=True)
00203     import rostest
00204     rostest.rosrun(PKG, NAME, cls, sys.argv)


test_rosmaster
Author(s): Ken Conley
autogenerated on Tue Mar 7 2017 03:45:38