test_rosparam_command_line_offline.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2009, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage, Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 #
34 # Revision $Id: test_rosparam_command_line_offline.py 5710 2009-08-20 03:11:04Z sfkwc $
35 
36 import os
37 import sys
38 import unittest
39 import time
40 
41 from subprocess import Popen, PIPE, check_call, call
42 
43 import rosparam
44 
46  return os.path.abspath(os.path.join(os.path.dirname(__file__)))
47 
48 class TestRosparamOffline(unittest.TestCase):
49 
50  def setUp(self):
51  pass
52 
53  ## test that the rosmsg command works
54  def test_cmd_help(self):
55  cmd = 'rosparam'
56  sub = ['set', 'get', 'load', 'dump', 'delete', 'list']
57 
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())
62 
63  for c in sub:
64  # make sure command is in usage statement
65  self.assert_("%s %s"%(cmd, c) in output.decode())
66 
67  for c in sub:
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()))
71 
72  # test no args on commands that require args
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())
77 
78  def test_offline(self):
79  cmd = 'rosparam'
80 
81  # point at a different 'master'
82  env = os.environ.copy()
83  env['ROS_MASTER_URI'] = 'http://localhost:11312'
84  kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE}
85 
86  msg = "ERROR: Unable to communicate with master!\n"
87 
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))
94  # have to test with actual file to avoid error
95  path = os.path.join(get_test_path(), 'test.yaml')
96  output = Popen([cmd, 'load', path], **kwds).communicate()
97  self.assert_(output[1].decode().endswith(msg))
98 
99  # test with file that does not exist
100  output = Popen([cmd, 'load', 'fake.yaml'], **kwds).communicate()
101  self.assertEquals('ERROR: file [fake.yaml] does not exist\n', output[1].decode())
102 
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))
107 


test_rosparam
Author(s): Ken Conley
autogenerated on Sun Feb 3 2019 03:30:21