Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 PKG = 'test_rospy'
00038
00039 import sys, time
00040 import unittest
00041
00042 import rospy, rostest
00043 from test_rospy.srv import *
00044
00045 SERVICE_BEFORE = 'service_order_before'
00046 SERVICE_AFTER = 'service_order_after'
00047
00048 FAKE_SECRET = 123456
00049
00050 WAIT_TIMEOUT = 10.0
00051
00052 def handle_empty_req(req):
00053 print "Returning fake_secret"
00054 return EmptyReqSrvResponse(FAKE_SECRET)
00055
00056 def service_before():
00057 s = rospy.Service(SERVICE_BEFORE, EmptyReqSrv, handle_empty_req)
00058 rospy.init_node('service_before')
00059 rospy.spin()
00060
00061
00062 def service_after():
00063 rospy.init_node('service_after')
00064 s = rospy.Service(SERVICE_AFTER, EmptyReqSrv, handle_empty_req)
00065 rospy.spin()
00066
00067 class TestServiceOrder(unittest.TestCase):
00068
00069 def _test(self, name, srv, req):
00070 rospy.wait_for_service(name, WAIT_TIMEOUT)
00071 s = rospy.ServiceProxy(name, srv)
00072 resp = s.call(req)
00073 self.assert_(resp is not None)
00074 return resp
00075 def test_before(self):
00076 resp = self._test(SERVICE_BEFORE, EmptyReqSrv,
00077 EmptyReqSrvRequest())
00078 self.assertEquals(FAKE_SECRET, resp.fake_secret,
00079 "fake_secret fields is not set as expected")
00080 def test_after(self):
00081 resp = self._test(SERVICE_AFTER, EmptyReqSrv,
00082 EmptyReqSrvRequest())
00083 self.assertEquals(FAKE_SECRET, resp.fake_secret,
00084 "fake_secret fields is not set as expected")
00085
00086 if __name__ == '__main__':
00087 if '--before' in sys.argv:
00088 service_before()
00089 elif '--after' in sys.argv:
00090 service_after()
00091 else:
00092 rostest.run(PKG, 'rospy_service_decl_order', TestServiceOrder, sys.argv)