test_static_publisher.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 #***********************************************************
00003 #* Software License Agreement (BSD License)
00004 #*
00005 #*  Copyright (c) 2016, Felix Duvallet
00006 #*  All rights reserved.
00007 #*
00008 #*  Redistribution and use in source and binary forms, with or without
00009 #*  modification, are permitted provided that the following conditions
00010 #*  are met:
00011 #*
00012 #*   * Redistributions of source code must retain the above copyright
00013 #*     notice, this list of conditions and the following disclaimer.
00014 #*   * Redistributions in binary form must reproduce the above
00015 #*     copyright notice, this list of conditions and the following
00016 #*     disclaimer in the documentation and/or other materials provided
00017 #*     with the distribution.
00018 #*   * Neither the name of Willow Garage, Inc. nor the names of its
00019 #*     contributors may be used to endorse or promote products derived
00020 #*     from this software without specific prior written permission.
00021 #*
00022 #*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 #*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 #*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 #*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 #*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 #*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 #*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 #*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 #*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 #*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 #*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 #*  POSSIBILITY OF SUCH DAMAGE.
00034 #* 
00035 #* Author: Felix Duvallet
00036 #***********************************************************
00037 
00038 import subprocess
00039 import unittest
00040 
00041 import rospy
00042 PKG = 'test_tf2'
00043 import roslib; roslib.load_manifest(PKG)
00044 
00045 
00046 class TestStaticPublisher(unittest.TestCase):
00047     """
00048     These tests ensure the static transform publisher dies gracefully when
00049     provided with an invalid (or non-existent) transform parameter.
00050 
00051     These tests are started by the static_publisher.launch, which loads
00052     parameters into the param server.
00053 
00054     We check the output to make sure the correct error is occurring, since the
00055     return code is always -1 (255).
00056 
00057     Note that this *could* cause a problem if a valid TF is stored in the param
00058     server for one of the names; in this case the subprocess would never return
00059     and the test would run forever.
00060     """
00061 
00062     def test_publisher_no_args(self):
00063         # Start the publisher with no argument.
00064         cmd = 'rosrun tf2_ros static_transform_publisher'
00065         with self.assertRaises(subprocess.CalledProcessError) as cm:
00066             ret = subprocess.check_output(
00067                 cmd.split(' '), stderr=subprocess.STDOUT)
00068         self.assertEqual(255, cm.exception.returncode)
00069         self.assertIn('not having the right number of arguments',
00070                       cm.exception.output)
00071 
00072     def test_publisher_nonexistent_param(self):
00073         # Here there is no paramater by that name.
00074         cmd = 'rosrun tf2_ros static_transform_publisher /test_tf2/tf_null'
00075         with self.assertRaises(subprocess.CalledProcessError) as cm:
00076             ret = subprocess.check_output(
00077                 cmd.split(' '), stderr=subprocess.STDOUT)
00078 
00079         self.assertEqual(255, cm.exception.returncode)
00080         self.assertIn('Could not read TF', cm.exception.output)
00081 
00082     def test_publisher_invalid_param(self):
00083         # Here there is an invalid parameter stored in the parameter server.
00084         cmd = 'rosrun tf2_ros static_transform_publisher /test_tf2/tf_invalid'
00085         with self.assertRaises(subprocess.CalledProcessError) as cm:
00086             ret = subprocess.check_output(
00087                 cmd.split(' '), stderr=subprocess.STDOUT)
00088 
00089         self.assertEqual(255, cm.exception.returncode)
00090         self.assertIn('Could not validate XmlRpcC', cm.exception.output)
00091 
00092 
00093 if __name__ == '__main__':
00094     rospy.init_node("test_static_publisher_py")
00095     import rostest
00096     rostest.rosrun(PKG, 'test_static_publisher_py', TestStaticPublisher)


test_tf2
Author(s): Tully Foote, Eitan Marder-Eppstein
autogenerated on Thu Jun 6 2019 20:23:15