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 import os
00037 import sys
00038 import unittest
00039 import cStringIO
00040 import time
00041
00042 from subprocess import Popen, PIPE, check_call, call
00043
00044 import rosparam
00045
00046 def get_test_path():
00047 return os.path.abspath(os.path.join(os.path.dirname(__file__)))
00048
00049 class TestRosparamOffline(unittest.TestCase):
00050
00051 def setUp(self):
00052 pass
00053
00054
00055 def test_cmd_help(self):
00056 cmd = 'rosparam'
00057 sub = ['set', 'get', 'load', 'dump', 'delete', 'list']
00058
00059 output = Popen([cmd], stdout=PIPE).communicate()[0]
00060 self.assert_('Commands' in output, output)
00061 output = Popen([cmd, '-h'], stdout=PIPE).communicate()[0]
00062 self.assert_('Commands' in output)
00063
00064 for c in sub:
00065
00066 self.assert_("%s %s"%(cmd, c) in output)
00067
00068 for c in sub:
00069 output = Popen([cmd, c, '-h'], stdout=PIPE, stderr=PIPE).communicate()
00070 self.assert_("Usage:" in output[0], "%s\n%s"%(output, c))
00071 self.assert_("%s %s"%(cmd, c) in output[0], "%s: %s"%(c, output[0]))
00072
00073
00074 for c in ['set', 'get', 'load', 'dump', 'delete']:
00075 output = Popen([cmd, c], stdout=PIPE, stderr=PIPE).communicate()
00076 self.assert_("Usage:" in output[0] or "Usage:" in output[1], "%s\n%s"%(output, c))
00077 self.assert_("%s %s"%(cmd, c) in output[1])
00078
00079 def test_offline(self):
00080 cmd = 'rosparam'
00081
00082
00083 env = os.environ.copy()
00084 env['ROS_MASTER_URI'] = 'http://localhost:11312'
00085 kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}
00086
00087 msg = "ERROR: Unable to communicate with master!\n"
00088
00089 output = Popen([cmd, 'list'], **kwds).communicate()
00090 self.assert_(output[1].endswith(msg))
00091 output = Popen([cmd, 'set', 'foo', '1.0'], **kwds).communicate()
00092 self.assert_(output[1].endswith(msg))
00093 output = Popen([cmd, 'get', 'foo'], **kwds).communicate()
00094 self.assert_(output[1].endswith(msg))
00095
00096 path = os.path.join(get_test_path(), 'test.yaml')
00097 output = Popen([cmd, 'load', path], **kwds).communicate()
00098 self.assert_(output[1].endswith(msg))
00099
00100
00101 output = Popen([cmd, 'load', 'fake.yaml'], **kwds).communicate()
00102 self.assertEquals('ERROR: file [fake.yaml] does not exist\n', output[1])
00103
00104 output = Popen([cmd, 'dump', 'foo.yaml'], **kwds).communicate()
00105 self.assert_(output[1].endswith(msg))
00106 output = Popen([cmd, 'delete', 'foo'], **kwds).communicate()
00107 self.assert_(output[1].endswith(msg))
00108