$search
00001 #!/usr/bin/env python 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2008, 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$ 00035 00036 import roslib; roslib.load_manifest('test_roslaunch') 00037 00038 import os, sys, unittest 00039 00040 import rostest 00041 import roslaunch.core 00042 import roslaunch.remote 00043 00044 00045 ## Unit tests for roslaunch.remote 00046 class TestRoslaunchRemote(unittest.TestCase): 00047 00048 00049 def test_remote_node_xml(self): 00050 # these are fairly brittle tests, but need to make sure there aren't regressions here 00051 Node = roslaunch.core.Node 00052 n = Node('pkg1', 'type1') 00053 self.assertEquals('<node pkg="pkg1" type="type1" ns="/" args="" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00054 n = Node('pkg2', 'type2', namespace="/ns2/") 00055 self.assertEquals('<node pkg="pkg2" type="type2" ns="/ns2/" args="" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00056 # machine_name should be a noop for remote xml 00057 n = Node('pkg3', 'type3', namespace="/ns3/", machine_name="machine3") 00058 self.assertEquals('<node pkg="pkg3" type="type3" ns="/ns3/" args="" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00059 00060 # test args 00061 n = Node('pkg4', 'type4', args="arg4a arg4b") 00062 self.assertEquals('<node pkg="pkg4" type="type4" ns="/" args="arg4a arg4b" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00063 # test respawn 00064 n = Node('pkg5', 'type5', respawn=True) 00065 self.assertEquals('<node pkg="pkg5" type="type5" ns="/" args="" respawn="True" required="False">\n</node>', n.to_remote_xml()) 00066 n = Node('pkg6', 'type6', respawn=False) 00067 self.assertEquals('<node pkg="pkg6" type="type6" ns="/" args="" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00068 # test remap_args 00069 n = Node('pkg6', 'type6', remap_args=[('from6a', 'to6a'), ('from6b', 'to6b')]) 00070 self.assertEquals("""<node pkg="pkg6" type="type6" ns="/" args="" respawn="False" required="False"> 00071 <remap from="from6a" to="to6a" /> 00072 <remap from="from6b" to="to6b" /> 00073 </node>""", n.to_remote_xml()) 00074 # test env args 00075 n = Node('pkg7', 'type7', env_args=[('key7a', 'val7a'), ('key7b', 'val7b')]) 00076 self.assertEquals("""<node pkg="pkg7" type="type7" ns="/" args="" respawn="False" required="False"> 00077 <env name="key7a" value="val7a" /> 00078 <env name="key7b" value="val7b" /> 00079 </node>""", n.to_remote_xml()) 00080 # test cwd 00081 n = Node('pkg8', 'type8', cwd='ros-root') 00082 self.assertEquals('<node pkg="pkg8" type="type8" ns="/" args="" cwd="ros-root" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00083 n = Node('pkg9', 'type9', cwd='node') 00084 self.assertEquals('<node pkg="pkg9" type="type9" ns="/" args="" cwd="node" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00085 # test output 00086 n = Node('pkg10', 'type10', output='screen') 00087 self.assertEquals('<node pkg="pkg10" type="type10" ns="/" args="" output="screen" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00088 n = Node('pkg11', 'type11', output='log') 00089 self.assertEquals('<node pkg="pkg11" type="type11" ns="/" args="" output="log" respawn="False" required="False">\n</node>', n.to_remote_xml()) 00090 00091 # test launch-prefix 00092 n = Node('pkg12', 'type12', launch_prefix='xterm -e') 00093 self.assertEquals('<node pkg="pkg12" type="type12" ns="/" args="" respawn="False" launch-prefix="xterm -e" required="False">\n</node>', n.to_remote_xml()) 00094 00095 # test required 00096 n = Node('pkg13', 'type13', required=True) 00097 self.assertEquals('<node pkg="pkg13" type="type13" ns="/" args="" respawn="False" required="True">\n</node>', n.to_remote_xml()) 00098 00099 #test everything 00100 n = Node('pkg20', 'type20', namespace="/ns20/", machine_name="foo", remap_args=[('from20a', 'to20a'), ('from20b', 'to20b')], env_args=[('key20a', 'val20a'), ('key20b', 'val20b')], output="screen", cwd="ros-root", respawn=True, args="arg20a arg20b", launch_prefix="nice", required=False) 00101 self.assertEquals("""<node pkg="pkg20" type="type20" ns="/ns20/" args="arg20a arg20b" output="screen" cwd="ros-root" respawn="True" launch-prefix="nice" required="False"> 00102 <remap from="from20a" to="to20a" /> 00103 <remap from="from20b" to="to20b" /> 00104 <env name="key20a" value="val20a" /> 00105 <env name="key20b" value="val20b" /> 00106 </node>""", n.to_remote_xml()) 00107 00108 def test_remote_test_node_xml(self): 00109 Test = roslaunch.core.Test 00110 #TODO: will certainly fail right now 00111 # these are fairly brittle tests, but need to make sure there aren't regressions here 00112 Test = roslaunch.core.Test 00113 n = Test('test1', 'pkg1', 'type1') 00114 self.assertEquals('<test pkg="pkg1" type="type1" ns="/" args="" output="log" required="False" test-name="test1">\n</test>', n.to_remote_xml()) 00115 n = Test('test2', 'pkg2', 'type2', namespace="/ns2/") 00116 self.assertEquals('<test pkg="pkg2" type="type2" ns="/ns2/" args="" output="log" required="False" test-name="test2">\n</test>', n.to_remote_xml()) 00117 # machine_name should be a noop for remote xml 00118 n = Test('test3', 'pkg3', 'type3', namespace="/ns3/", machine_name="machine3") 00119 self.assertEquals('<test pkg="pkg3" type="type3" ns="/ns3/" args="" output="log" required="False" test-name="test3">\n</test>', n.to_remote_xml()) 00120 00121 # test args 00122 n = Test('test4', 'pkg4', 'type4', args="arg4a arg4b") 00123 self.assertEquals('<test pkg="pkg4" type="type4" ns="/" args="arg4a arg4b" output="log" required="False" test-name="test4">\n</test>', n.to_remote_xml()) 00124 # test remap_args 00125 n = Test('test6', 'pkg6', 'type6', remap_args=[('from6a', 'to6a'), ('from6b', 'to6b')]) 00126 self.assertEquals("""<test pkg="pkg6" type="type6" ns="/" args="" output="log" required="False" test-name="test6"> 00127 <remap from="from6a" to="to6a" /> 00128 <remap from="from6b" to="to6b" /> 00129 </test>""", n.to_remote_xml()) 00130 # test env args 00131 n = Test('test7', 'pkg7', 'type7', env_args=[('key7a', 'val7a'), ('key7b', 'val7b')]) 00132 self.assertEquals("""<test pkg="pkg7" type="type7" ns="/" args="" output="log" required="False" test-name="test7"> 00133 <env name="key7a" value="val7a" /> 00134 <env name="key7b" value="val7b" /> 00135 </test>""", n.to_remote_xml()) 00136 # test cwd 00137 n = Test('test8', 'pkg8', 'type8', cwd='ros-root') 00138 self.assertEquals('<test pkg="pkg8" type="type8" ns="/" args="" output="log" cwd="ros-root" required="False" test-name="test8">\n</test>', n.to_remote_xml()) 00139 n = Test('test9', 'pkg9', 'type9', cwd='node') 00140 self.assertEquals('<test pkg="pkg9" type="type9" ns="/" args="" output="log" cwd="node" required="False" test-name="test9">\n</test>', n.to_remote_xml()) 00141 00142 #test everything 00143 n = Test('test20', 'pkg20', 'type20', namespace="/ns20/", machine_name="foo", remap_args=[('from20a', 'to20a'), ('from20b', 'to20b')], env_args=[('key20a', 'val20a'), ('key20b', 'val20b')], cwd="ros-root", args="arg20a arg20b") 00144 self.assertEquals("""<test pkg="pkg20" type="type20" ns="/ns20/" args="arg20a arg20b" output="log" cwd="ros-root" required="False" test-name="test20"> 00145 <remap from="from20a" to="to20a" /> 00146 <remap from="from20b" to="to20b" /> 00147 <env name="key20a" value="val20a" /> 00148 <env name="key20b" value="val20b" /> 00149 </test>""", n.to_remote_xml()) 00150 00151 if __name__ == '__main__': 00152 rostest.unitrun('test_roslaunch', sys.argv[0], TestRoslaunchRemote, coverage_packages=['roslaunch.remote']) 00153