$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: test_empty_service.py 7395 2009-12-18 00:39:24Z kwc $ 00035 00036 ## Integration test for empty services to test serializers 00037 ## and transport 00038 00039 PKG = 'test_rospy' 00040 NAME = 'empty_service' 00041 import roslib; roslib.load_manifest(PKG) 00042 00043 import sys, time 00044 import unittest 00045 00046 import rostest 00047 00048 class TestServiceFailure(unittest.TestCase): 00049 00050 def test_persistent(self): 00051 # fail_two_ints succeeds unless the first argument is -1. 00052 # this makes sure, in the persistent case, that the proxy handle remains valid after a call 00053 from test_ros.srv import AddTwoInts 00054 import rospy 00055 rospy.wait_for_service('fail_two_ints', 10.) 00056 p = rospy.ServiceProxy('fail_two_ints', AddTwoInts, persistent=True) 00057 for a in [1, -1, 1, -1, -1, -1, -1, 1]: 00058 try: 00059 resp = p(a, 1) 00060 if a == 1: 00061 self.assertEquals(resp.sum, 2) 00062 else: 00063 self.fail("service call should have failed: %s,%s, %s"%(a, 1, resp.sum)) 00064 except rospy.ServiceException, e: 00065 if a == -1: 00066 # expected 00067 pass 00068 else: 00069 self.fail("service call failed when it shouldn't have: %s"%str(e)) 00070 00071 def test_non_persistent(self): 00072 # fail_two_ints succeeds unless the first argument is -1. 00073 # this makes sure, in the non-persistent case, that the proxy handle remains valid after a call 00074 from test_ros.srv import AddTwoInts 00075 import rospy 00076 rospy.wait_for_service('fail_two_ints', 10.) 00077 p = rospy.ServiceProxy('fail_two_ints', AddTwoInts) 00078 for a in [1, -1, 1, -1, -1, -1, -1, 1]: 00079 try: 00080 resp = p(a, 1) 00081 if a == 1: 00082 self.assertEquals(resp.sum, 2) 00083 else: 00084 self.fail("service call should have failed") 00085 except rospy.ServiceException, e: 00086 if a == -1: 00087 # expected 00088 pass 00089 else: 00090 self.fail("service call should have failed") 00091 00092 00093 if __name__ == '__main__': 00094 rostest.run(PKG, 'rospy_service_failure', TestServiceFailure, sys.argv)