test_loader.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright (c) 2009, Willow Garage, Inc.
00004 # All rights reserved.
00005 # 
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 # 
00009 #     * Redistributions of source code must retain the above copyright
00010 #       notice, this list of conditions and the following disclaimer.
00011 #     * Redistributions in binary form must reproduce the above copyright
00012 #       notice, this list of conditions and the following disclaimer in the
00013 #       documentation and/or other materials provided with the distribution.
00014 #     * Neither the name of the Willow Garage, Inc. nor the names of its
00015 #       contributors may be used to endorse or promote products derived from
00016 #       this software without specific prior written permission.
00017 # 
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 # POSSIBILITY OF SUCH DAMAGE.
00029 
00030 
00031 import roslib; roslib.load_manifest('test_nodelet')
00032 import rospy
00033 import unittest
00034 import rostest
00035 import random
00036 
00037 from nodelet.srv import *
00038 
00039 class TestLoader(unittest.TestCase):
00040     def test_loader(self):
00041         load = rospy.ServiceProxy('/nodelet_manager/load_nodelet', NodeletLoad)
00042         unload = rospy.ServiceProxy('/nodelet_manager/unload_nodelet', NodeletUnload)
00043         list = rospy.ServiceProxy('/nodelet_manager/list', NodeletList)
00044         
00045         load.wait_for_service()
00046         unload.wait_for_service()
00047         list.wait_for_service()
00048         
00049         req = NodeletLoadRequest()
00050         req.name = "/my_nodelet"
00051         req.type = "test_nodelet/Plus"
00052         
00053         res = load.call(req)
00054         self.assertTrue(res.success)
00055         
00056         req = NodeletListRequest()
00057         res = list.call(req)
00058         self.assertTrue("/my_nodelet" in res.nodelets)
00059         
00060         req = NodeletUnloadRequest()
00061         req.name = "/my_nodelet"
00062         res = unload.call(req)
00063         self.assertTrue(res.success)
00064 
00065     def test_loader_failed_initialization(self):
00066         load = rospy.ServiceProxy('/nodelet_manager/load_nodelet', NodeletLoad)
00067         unload = rospy.ServiceProxy('/nodelet_manager/unload_nodelet', NodeletUnload)
00068         list = rospy.ServiceProxy('/nodelet_manager/list', NodeletList)
00069 
00070         load.wait_for_service()
00071         unload.wait_for_service()
00072         list.wait_for_service()
00073 
00074         req = NodeletLoadRequest()
00075         req.name = "/my_nodelet"
00076         req.type = "test_nodelet/FailingNodelet"
00077         self.assertRaises(rospy.ServiceException, load.call, req)
00078 
00079         # If the Nodelet failed to initialize, it shouldn't be stored in the
00080         # nodelet map
00081         req = NodeletListRequest()
00082         res = list.call(req)
00083         self.assertFalse("/my_nodelet" in res.nodelets)
00084 
00085         req = NodeletUnloadRequest()
00086         req.name = "/my_nodelet"
00087         self.assertRaises(rospy.ServiceException, unload.call, req)
00088 
00089 
00090 if __name__ == '__main__':
00091     rospy.init_node('test_loader')
00092     rostest.unitrun('test_loader', 'test_loader', TestLoader)
00093 


test_nodelet
Author(s): Tully Foote
autogenerated on Wed Aug 26 2015 14:56:52