41 from subprocess
import Popen, PIPE, check_call, call
43 from rosgraph.names
import script_resolve_name
47 return rosgraph.Master(
'/rosparam')
64 names = [
'/chatter',
'foo/chatter']
67 params = [
'/string',
'/int',
'/float',
68 '/g1/string',
'/g1/int',
'/g1/float',
69 '/g2/string',
'/g2/int',
'/g2/float',
72 output = Popen([cmd,
'list'], stdout=PIPE).communicate()[0]
73 l = set(output.split())
79 output = Popen([cmd,
'get',
"string"], stdout=PIPE).communicate()[0]
80 self.assertEquals(
'foo-value', output.strip())
82 output = Popen([cmd,
'get',
'-p',
"string"], stdout=PIPE).communicate()[0]
83 self.assertEquals(
'foo-value', output.strip())
84 output = Popen([cmd,
'get',
"/string"], stdout=PIPE).communicate()[0]
85 self.assertEquals(
'foo-value', output.strip())
86 output = Popen([cmd,
'get',
"g1/string"], stdout=PIPE).communicate()[0]
87 self.assertEquals(
'g1-foo-value', output.strip())
88 output = Popen([cmd,
'get',
"/g1/string"], stdout=PIPE).communicate()[0]
89 self.assertEquals(
'g1-foo-value', output.strip())
90 output = Popen([cmd,
'get',
"/g2/string"], stdout=PIPE).communicate()[0]
91 self.assertEquals(
'g2-foo-value', output.strip())
93 output = Popen([cmd,
'get',
"int"], stdout=PIPE).communicate()[0]
94 self.assertEquals(
'1', output.strip())
96 output = Popen([cmd,
'get',
'-p',
"int"], stdout=PIPE).communicate()[0]
97 self.assertEquals(
'1', output.strip())
98 output = Popen([cmd,
'get',
"/int"], stdout=PIPE).communicate()[0]
99 self.assertEquals(
'1', output.strip())
100 output = Popen([cmd,
'get',
"g1/int"], stdout=PIPE).communicate()[0]
101 self.assertEquals(
'10', output.strip())
102 output = Popen([cmd,
'get',
"/g1/int"], stdout=PIPE).communicate()[0]
103 self.assertEquals(
'10', output.strip())
104 output = Popen([cmd,
'get',
"/g2/int"], stdout=PIPE).communicate()[0]
105 self.assertEquals(
'20', output.strip())
107 output = Popen([cmd,
'get',
"float"], stdout=PIPE).communicate()[0]
108 self.assertEquals(
'1.0', output.strip())
110 output = Popen([cmd,
'get',
'-p',
"float"], stdout=PIPE).communicate()[0]
111 self.assertEquals(
'1.0', output.strip())
112 output = Popen([cmd,
'get',
"/float"], stdout=PIPE).communicate()[0]
113 self.assertEquals(
'1.0', output.strip())
114 output = Popen([cmd,
'get',
"g1/float"], stdout=PIPE).communicate()[0]
115 self.assertEquals(
'10.0', output.strip())
116 output = Popen([cmd,
'get',
"/g1/float"], stdout=PIPE).communicate()[0]
117 self.assertEquals(
'10.0', output.strip())
118 output = Popen([cmd,
'get',
"/g2/float"], stdout=PIPE).communicate()[0]
119 self.assertEquals(
'20.0', output.strip())
121 output = Popen([cmd,
'get',
"g1"], stdout=PIPE).communicate()[0]
123 d = yaml.load(output)
124 self.assertEquals(d[
'float'], 10.0)
125 self.assertEquals(d[
'int'], 10.0)
126 self.assertEquals(d[
'string'],
"g1-foo-value")
127 self.assertEquals(set([
'float',
'int',
'string']), set(d.keys()))
130 check_call([cmd,
'get',
'-p',
"g1"])
132 check_call([cmd,
'get',
'-pv',
"g1"])
136 Popen([cmd,
'set',
"/set/test1",
"1"], stdout=PIPE).communicate()[0]
137 self.assertEquals(1, ps.getParam(
'/set/test1'))
139 Popen([cmd,
'set',
'-v',
"/set/test1",
"1"], stdout=PIPE).communicate()[0]
140 self.assertEquals(1, ps.getParam(
'/set/test1'))
141 Popen([cmd,
'set',
"set/test1",
"2"], stdout=PIPE).communicate()[0]
142 self.assertEquals(2, ps.getParam(
'/set/test1'))
144 Popen([cmd,
'set',
"/set/test2",
"1.0"], stdout=PIPE).communicate()[0]
145 self.assertEquals(1, ps.getParam(
'/set/test2'))
146 Popen([cmd,
'set',
"set/test2",
"2.0"], stdout=PIPE).communicate()[0]
147 self.assertEquals(2, ps.getParam(
'/set/test2'))
149 Popen([cmd,
'set',
"/set/testbool",
"true"], stdout=PIPE).communicate()[0]
150 self.assertEquals(
True, ps.getParam(
'/set/testbool'))
151 Popen([cmd,
'set',
"set/testbool",
"false"], stdout=PIPE).communicate()[0]
152 self.assertEquals(
False, ps.getParam(
'/set/testbool'))
155 Popen([cmd,
'set',
"/set/teststr",
"hi"], stdout=PIPE).communicate()[0]
156 self.assertEquals(
"hi", ps.getParam(
'/set/teststr'))
157 Popen([cmd,
'set',
"set/teststr",
"hello world"], stdout=PIPE).communicate()[0]
158 self.assertEquals(
"hello world", ps.getParam(
'/set/teststr'))
159 Popen([cmd,
'set',
"set/teststr",
"'true'"], stdout=PIPE).communicate()[0]
160 self.assertEquals(
"true", ps.getParam(
'/set/teststr'))
162 Popen([cmd,
'set',
"set/testlist",
"[]"], stdout=PIPE).communicate()[0]
163 self.assertEquals([], ps.getParam(
'/set/testlist'))
164 Popen([cmd,
'set',
"/set/testlist",
"[1, 2, 3]"], stdout=PIPE).communicate()[0]
165 self.assertEquals([1, 2, 3], ps.getParam(
'/set/testlist'))
167 Popen([cmd,
'set',
"/set/testdict",
"{a: b, c: d}"], stdout=PIPE).communicate()[0]
168 self.assertEquals(
'b', ps.getParam(
'/set/testdict/a'))
169 self.assertEquals(
'd', ps.getParam(
'/set/testdict/c'))
171 Popen([cmd,
'set',
"set/testdict",
"{}"], stdout=PIPE).communicate()[0]
172 self.assertEquals(
'b', ps.getParam(
'/set/testdict/a'))
173 self.assertEquals(
'd', ps.getParam(
'/set/testdict/c'))
175 Popen([cmd,
'set',
"/set/testdict",
"{e: f, g: h}"], stdout=PIPE).communicate()[0]
176 self.assertEquals(
'b', ps.getParam(
'/set/testdict/a'))
177 self.assertEquals(
'd', ps.getParam(
'/set/testdict/c'))
178 self.assertEquals(
'f', ps.getParam(
'/set/testdict/e'))
179 self.assertEquals(
'h', ps.getParam(
'/set/testdict/g'))
181 check_call([cmd,
'set',
'-v',
"/set/testdictverbose",
"{e: f, g: h}"])
184 ps.setParam(
'/delete/me',
True)
185 self.assert_(ps.hasParam(
'/delete/me'))
186 Popen([cmd,
'delete',
"/delete/me"], stdout=PIPE).communicate()[0]
187 self.failIf(ps.hasParam(
'/delete/me'))
192 PKG =
'test_rosparam' 193 NAME =
'test_rosparam_command_line_online' 194 if __name__ ==
'__main__':
195 rostest.run(PKG, NAME, TestRosparamOnline, sys.argv)
def callback(self, msg, val)