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 = 'topic_tools'
00038
00039 import unittest
00040 import rospy
00041
00042 from topic_tools.srv import MuxAdd
00043 from topic_tools.srv import MuxDelete
00044 from topic_tools.srv import MuxList
00045 from topic_tools.srv import MuxSelect
00046
00047 class MuxServiceTestCase(unittest.TestCase):
00048 def make_srv_proxies(self):
00049 try:
00050 rospy.wait_for_service('mux/add', 5)
00051 rospy.wait_for_service('mux/delete', 5)
00052 rospy.wait_for_service('mux/list', 5)
00053 rospy.wait_for_service('mux/select', 5)
00054 except rospy.ROSException as e:
00055 self.fail('failed to find a required service: ' + `e`)
00056
00057 add_srv = rospy.ServiceProxy('mux/add', MuxAdd)
00058 delete_srv = rospy.ServiceProxy('mux/delete', MuxDelete)
00059 list_srv = rospy.ServiceProxy('mux/list', MuxList)
00060 select_srv = rospy.ServiceProxy('mux/select', MuxSelect)
00061
00062 return (add_srv, delete_srv, list_srv, select_srv)
00063
00064 def test_add_delete_list(self):
00065 add_srv, delete_srv, list_srv, select_srv = self.make_srv_proxies()
00066
00067 topics = list_srv().topics
00068 self.assertEquals(set(topics), set(['/input']))
00069
00070 add_srv('/new_input')
00071 topics = list_srv().topics
00072 self.assertEquals(set(topics), set(['/input', '/new_input']))
00073
00074
00075 try:
00076 add_srv('/new_input')
00077 except rospy.ServiceException:
00078 pass
00079 else:
00080 self.fail('service call should have thrown an exception')
00081 topics = list_srv().topics
00082 self.assertEquals(set(topics), set(['/input', '/new_input']))
00083
00084
00085 select_srv('/input')
00086 try:
00087 delete_srv('/input')
00088 except rospy.ServiceException:
00089 pass
00090 else:
00091 self.fail('service call should have thrown an exception')
00092 topics = list_srv().topics
00093 self.assertEquals(set(topics), set(['/input', '/new_input']))
00094
00095 select_srv('__none')
00096
00097 delete_srv('/input')
00098 topics = list_srv().topics
00099 self.assertEquals(set(topics), set(['/new_input']))
00100 delete_srv('/new_input')
00101 topics = list_srv().topics
00102 self.assertEquals(set(topics), set([]))
00103
00104 if __name__ == "__main__":
00105 import rostest
00106 rostest.unitrun(PKG, 'mux_services', MuxServiceTestCase)
00107