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 import os
00035 import sys
00036 import unittest
00037 import cStringIO
00038 import time
00039
00040 import rostest
00041
00042 from subprocess import Popen, PIPE, check_call, call
00043
00044 class TestRosserviceOffline(unittest.TestCase):
00045
00046 def setUp(self):
00047 pass
00048
00049
00050 def test_cmd_help(self):
00051 cmd = 'rosservice'
00052 sub = ['args', 'info', 'list', 'call', 'type', 'uri', 'find']
00053
00054 output = Popen([cmd], stdout=PIPE).communicate()[0]
00055 self.assert_('Commands' in output)
00056 output = Popen([cmd, '-h'], stdout=PIPE).communicate()[0]
00057 self.assert_('Commands' in output)
00058
00059 for c in sub:
00060 self.assert_("%s %s"%(cmd, c) in output, output)
00061
00062 for c in sub:
00063 output = Popen([cmd, c, '-h'], stdout=PIPE).communicate()
00064 self.assert_("Usage:" in output[0], output)
00065
00066 self.assert_("%s %s"%(cmd, c) in output[0], output)
00067
00068 def test_offline(self):
00069 cmd = 'rosservice'
00070
00071
00072 env = os.environ.copy()
00073 env['ROS_MASTER_URI'] = 'http://localhost:11312'
00074 kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}
00075
00076 msg = "ERROR: Unable to communicate with master!\n"
00077
00078 output = Popen([cmd, 'list'], **kwds).communicate()
00079 self.assert_(output[1].endswith(msg))
00080 output = Popen([cmd, 'type', 'add_two_ints'], **kwds).communicate()
00081 self.assert_(output[1].endswith(msg))
00082 output = Popen([cmd, 'uri', 'add_two_ints'], **kwds).communicate()
00083 self.assert_(output[1].endswith(msg))
00084 output = Popen([cmd, 'call', 'add_two_ints', '1', '2'], **kwds).communicate()
00085 self.assert_(output[1].endswith(msg))
00086
00087 output = Popen([cmd, 'call', '--wait', 'add_two_ints', '1', '2'], **kwds).communicate()
00088 self.assert_(output[1].endswith(msg))
00089 output = Popen([cmd, 'find', 'test_ros/AddTwoInts'], **kwds).communicate()
00090 self.assert_(output[1].endswith(msg))
00091
00092 if __name__ == '__main__':
00093 rostest.unitrun('test_rosservice', NAME, TestRosserviceOffline, sys.argv, coverage_packages=[])