41 from subprocess
import Popen, PIPE, check_call, call
46 return os.path.abspath(os.path.join(os.path.dirname(__file__)))
56 sub = [
'set',
'get',
'load',
'dump',
'delete',
'list']
58 output = Popen([cmd], stdout=PIPE).communicate()[0]
59 self.assert_(
'Commands' in output.decode(), output)
60 output = Popen([cmd,
'-h'], stdout=PIPE).communicate()[0]
61 self.assert_(
'Commands' in output.decode())
65 self.assert_(
"%s %s"%(cmd, c)
in output.decode())
68 output = Popen([cmd, c,
'-h'], stdout=PIPE, stderr=PIPE).communicate()
69 self.assert_(
"Usage:" in output[0].decode(),
"%s\n%s" % (output, c))
70 self.assert_(
"%s %s"%(cmd, c)
in output[0].decode(),
"%s: %s" % (c, output[0].decode()))
73 for c
in [
'set',
'get',
'load',
'delete']:
74 output = Popen([cmd, c], stdout=PIPE, stderr=PIPE).communicate()
75 self.assert_(
"Usage:" in output[0].decode()
or "Usage:" in output[1].decode(),
"%s\n%s"%(output, c))
76 self.assert_(
"%s %s"%(cmd, c)
in output[1].decode())
82 env = os.environ.copy()
83 env[
'ROS_MASTER_URI'] =
'http://localhost:11312' 84 kwds = {
'env': env,
'stdout': PIPE,
'stderr': PIPE}
86 msg =
"ERROR: Unable to communicate with master!\n" 88 output = Popen([cmd,
'list'], **kwds).communicate()
89 self.assert_(output[1].decode().endswith(msg))
90 output = Popen([cmd,
'set',
'foo',
'1.0'], **kwds).communicate()
91 self.assert_(output[1].decode().endswith(msg))
92 output = Popen([cmd,
'get',
'foo'], **kwds).communicate()
93 self.assert_(output[1].decode().endswith(msg))
96 output = Popen([cmd,
'load', path], **kwds).communicate()
97 self.assert_(output[1].decode().endswith(msg))
100 output = Popen([cmd,
'load',
'fake.yaml'], **kwds).communicate()
101 self.assertEquals(
'ERROR: file [fake.yaml] does not exist\n', output[1].decode())
103 output = Popen([cmd,
'dump',
'foo.yaml'], **kwds).communicate()
104 self.assert_(output[1].decode().endswith(msg))
105 output = Popen([cmd,
'delete',
'foo'], **kwds).communicate()
106 self.assert_(output[1].decode().endswith(msg))
def test_cmd_help(self)
test that the rosmsg command works