$search
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_rostopic_command_line_online.py 6411 2009-10-02 21:32:01Z kwc $ 00035 00036 PKG = 'test_rostopic' 00037 NAME = 'test_rostopic_command_line_online' 00038 import roslib; roslib.load_manifest(PKG) 00039 00040 import os 00041 import signal 00042 import sys 00043 import time 00044 import unittest 00045 00046 import rospy 00047 import rostest 00048 00049 import std_msgs.msg 00050 00051 from subprocess import Popen, PIPE, check_call, call 00052 00053 def run_for(cmd, secs): 00054 popen = Popen(cmd, stdout=PIPE, stderr=PIPE, close_fds=True) 00055 timeout_t = time.time() + secs 00056 while time.time() < timeout_t: 00057 time.sleep(0.1) 00058 os.kill(popen.pid, signal.SIGKILL) 00059 00060 class TestRostopicOnline(unittest.TestCase): 00061 00062 def setUp(self): 00063 self.vals = set() 00064 self.msgs = {} 00065 00066 ## test that the rosmsg command works 00067 def test_cmd_help(self): 00068 cmd = 'roswtf' 00069 output = Popen([cmd, '-h'], stdout=PIPE).communicate()[0] 00070 self.assert_('Options' in output) 00071 00072 def test_offline(self): 00073 # this test is disabled for now; now that test_roswtf is part 00074 # of ros_comm, the tricks before that were used no longer work 00075 cmd = 'roswtf' 00076 00077 # pass in special test key to roswtf for ROS_PACKAGE_PATH 00078 env = os.environ.copy() 00079 import roslib.stacks 00080 00081 env['ROS_PACKAGE_PATH'] = roslib.stacks.get_stack_dir('ros_comm') 00082 00083 import roslib.packages 00084 cwd = roslib.packages.get_pkg_dir('test_roswtf') 00085 kwds = { 'env': env, 'stdout': PIPE, 'stderr': PIPE, 'cwd': cwd} 00086 00087 # run roswtf nakedly in the test_roswtf directory. Running in 00088 # ROS_ROOT effectively make test_roswtf have dependencies on 00089 # every package in the ROS stack, which doesn't work. 00090 00091 output, err = Popen([cmd], **kwds).communicate() 00092 self.assert_('No errors or warnings' in output, "OUTPUT[%s]\nstderr[%s}"%(output, err)) 00093 self.assert_('ERROR' not in output, "OUTPUT[%s]"%output) 00094 00095 # run roswtf on a simple launch file online 00096 import roslib.packages 00097 p = os.path.join(roslib.packages.get_pkg_dir('test_roswtf'), 'test', 'min.launch') 00098 output = Popen([cmd, p], **kwds).communicate()[0] 00099 self.assert_('No errors or warnings' in output, "OUTPUT[%s]"%output) 00100 self.assert_('ERROR' not in output, "OUTPUT[%s]"%output) 00101 00102 if __name__ == '__main__': 00103 rostest.run(PKG, NAME, TestRostopicOnline, sys.argv)