test_rosparam_command_line_offline.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2009, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 # Revision $Id: test_rosparam_command_line_offline.py 5710 2009-08-20 03:11:04Z sfkwc $
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     ## test that the rosmsg command works
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             # make sure command is in usage statement
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         # test no args on commands that require args
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         # point at a different 'master'
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         # have to test with actual file to avoid error
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         # test with file that does not exist
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         


test_rosparam
Author(s): Ken Conley
autogenerated on Tue Mar 7 2017 03:45:41