$search
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 # Revision $Id$ 00035 00036 import roslib; roslib.load_manifest('test_rospy') 00037 00038 import os 00039 import sys 00040 import struct 00041 import unittest 00042 import time 00043 00044 # test rospy API verifies that the rospy module exports the required symbols 00045 class TestRospyApi(unittest.TestCase): 00046 00047 def test_msg(self): 00048 # rospy.Message really only exists at the client level, as the internal 00049 # implementation is built around the roslib reference, so we put the test here 00050 00051 import rospy 00052 #trip wires against Message API 00053 m = rospy.Message() 00054 from cStringIO import StringIO 00055 buff = StringIO() 00056 m.serialize(buff) 00057 self.assertEquals(0, buff.tell()) 00058 m.deserialize('') 00059 00060 def test_anymsg(self): 00061 # rospy.AnyMsg really only exists at the client level as nothing within 00062 # rospy uses its functionality. 00063 00064 00065 from cStringIO import StringIO 00066 import rospy 00067 #trip wires against AnyMsg API 00068 m = rospy.AnyMsg() 00069 try: 00070 m.serialize(StringIO()) 00071 self.fail("AnyMsg should not allow serialization") 00072 except: 00073 pass 00074 00075 teststr = 'foostr-%s'%time.time() 00076 m.deserialize(teststr) 00077 self.assertEquals(teststr, m._buff) 00078 00079 #test AnyMsg ctor error checking 00080 try: 00081 m = rospy.AnyMsg('foo') 00082 self.fail("AnyMsg ctor should not allow args") 00083 except: pass 00084 00085 def test_rospy_api(self): 00086 import rospy 00087 00088 # just a laundry list of API methods to make sure that they still exist 00089 00090 # removed 00091 try: 00092 rospy.add_shutdown_hook 00093 self.fail("add_shutdown_hookshould not longer be top-level API") 00094 except AttributeError: pass 00095 00096 rospy.DEBUG 00097 rospy.INFO 00098 rospy.WARN 00099 rospy.ERROR 00100 rospy.FATAL 00101 00102 rospy.get_caller_id 00103 rospy.get_name 00104 rospy.get_master 00105 rospy.get_namespace 00106 rospy.get_published_topics 00107 rospy.get_node_uri 00108 rospy.get_ros_root 00109 rospy.get_time 00110 rospy.get_rostime 00111 rospy.init_node 00112 rospy.is_shutdown 00113 rospy.logdebug 00114 rospy.logerr 00115 rospy.logfatal 00116 rospy.loginfo 00117 rospy.logout #deprecated 00118 rospy.logwarn 00119 rospy.myargv 00120 rospy.on_shutdown 00121 rospy.parse_rosrpc_uri 00122 rospy.resolve_name 00123 rospy.remap_name 00124 rospy.signal_shutdown 00125 rospy.sleep 00126 rospy.spin 00127 rospy.wait_for_message 00128 rospy.wait_for_service 00129 00130 rospy.delete_param 00131 rospy.get_param 00132 rospy.get_param_names 00133 rospy.has_param 00134 rospy.set_param 00135 rospy.search_param 00136 00137 rospy.AnyMsg 00138 rospy.Duration 00139 rospy.Header 00140 rospy.MasterProxy 00141 rospy.Message 00142 rospy.Publisher 00143 rospy.Rate 00144 rospy.ROSException 00145 rospy.ROSInternalException 00146 rospy.ROSSerializationException 00147 rospy.ServiceDefinition 00148 rospy.ServiceException 00149 rospy.Service 00150 rospy.ServiceProxy 00151 rospy.SubscribeListener 00152 rospy.Subscriber 00153 rospy.Time 00154 rospy.TransportException 00155 rospy.TransportTerminated 00156 rospy.TransportInitError 00157 00158 if __name__ == '__main__': 00159 import rostest 00160 rostest.unitrun('test_rospy', sys.argv[0], TestRospyApi)