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