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 from __future__ import with_statement
00037
00038 NAME = 'test_rosmsg_command_line'
00039 import roslib; roslib.load_manifest('test_rosmsg')
00040
00041 import os
00042 import sys
00043 import unittest
00044 import cStringIO
00045 import time
00046
00047 import rostest
00048
00049 from subprocess import Popen, PIPE, check_call, call
00050
00051 class TestRosmsg(unittest.TestCase):
00052
00053 def setUp(self):
00054 pass
00055
00056
00057 def test_cmd_help(self):
00058 sub = ['show', 'md5', 'package', 'packages', 'users']
00059
00060 for cmd in ['rosmsg', 'rossrv']:
00061 output = Popen([cmd], stdout=PIPE).communicate()[0]
00062 self.assert_('Commands' in output)
00063 output = Popen([cmd, '-h'], stdout=PIPE).communicate()[0]
00064 self.assert_('Commands' in output)
00065 self.assert_('Traceback' not in output)
00066 for c in sub:
00067 self.assert_("%s %s"%(cmd, c) in output, output)
00068
00069 for c in sub:
00070 output = Popen([cmd, c, '-h'], stdout=PIPE).communicate()[0]
00071 self.assert_('Usage' in output)
00072 self.assert_("%s %s"%(cmd, c) in output, output)
00073
00074 def xtest_cmd_packages(self):
00075
00076 output1 = Popen(['rosmsg', 'packages', '-s'], stdout=PIPE).communicate()[0]
00077
00078 output2 = Popen(['rosmsg', 'packages'], stdout=PIPE).communicate()[0]
00079 l1 = [x for x in output1.split() if x]
00080 l2 = [x.strip() for x in output2.split('\n') if x.strip()]
00081 self.assertEquals(l1, l2)
00082 for p in ['roslib', 'test_rosmsg', 'std_msgs', 'test_ros']:
00083 self.assert_(p in l1)
00084 for p in ['std_srvs', 'rospy']:
00085 self.assert_(p not in l1)
00086
00087 output1 = Popen(['rossrv', 'packages', '-s'], stdout=PIPE).communicate()[0]
00088 output2 = Popen(['rossrv', 'packages'], stdout=PIPE).communicate()[0]
00089 l1 = [x for x in output1.split() if x]
00090 l2 = [x.strip() for x in output2.split('\n') if x.strip()]
00091 self.assertEquals(l1, l2)
00092 for p in ['test_rosmsg', 'std_srvs', 'test_ros']:
00093 self.assert_(p in l1)
00094 for p in ['std_msgs', 'rospy']:
00095 self.assert_(p not in l1)
00096
00097 def xtest_cmd_package(self):
00098
00099
00100 output1 = Popen(['rosmsg', 'package', '-s', 'test_rosmsg'], stdout=PIPE).communicate()[0]
00101
00102 output2 = Popen(['rosmsg', 'package', 'test_rosmsg'], stdout=PIPE).communicate()[0]
00103 l = set([x for x in output1.split() if x])
00104 l2 = set([x.strip() for x in output2.split('\n') if x.strip()])
00105 self.assertEquals(l, l2)
00106
00107 self.assertEquals(set(['test_rosmsg/RosmsgA',
00108 'test_rosmsg/RosmsgB',
00109 'test_rosmsg/RosmsgC',
00110 ]), l)
00111
00112 output = Popen(['rossrv', 'package', '-s', 'test_rosmsg'], stdout=PIPE).communicate()[0]
00113 output2 = Popen(['rossrv', 'package','test_rosmsg'], stdout=PIPE).communicate()[0]
00114 l = set([x for x in output.split() if x])
00115 l2 = set([x.strip() for x in output2.split('\n') if x.strip()])
00116 self.assertEquals(l, l2)
00117
00118 self.assertEquals(set(['test_rosmsg/RossrvA', 'test_rosmsg/RossrvB']), l)
00119
00120
00121 def xtest_cmd_show(self):
00122 output = Popen(['rosmsg', 'show', 'std_msgs/String'], stdout=PIPE).communicate()[0]
00123 self.assertEquals('string data', output.strip())
00124
00125 output = Popen(['rossrv', 'show', 'std_srvs/Empty'], stdout=PIPE).communicate()[0]
00126 self.assertEquals('---', output.strip())
00127 output = Popen(['rossrv', 'show', 'std_srvs/Empty'], stdout=PIPE).communicate()[0]
00128 self.assertEquals('---', output.strip())
00129 output = Popen(['rossrv', 'show', 'test_ros/AddTwoInts'], stdout=PIPE).communicate()[0]
00130 self.assertEquals('int64 a\nint64 b\n---\nint64 sum', output.strip())
00131
00132
00133 d = roslib.packages.get_pkg_dir('test_rosmsg')
00134 msg_d = os.path.join(d, 'msg')
00135
00136 for t in ['RosmsgA', 'RosmsgB']:
00137 with open(os.path.join(msg_d, '%s.msg'%t), 'r') as f:
00138 text = f.read()
00139 text = text+'\n'
00140 type_ ='test_rosmsg/'+t
00141 output = Popen(['rosmsg', 'show', type_], stdout=PIPE).communicate()[0]
00142 self.assertEquals(text, output)
00143 output = Popen(['rosmsg', 'show', '-r',type_], stdout=PIPE, stderr=PIPE).communicate()
00144 self.assertEquals(text, output[0], "Failed: %s"%(str(output)))
00145 output = Popen(['rosmsg', 'show', '--raw', type_], stdout=PIPE).communicate()[0]
00146 self.assertEquals(text, output)
00147
00148
00149 type_ = t
00150 text = "[test_rosmsg/%s]:\n%s"%(t, text)
00151 output = Popen(['rosmsg', 'show', type_], stdout=PIPE).communicate()[0]
00152 self.assertEquals(text, output)
00153 output = Popen(['rosmsg', 'show', '-r',type_], stdout=PIPE, stderr=PIPE).communicate()
00154 self.assertEquals(text, output[0], "Failed: %s"%(str(output)))
00155 output = Popen(['rosmsg', 'show', '--raw', type_], stdout=PIPE).communicate()[0]
00156 self.assertEquals(text, output)
00157
00158 if __name__ == '__main__':
00159 rostest.unitrun('test_rosmsg', NAME, TestRosmsg, sys.argv, coverage_packages=[])