00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import roslib; roslib.load_manifest('test_rosinstall')
00034
00035 import os
00036 import stat
00037 import struct
00038 import sys
00039 import unittest
00040 import subprocess
00041 import tempfile
00042 import urllib
00043 import shutil
00044 import roslib
00045 import rostest
00046
00047 import rosinstall
00048 import rosinstall.helpers
00049
00050 class RosinstallCommandlineTest(unittest.TestCase):
00051
00052 def setUp(self):
00053
00054 self.rosinstall_fn = ["rosrun", "rosinstall", "rosinstall"]
00055
00056
00057 self.directories = {}
00058
00059
00060 def tearDown(self):
00061 for d in self.directories:
00062 shutil.rmtree(self.directories[d])
00063
00064
00065 def test_Rosinstall_executable(self):
00066 cmd = self.rosinstall_fn
00067 print cmd.append("-h")
00068 self.assertEqual(0,subprocess.call(cmd))
00069
00070 def test_Rosinstall_ros(self):
00071 directory = tempfile.mkdtemp()
00072 self.directories["ros"] = directory
00073 cmd = self.rosinstall_fn
00074 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "ros_w_release.rosinstall")])
00075 self.assertEqual(0,subprocess.call(cmd))
00076 shutil.rmtree(directory)
00077 self.directories.pop("ros")
00078
00079 def DISABLED_test_Rosinstall_ros_stack(self):
00080 directory = tempfile.mkdtemp()
00081 self.directories["stack"] = directory
00082 cmd = self.rosinstall_fn
00083 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "distro_stack.rosinstall")])
00084 self.assertEqual(0,subprocess.call(cmd))
00085 shutil.rmtree(directory)
00086 self.directories.pop("stack")
00087
00088 def DISABLED_test_Rosinstall_ros_variant(self):
00089 directory = tempfile.mkdtemp()
00090 self.directories["variant"] = directory
00091 cmd = self.rosinstall_fn
00092 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "distro_variant.rosinstall")])
00093 self.assertEqual(0,subprocess.call(cmd))
00094 shutil.rmtree(directory)
00095 self.directories.pop("variant")
00096
00097
00098 class RosinstallCommandlineOverlays(unittest.TestCase):
00099
00100 def setUp(self):
00101 self.rosinstall_tempfile = tempfile.NamedTemporaryFile(mode='a+b')
00102 self.rosinstall_fn = ["rosrun", "rosinstall", "rosinstall"]
00103
00104
00105
00106 self.directories = {}
00107 self.base = tempfile.mkdtemp()
00108 cmd = self.rosinstall_fn[:]
00109
00110 cmd.extend([self.base, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "ros_w_release.rosinstall")])
00111 self.assertEqual(0,subprocess.call(cmd))
00112
00113
00114 def tearDown(self):
00115 for d in self.directories:
00116 shutil.rmtree(self.directories[d])
00117 shutil.rmtree(self.base)
00118
00119
00120 def test_Rosinstall_rosinstall_file_generation(self):
00121 generated_rosinstall_filename = os.path.join(self.base, ".rosinstall")
00122 self.assertTrue(os.path.exists(generated_rosinstall_filename))
00123 source_yaml = rosinstall.helpers.get_yaml_from_uri(generated_rosinstall_filename)
00124 self.assertEqual(source_yaml,
00125 [{'svn': { 'uri': 'https://code.ros.org/svn/ros/stacks/ros/tags/boxturtle',
00126 'local-name': 'ros'} },
00127 {'svn': { 'uri': 'https://code.ros.org/svn/ros/stacks/ros_release/trunk',
00128 'local-name': 'ros_release'} }
00129 ])
00130
00131
00132
00133
00134 def test_Rosinstall_common_msgs_as_explicit_overlay(self):
00135 self.assertEqual(self.rosinstall_fn, ["rosrun", "rosinstall", "rosinstall"])
00136 directory = tempfile.mkdtemp()
00137 with tempfile.NamedTemporaryFile() as ri_file:
00138 file_text = """
00139 - other:
00140 local-name: %s/ros_release
00141 - other:
00142 local-name: %s/ros
00143 - svn:
00144 uri: https://code.ros.org/svn/ros-pkg/stacks/common_msgs/tags/boxturtle
00145 local-name: stacks/common_msgs
00146 """%(self.base, self.base)
00147 print file_text
00148 ri_file.write(file_text)
00149 ri_file.flush()
00150
00151 self.directories["tutorials"] = directory
00152 cmd = self.rosinstall_fn[:]
00153 cmd.extend([directory, ri_file.name])
00154 print "EXECUTING", cmd
00155 self.assertEqual(0,subprocess.call(cmd))
00156
00157 shutil.rmtree(directory)
00158 self.directories.pop("tutorials")
00159
00160 def test_Rosinstall_ros_tutorial_as_argument(self):
00161 directory = tempfile.mkdtemp()
00162 self.directories["tutorials2"] = directory
00163 cmd = self.rosinstall_fn[:]
00164 cmd.extend([directory, self.base, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "overlay.rosinstall")])
00165 print "Running command %s"%cmd
00166 self.assertEqual(0,subprocess.call(cmd))
00167
00168
00169 shutil.rmtree(directory)
00170 self.directories.pop("tutorials2")
00171
00172 class RosinstallOptionsTest(unittest.TestCase):
00173
00174 def setUp(self):
00175
00176 self.rosinstall_fn = ["rosrun", "rosinstall", "rosinstall"]
00177
00178
00179 self.directories = {}
00180
00181
00182 def tearDown(self):
00183 for d in self.directories:
00184 shutil.rmtree(self.directories[d])
00185
00186
00187
00188 def test_rosinstall_delete_changes(self):
00189 directory = tempfile.mkdtemp()
00190 self.directories["delete"] = directory
00191 cmd = self.rosinstall_fn
00192 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple.rosinstall"), "-n"])
00193 self.assertEqual(0,subprocess.call(cmd))
00194
00195 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple_changed_uri.rosinstall"), "--delete-changed-uri", "-n"])
00196 self.assertEqual(0,subprocess.call(cmd))
00197
00198 shutil.rmtree(directory)
00199 self.directories.pop("delete")
00200
00201 def test_rosinstall_abort_changes(self):
00202 directory = tempfile.mkdtemp()
00203 self.directories["abort"] = directory
00204 cmd = self.rosinstall_fn
00205 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple.rosinstall"), "-n"])
00206 self.assertEqual(0,subprocess.call(cmd))
00207
00208 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple_changed_uri.rosinstall"), "--abort-changed-uri", "-n"])
00209 self.assertEqual(1,subprocess.call(cmd))
00210
00211 shutil.rmtree(directory)
00212 self.directories.pop("abort")
00213
00214 def test_rosinstall_backup_changes(self):
00215 directory = tempfile.mkdtemp()
00216 self.directories["backup"] = directory
00217 cmd = self.rosinstall_fn
00218 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple.rosinstall"), "-n"])
00219 self.assertEqual(0,subprocess.call(cmd))
00220
00221 directory1 = tempfile.mkdtemp()
00222 self.directories["backup1"] = directory1
00223 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple_changed_uri.rosinstall"), "--backup-changed-uri=%s"%directory1, "-n"])
00224 self.assertEqual(0,subprocess.call(cmd))
00225
00226 self.assertEqual(len(os.listdir(directory1)), 1)
00227
00228 shutil.rmtree(directory)
00229 self.directories.pop("backup")
00230 shutil.rmtree(directory1)
00231 self.directories.pop("backup1")
00232
00233
00234 def test_rosinstall_invalid_fail(self):
00235 directory = tempfile.mkdtemp()
00236 self.directories["invalid_fail"] = directory
00237 cmd = self.rosinstall_fn
00238 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "broken.rosinstall"), "-n"])
00239 self.assertEqual(1,subprocess.call(cmd))
00240
00241 shutil.rmtree(directory)
00242 self.directories.pop("invalid_fail")
00243
00244 def test_rosinstall_invalid_continue(self):
00245 directory = tempfile.mkdtemp()
00246 self.directories["invalid_continue"] = directory
00247 cmd = self.rosinstall_fn
00248 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "broken.rosinstall"), "-n", "--continue-on-error"])
00249 self.assertEqual(0,subprocess.call(cmd))
00250
00251 shutil.rmtree(directory)
00252 self.directories.pop("invalid_continue")
00253
00254 def test_rosinstall_change_vcs_type(self):
00255 directory = tempfile.mkdtemp()
00256 self.directories["change_vcs_type"] = directory
00257 cmd = self.rosinstall_fn
00258 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple.rosinstall"), "-n"])
00259 self.assertEqual(0,subprocess.call(cmd))
00260
00261 cmd.extend([directory, os.path.join(roslib.packages.get_pkg_dir("test_rosinstall"), "rosinstalls", "simple_changed_vcs_type.rosinstall"), "--delete-changed-uri", "-n"])
00262 self.assertEqual(0,subprocess.call(cmd))
00263
00264 shutil.rmtree(directory)
00265 self.directories.pop("change_vcs_type")
00266
00267
00268 if __name__ == '__main__':
00269 rostest.unitrun('test_rosinstall', 'test_commandline', RosinstallOptionsTest, coverage_packages=['rosinstall'])
00270 rostest.unitrun('test_rosinstall', 'test_commandline', RosinstallCommandlineTest, coverage_packages=['rosinstall'])
00271 rostest.unitrun('test_rosinstall', 'test_commandline_overlay', RosinstallCommandlineOverlays, coverage_packages=['rosinstall'])
00272