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


test_rosparam
Author(s): Ken Conley
autogenerated on Fri Aug 28 2015 12:34:29