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
00034
00035 PKG = 'test_rospack'
00036 import roslib; roslib.load_manifest(PKG)
00037
00038 import os
00039 import unittest
00040 import tempfile
00041 import shutil
00042 from subprocess import Popen, PIPE
00043
00044 ROS_ROOT = 'ROS_ROOT'
00045 ROS_PACKAGE_PATH = 'ROS_PACKAGE_PATH'
00046 ROS_LANG_DISABLE = 'ROS_LANG_DISABLE'
00047
00048 _structure_test_p = os.path.abspath('structure_test')
00049
00050 structure_test = {
00051 'package1': 'package1',
00052 'package2': 'package2',
00053 'package3': 'subdir1/package3',
00054 'package4': 'subdir1/subdir1_1/package4',
00055 'package5': 'subdir1/subdir1_1/package5',
00056 'package6': 'subdir3/package6',
00057 'package7': 'subdir3/package7',
00058 }
00059
00060 for k in structure_test.keys():
00061 structure_test[k] = os.path.abspath(os.path.join(_structure_test_p, structure_test[k]))
00062
00063
00064 aliases = {
00065 'deps': 'depends',
00066 'deps1': 'depends1',
00067 'deps-manifests': 'depends-manifests',
00068 'deps-indent': 'depends-indent',
00069 'rosdep': 'rosdeps',
00070 'rosdep0': 'rosdeps0'
00071 }
00072
00073
00074 initial_cwd = os.getcwd()
00075
00076
00077 class RospackTestCase(unittest.TestCase):
00078
00079
00080
00081 def _run_rospack(self, ros_root, ros_package_path, pkgname, command):
00082 env = os.environ.copy()
00083 if ros_root is not None:
00084 env[ROS_ROOT] = ros_root
00085 else:
00086 del env[ROS_ROOT]
00087 if ros_package_path is not None:
00088 env[ROS_PACKAGE_PATH] = ros_package_path
00089 elif ROS_PACKAGE_PATH in env:
00090 del env[ROS_PACKAGE_PATH]
00091
00092
00093
00094
00095 args = ["rospack"]
00096 if command:
00097 for s in command.split():
00098 args.append(s)
00099 if pkgname is not None:
00100 args.append(pkgname)
00101 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00102 stdout, stderr = p.communicate()
00103
00104
00105
00106 if command:
00107 cmd = command.split()[-1]
00108 if cmd in aliases:
00109 args[-2] = aliases[cmd]
00110 alias_p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00111 alias_stdout, alias_stderr = alias_p.communicate()
00112 self.assertEquals(p.returncode, alias_p.returncode)
00113 self.assertEquals(stdout, alias_stdout)
00114
00115
00116
00117
00118
00119 if p.returncode < 0:
00120
00121
00122
00123 os.chdir(initial_cwd)
00124 self.fail('rospack returned non-zero exit code, indicating a crash')
00125
00126 return p.returncode, stdout.strip(), stderr
00127
00128
00129
00130
00131
00132
00133 def run_rospack(self, pkgname, command):
00134 ros_root = os.path.abspath('test')
00135 return self._run_rospack(ros_root, None, pkgname, command)[1]
00136
00137
00138 def erun_rospack(self, ros_root, ros_package_path, pkgname, command):
00139 return self._run_rospack(ros_root, ros_package_path, pkgname, command)[1]
00140
00141
00142
00143 def run_rospack_status(self, pkgname, command):
00144 ros_root = os.path.abspath('test')
00145 return self._run_rospack(ros_root, None, pkgname, command)[0]
00146
00147
00148 def erun_rospack_status(self, ros_root, ros_package_path, pkgname, command):
00149 return self._run_rospack(ros_root, ros_package_path, pkgname, command)[0]
00150
00151
00152 def rospack_fail(self, package, command):
00153 ros_root = os.path.abspath('test')
00154 code, stdout, stderr = self._run_rospack(ros_root, None, package, command)
00155 self.assertNotEquals(0, code, "rospack [%s %s] should have failed. \n\nstdout[%s] \n\nstderr[%s]"%(command, package, stdout, stderr))
00156
00157
00158 def erospack_fail(self, ros_root, ros_package_path, package, command):
00159 code, stdout, stderr = self._run_rospack(ros_root, ros_package_path, package, command)
00160 self.assertNotEquals(0, code, "rospack [%s %s] should have failed instead of returning status code 0. \n\nstdout[%s] \n\nstderr[%s]"%(command, package, stdout, stderr))
00161
00162
00163 def rospack_succeed(self, package, command):
00164 ros_root = os.path.abspath('test')
00165 status_code, stdout, stderr = self._run_rospack(ros_root, None, package, command)
00166 self.assertEquals(0, status_code, '"rospack %s %s" failed with status code [%s] instead of succeeding with [0]. \n\nstdout[%s] \n\nstderr[%s]'%(command, package, status_code, stdout, stderr))
00167
00168
00169 def erospack_succeed(self, ros_root, ros_package_path, package, command):
00170 status_code, stdout, stderr = self._run_rospack(ros_root, ros_package_path, package, command)
00171 self.assertEquals(0, status_code, "rospack [%s %s, env ROS_ROOT=%s ROS_PACKAGE_PATH=%s] failed with status code [%s] instead of succeeding with [0]. \n\nstdout[%s] \n\nstderr[%s]"%(command, package, ros_root, ros_package_path, status_code, stdout, stderr))
00172
00173
00174
00175 def check_ordered_list(self, command, tests):
00176 for retlist, package in tests:
00177 expected = set(retlist)
00178 self.rospack_succeed(package, command)
00179 retval = self.strip_opt_ros(self.run_rospack(package, command))
00180 retactual = [v for v in retval.split('\n') if v]
00181 self.failIf(set(retlist) ^ set(retactual), "rospack %s %s failed: [%s] vs [%s]"%(command, package, retlist, retactual))
00182 self.assertEquals('\n'.join(retlist), '\n'.join(retactual))
00183
00184
00185
00186
00187 def echeck_ordered_list(self, command, tests):
00188 for retlist, ros_root, ros_package_path, package in tests:
00189 expected = set(retlist)
00190 self.erospack_succeed(ros_root, ros_package_path, package, command)
00191 retval = self.erun_rospack(ros_root, ros_package_path, package, command)
00192 retactual = [v for v in retval.split('\n') if v]
00193 self.failIf(set(retlist) ^ set(retactual), "[env %s %s] rospack %s %s failed: [%s] vs [%s]"%(ros_root, ros_package_path, command, package, retlist, retactual))
00194
00195
00196 def check_unordered_list(self, command, tests):
00197 for retlist, package in tests:
00198 expected = set(retlist)
00199 self.rospack_succeed(package, command)
00200 retval = self.run_rospack(package, command)
00201 retactual = [v for v in retval.split('\n') if v]
00202 self.failIf(set(retlist) ^ set(retactual), "rospack %s %s failed: [%s] vs [%s]"%(command, package, retlist, retactual))
00203
00204
00205
00206 def echeck_unordered_list(self, command, tests):
00207 for retlist, ros_root, ros_package_path, package in tests:
00208 expected = set(retlist)
00209 self.erospack_succeed(ros_root, ros_package_path, package, command)
00210 retval = self.erun_rospack(ros_root, ros_package_path, package, command)
00211 retactual = [v for v in retval.split('\n') if v]
00212 self.failIf(set(retlist) ^ set(retactual), "rospack %s %s failed: [%s] vs [%s]"%(command, package, retlist, retactual))
00213
00214
00215
00216
00217
00218 def test_no_option(self):
00219 self.rospack_succeed(None, None)
00220
00221 def test_fake_option(self):
00222 self.rospack_fail("deps", "--fake deps")
00223
00224 def test_invalid_option(self):
00225 self.rospack_fail("deps", "deps --lang=cpp --attrib=flags")
00226 self.rospack_fail("deps", "deps --lang=cpp")
00227 self.rospack_fail("deps", "deps --attrib=lflags")
00228 self.rospack_fail("base", "export --lang=cpp --attrib=cflags --top=")
00229 self.rospack_fail(None, "profile --length=")
00230 self.rospack_fail(None, "deps --length=10")
00231 self.rospack_fail(None, "deps --zombie-only")
00232 self.rospack_fail(None, "profile --deps-only")
00233
00234 def test_ros_cache_timeout(self):
00235 env = os.environ.copy()
00236 os.environ['ROS_CACHE_TIMEOUT'] = '0'
00237 self.rospack_succeed(None, "profile")
00238 os.environ['ROS_CACHE_TIMEOUT'] = '-1'
00239 self.rospack_succeed(None, "profile")
00240 import time
00241 time.sleep(0.1)
00242 os.environ['ROS_CACHE_TIMEOUT'] = '.001'
00243 self.rospack_succeed(None, "profile")
00244 os.environ = env
00245
00246 def test_profile(self):
00247
00248 self.rospack_succeed(None, "profile --zombie-only")
00249
00250 self.rospack_succeed(None, "profile --length=10")
00251
00252 def test_ros_home(self):
00253 env = os.environ.copy()
00254
00255
00256 d = tempfile.mkdtemp()
00257 os.environ['ROS_HOME'] = d
00258 self.rospack_succeed(None, "profile")
00259 self.assertEquals(True, os.path.exists(os.path.join(d,'rospack_cache')))
00260
00261 shutil.rmtree(d)
00262 self.rospack_succeed(None, "profile")
00263 self.assertEquals(True, os.path.exists(os.path.join(d,'rospack_cache')))
00264
00265 del os.environ['ROS_HOME']
00266 os.environ['HOME'] = d
00267 self.rospack_succeed(None, "profile")
00268 cache_path = os.path.join(d,'.ros','rospack_cache')
00269 self.assertEquals(True, os.path.exists(cache_path))
00270
00271 f = open(cache_path, 'w')
00272 f.write('#SOMETHING\n')
00273 f.close()
00274 self.rospack_succeed(None, "list")
00275
00276 os.unlink(cache_path)
00277 self.rospack_succeed(None, "profile")
00278 self.assertEquals(True, os.path.exists(cache_path))
00279
00280 shutil.rmtree(os.path.join(d,'.ros'))
00281 os.chmod(d, 0000)
00282 self.rospack_succeed(None, "profile")
00283
00284
00285
00286 if os.path.exists(os.path.join(d,'.ros')):
00287 shutil.rmtree(os.path.join(d,'.ros'))
00288
00289 os.chmod(d, 0700)
00290 f = open(os.path.join(d,'.ros'), 'w')
00291 f.close()
00292 self.rospack_succeed(None, "profile")
00293
00294 del os.environ['HOME']
00295 self.rospack_succeed(None, "profile")
00296
00297
00298 shutil.rmtree(d)
00299 os.environ = env
00300
00301 def test_no_package_allowed(self):
00302 self.rospack_succeed(None, "help")
00303 self.rospack_succeed(None, "profile")
00304 self.rospack_succeed(None, "list")
00305 self.rospack_succeed(None, "list-names")
00306 self.rospack_succeed(None, "list-duplicates")
00307 self.rospack_succeed(None, "langs")
00308
00309 def test_no_package_allowed_bad(self):
00310 self.rospack_fail("deps", "help")
00311 self.rospack_fail("deps", "profile")
00312 self.rospack_fail("deps", "list")
00313 self.rospack_fail("deps", "list-names")
00314 self.rospack_fail("deps", "list-duplicates")
00315 self.rospack_fail("deps", "langs")
00316
00317 def test_invalid_option_order(self):
00318 self.rospack_fail("deps", "--lang=cpp --attrib=lflags export")
00319 self.rospack_fail("deps", "--lang=cpp export --attrib=lflags")
00320 self.rospack_fail("deps", "--deps-only cflags-only-I")
00321
00322 def test_export_bad(self):
00323 self.rospack_fail("base", "export --lang= --attrib=lflags")
00324 self.rospack_fail("base", "export --lang=cpp --attrib=")
00325 self.rospack_fail("base", "export --attrib=lflags")
00326 self.rospack_fail("base", "export --lang=cpp")
00327 self.rospack_fail("base", "export --lang=cpp --lang=python --attrib=lflags")
00328 self.rospack_fail("base", "export --lang=cpp --attrib=lflags --attrib=cflags")
00329 self.rospack_fail("base", "export --lang=cpp --attrib=cflags --top=foo")
00330
00331 def test_plugins_bad(self):
00332 self.rospack_fail("base", "plugins")
00333 self.rospack_fail("base", "plugins --lang=cpp")
00334 self.rospack_fail("base", "plugins --attrib=")
00335 self.rospack_fail("base", "plugins --top=foo")
00336
00337 def test_rosdep(self):
00338 self.rospack_succeed("base", "rosdep")
00339 self.assertEquals("name: foo", self.run_rospack("base", "rosdep"))
00340 self.rospack_succeed("deps", "rosdep0")
00341 self.assertEquals("name: bar", self.run_rospack("deps", "rosdep0"))
00342 self.check_unordered_list("rosdep", [(["name: foo", "name: bar"], "deps")])
00343
00344
00345
00346
00347 def test_export_cpp(self):
00348 package = 'base'
00349 tests = [("-lfoo", "export --lang=cpp --attrib=lflags"),
00350 ("-lfoo", "export --attrib=lflags --lang=cpp"),
00351 ("-Isomething", "export --lang=cpp --attrib=cflags"),
00352 ("-Isomething", "export --attrib=cflags --lang=cpp"),
00353 ]
00354 for retval, arg in tests:
00355 self.rospack_succeed(package, arg)
00356 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00357 self.assertEquals("-lfoo -lbar", self.strip_opt_ros(self.run_rospack("deps", "export --lang=cpp --attrib=lflags --deps-only")))
00358
00359
00360 def test_export_roslang(self):
00361 package = 'base'
00362 tests = [("something.cmake", "export --lang=roslang --attrib=cmake")]
00363 for retval, arg in tests:
00364 self.rospack_succeed(package, arg)
00365 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00366
00367 def test_export_non_existent_attrib(self):
00368 self.rospack_succeed("base", "export --lang=cpp --attrib=fake")
00369 self.failIf(self.run_rospack("base", "export --lang=cpp --attrib=fake"))
00370
00371
00372
00373
00374 def test_plugins(self):
00375 tests = [(["deps foo.cmake", "plugins bat.cmake"], "base")]
00376 self.check_unordered_list("plugins --attrib=cmake", tests)
00377
00378 package = 'base'
00379 tests = [("deps foo.cmake", "plugins --attrib=cmake --top=deps")]
00380 for retval, arg in tests:
00381 self.rospack_succeed(package, arg)
00382 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00383 package = 'base_two'
00384 tests = [("deps bar.cmake", "plugins --attrib=cmake")]
00385 for retval, arg in tests:
00386 self.rospack_succeed(package, arg)
00387 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00388
00389
00390
00391
00392 def test_no_ros_root(self):
00393 testp = os.path.abspath('test')
00394 self.erospack_fail(None, testp, "deps", "deps")
00395
00396 def test_bad_ros_root(self):
00397
00398 non_existent1 = os.path.abspath('non_existent1')
00399 testp = os.path.abspath("test")
00400 self.assertNotEquals(0, self.erun_rospack_status(non_existent1, testp, "deps", "deps"))
00401
00402
00403 def test_ros_root_ros_package_path_identical(self):
00404
00405
00406 testp = os.path.abspath('test')
00407 tests = [
00408 (["base", "base_two"], testp, testp, "deps"),
00409 ]
00410 self.echeck_ordered_list("deps", tests)
00411
00412
00413 def test_empty_ros_package_path(self):
00414 testp = os.path.abspath('test')
00415 tests = [
00416 (["base", "base_two"], testp, '', "deps"),
00417 ]
00418 self.echeck_ordered_list("deps", tests)
00419
00420
00421 def test_ros_package_path_precedence(self):
00422 teste = os.path.abspath('test_empty')
00423 testp = os.path.abspath('test')
00424 test2p = os.path.abspath('test2')
00425 testp_roslang = os.path.join(testp, 'roslang')
00426 test2p_roslang = os.path.join(test2p, 'roslang')
00427 tests = [([testp_roslang], teste, ':'.join([testp, test2p]), "roslang"),
00428 ([testp_roslang], teste, ':'.join([testp, test2p_roslang]), "roslang"),
00429 ([testp_roslang], teste, ':'.join([testp_roslang, test2p]), "roslang"),
00430 ([testp_roslang], teste, ':'.join([testp_roslang, test2p_roslang]), "roslang")]
00431 self.echeck_unordered_list('find', tests)
00432
00433
00434 def test_ros_package_path_precedence_1(self):
00435 testp = os.path.abspath('test')
00436 test2p = os.path.abspath('test2')
00437 test3p = os.path.abspath('test3')
00438 tests = [
00439 (["test"], testp, test2p, "precedence1"),
00440 (["test2"], test2p, testp, "precedence1"),
00441 (["test2"], testp, "%s:%s"%(test2p, test3p), "precedence2"),
00442 (["test3"], testp, "%s:%s"%(test3p, test2p), "precedence2"),
00443 ]
00444 self.echeck_ordered_list('libs-only-l', tests)
00445
00446
00447 def test_list_duplicates(self):
00448 testp = os.path.abspath('test')
00449 test2p = os.path.abspath('test2')
00450 test3p = os.path.abspath('test3')
00451 self.erospack_succeed(testp, None, None, 'list-duplicates')
00452 self.erospack_fail(testp, '%s:%s'%(test2p,test3p), None, 'list-duplicates')
00453
00454
00455 def test_ros_package_path_direct_package(self):
00456 testp = os.path.abspath('test')
00457 test2p = os.path.abspath('test2')
00458 test3p = os.path.abspath('test3')
00459
00460 rpp = ':'.join([os.path.join(test2p, 'precedence2'),os.path.join(test3p, 'precedence3')])
00461 tests = [
00462 (["test2"], testp, rpp, "precedence2"),
00463 (["test3"], testp, rpp, "precedence3"),
00464 ]
00465 self.echeck_ordered_list('libs-only-l', tests)
00466
00467 def test_ros_package_path_colons(self):
00468
00469 testp = os.path.abspath('test')
00470 test2p = os.path.abspath('test2')
00471
00472 test3p = os.path.abspath('test3') + '/'
00473 tests = [
00474 (["base","base_two"], testp, "::%s:::"%testp, "deps"),
00475 (["base","base_two"], testp, "::", "deps"),
00476 ]
00477 self.echeck_ordered_list('deps', tests)
00478 tests = [
00479 (["test"], testp, ":::%s:"%test2p, "precedence1"),
00480 (["test2"],testp, "::%s::%s::"%(test2p,test3p), "precedence2"),
00481 ]
00482 self.echeck_ordered_list("libs-only-l", tests)
00483
00484 def test_ros_package_path_bad_paths(self):
00485 testp = os.path.abspath('test')
00486 test2p = os.path.abspath('test2')
00487 non_existentp = os.path.abspath('test')
00488 tests = [
00489 (["test"], testp, non_existentp, "precedence1"),
00490 (["test2"],testp, ":%s:%s"%(non_existentp, test2p), "precedence2"),
00491 (["test2"],testp, ":%s:%s"%(test2p, non_existentp), "precedence2"),
00492 ]
00493 self.echeck_ordered_list("libs-only-l", tests)
00494
00495
00496 def test_ros_in_package(self):
00497 pwd = os.getcwd()
00498 ros_root = os.path.join(pwd, 'test')
00499 os.chdir(os.path.abspath(os.path.join('test', 'deps')))
00500 self.erospack_succeed(ros_root, None, None, 'depends1')
00501 self.echeck_unordered_list('depends1', [(["base", "base_two"], ros_root, None, None)])
00502
00503 d = tempfile.mkdtemp()
00504 os.chdir(d)
00505 os.rmdir(d)
00506 self.erospack_fail(ros_root, None, None, 'depends1')
00507 os.chdir(pwd)
00508
00509
00510
00511
00512 def _rospack_list(self, ros_root, ros_package_path):
00513 env = os.environ.copy()
00514 if ros_root is not None:
00515 env[ROS_ROOT] = ros_root
00516 else:
00517 del env[ROS_ROOT]
00518 if ros_package_path is not None:
00519 env[ROS_PACKAGE_PATH] = ros_package_path
00520 elif ROS_PACKAGE_PATH in env:
00521 del env[ROS_PACKAGE_PATH]
00522 args = ["rospack", 'list']
00523 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00524 retval = p.communicate()[0]
00525 return p.returncode, retval.strip()
00526
00527 def _check_rospack_list(self, expected, retval):
00528 lines = [l for l in retval.split('\n') if l]
00529 packages = [l[:l.find(' ')] for l in lines]
00530
00531 paths = [os.path.abspath(l[l.find(' ')+1:]) for l in lines]
00532 result = {}
00533 for pack, path in zip(packages, paths):
00534 result[pack] = os.path.abspath(path)
00535 self.failIf(set(expected.keys()) ^ set(packages), "package lists do not match (expected vs. actual): %s vs %s"%(expected.keys(), packages))
00536 for pack,path in expected.iteritems():
00537 self.assertEquals(path, result[pack])
00538
00539
00540 def test_rospack_list_empty(self):
00541 rr = os.path.abspath('test_empty')
00542 retcode, retval = self._rospack_list(rr, None)
00543 self.assertEquals(0, retcode)
00544 self.failIf(retval, "rospack list on empty directory returned value %s"%retval)
00545
00546
00547 def test_rospack_depends_on_not_a_package(self):
00548 pwd = os.getcwd()
00549 ros_root = os.path.abspath('test')
00550 os.chdir(os.path.abspath('test_empty'))
00551 self.erospack_fail(ros_root, None, None, 'depends-on1')
00552 os.chdir(pwd)
00553
00554
00555 def test_rospack_list_dups(self):
00556
00557 rr = os.path.abspath('structure_test')
00558 retcode, retval = self._rospack_list(rr, None)
00559 self.assertEquals(0, retcode)
00560 retcode2, retval2 = self._rospack_list(rr, rr)
00561 self.assertEquals(0, retcode2)
00562 self.assertEquals(retval, retval2, "rospack list did not remove duplicates")
00563
00564 def test_rospack_list_no_rpp(self):
00565 rr = os.path.abspath('structure_test')
00566 expected = structure_test.copy()
00567 retcode, retval = self._rospack_list(rr, None)
00568 self.assertEquals(0, retcode)
00569 self._check_rospack_list(expected, retval)
00570
00571
00572
00573
00574
00575
00576
00577 def _rospack_list_names(self, ros_root, ros_package_path):
00578 env = os.environ.copy()
00579 if ros_root is not None:
00580 env[ROS_ROOT] = ros_root
00581 else:
00582 del env[ROS_ROOT]
00583 if ros_package_path is not None:
00584 env[ROS_PACKAGE_PATH] = ros_package_path
00585 elif ROS_PACKAGE_PATH in env:
00586 del env[ROS_PACKAGE_PATH]
00587 args = ["rospack", 'list-names']
00588 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00589 retval = p.communicate()[0]
00590 return p.returncode, retval.strip()
00591
00592
00593 def test_rospack_list_names_empty(self):
00594 rr = os.path.abspath('test_empty')
00595 retcode, retval = self._rospack_list_names(rr, None)
00596 self.assertEquals(0, retcode)
00597 self.failIf(retval, "rospack list-names on empty directory returned value %s"%retval)
00598
00599
00600 def test_rospack_list_names_dups(self):
00601
00602 rr = os.path.abspath('structure_test')
00603 retcode, retval = self._rospack_list_names(rr, None)
00604 self.assertEquals(0, retcode)
00605 retcode2, retval2 = self._rospack_list_names(rr, rr)
00606 self.assertEquals(0, retcode2)
00607 self.assertEquals(retval, retval2, "rospack list-names did not remove duplicates")
00608
00609 def test_rospack_list_names_no_rpp(self):
00610 rr = os.path.abspath('structure_test')
00611 expected = set(structure_test.copy().keys())
00612 retcode, retval = self._rospack_list_names(rr, None)
00613 self.assertEquals(0, retcode)
00614 self.assertEquals(expected, set(retval.split()))
00615
00616
00617
00618
00619
00620
00621
00622
00623 def test_rospack_find_fail(self):
00624 rr = os.path.abspath('test_empty')
00625 self.erospack_fail(rr, None, 'package', 'find')
00626
00627
00628 def test_rospack_find_direct(self):
00629 testp = os.path.abspath('test')
00630 package1p = os.path.abspath(os.path.join('structure_test', 'package1'))
00631 self.erospack_succeed(testp, package1p, 'package1', 'find')
00632 self.assertEquals(package1p, self.erun_rospack(testp, package1p, 'package1', 'find'))
00633
00634
00635
00636 def test_rospack_find_direct_with_rospack_nosubdirs(self):
00637 testp = os.path.abspath('test')
00638 package2p = os.path.abspath(os.path.join('structure_test', 'package2'))
00639 self.erospack_succeed(testp, package2p, 'package2', 'find')
00640 self.assertEquals(package2p, self.erun_rospack(testp, package2p, 'package2', 'find'))
00641
00642 def test_rospack_find_no_rpp(self):
00643 rr = os.path.abspath('structure_test')
00644 expected = structure_test.copy()
00645 for package,path in expected.iteritems():
00646 self.erospack_succeed(rr, None, package, 'find')
00647 self.assertEquals(path, os.path.abspath(self.erun_rospack(rr, None, package, 'find')))
00648
00649
00650
00651
00652
00653
00654
00655 def test_deps(self):
00656 depth_list = ['depth-%s'%i for i in xrange(1, 101)]
00657 depth_list.reverse()
00658 tests = [
00659 (["base","base_two"], "deps"),
00660 (["base","base_two","deps"], "deps_higher"),
00661 (["base","base_two","deps","deps_higher"],"deps_dup"),
00662 (depth_list, "depth-0")
00663 ]
00664 self.check_ordered_list('deps', tests)
00665
00666 def test_deps1(self):
00667 tests = [
00668 (["base","base_two"], "deps"),
00669 (["deps"], "deps_higher"),
00670 (["depth-1"], "depth-0"),
00671 (["depth-99"], "depth-98"),
00672 ]
00673 self.check_ordered_list('deps1',tests)
00674
00675 def test_deps_invalid(self):
00676 self.rospack_fail("deps_invalid", "deps")
00677
00678 def test_depends_on(self):
00679 depth_list = ['depth-%s'%i for i in xrange(0, 100)]
00680 depth_list.reverse()
00681
00682 self.rospack_succeed("deps", "depends-on")
00683 tests = [
00684 (["plugins", "deps_dup", "deps", "deps_higher"], "base"),
00685 (["deps_higher","deps_dup"], "deps"),
00686 ([], "depth-0"),
00687 (depth_list, "depth-100"),
00688 ]
00689 self.check_unordered_list("depends-on", tests)
00690
00691 def test_depends_on1(self):
00692
00693 self.rospack_succeed("deps", "depends-on")
00694 tests = [
00695 (["deps_higher"], "deps"),
00696 (["deps", "deps_dup", "plugins"], "base"),
00697 (["deps", "deps_dup"], "base_two"),
00698 ]
00699 self.check_unordered_list("depends-on1", tests)
00700
00701 def test_depends_on_nonexistent(self):
00702 self.rospack_fail("deps", "deps_nonexistent")
00703 self.rospack_fail("deps", "nonexistentpackage")
00704 tests = [
00705 (["deps_nonexistent"], "nonexistentpackage"),
00706 ]
00707 self.check_ordered_list("depends-on", tests)
00708
00709 def test_lflags_base(self):
00710 self.rospack_succeed("base", "libs-only-l")
00711 self.assertEquals("foo", self.run_rospack("base", "libs-only-l"))
00712
00713 def test_circular(self):
00714 testp = os.path.abspath("test")
00715 self.erospack_fail(testp, os.path.abspath("test_circular/cycle0"), "self_ref", "deps")
00716 self.erospack_fail(testp, os.path.abspath("test_circular/cycle1"), "friend1", "deps")
00717 self.erospack_fail(testp, os.path.abspath("test_circular/cycle1"), "friend2", "deps")
00718 self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend1", "deps")
00719 self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend2", "deps")
00720 self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend3", "deps")
00721
00722
00723
00724 self.erospack_succeed(testp, os.path.abspath("test_circular/cycle2"), "friend3", "depends-on")
00725
00726 def test_lflags_backquote(self):
00727 self.rospack_succeed("backquote", "libs-only-l")
00728 self.assertEquals("loki foo backquote", self.run_rospack("backquote", "libs-only-l"))
00729
00730 def test_backquote_invalid(self):
00731 self.rospack_fail("backquote_invalid", "libs-only-other")
00732
00733
00734 def strip_opt_ros(self, flags):
00735 prefix = '/opt/ros'
00736 if 'ROS_BINDEPS_PATH' in os.environ:
00737 prefix = os.environ['ROS_BINDEPS_PATH']
00738 tostrip = [prefix + '/lib',
00739 prefix + '/include',
00740 '-L' + prefix + '/lib',
00741 '-I' + prefix + '/include',
00742 '-Wl,-rpath,' + prefix + '/lib']
00743 res = ''
00744 for f in flags.split(' '):
00745 if f and f not in tostrip:
00746 if len(res) > 0:
00747 res += ' '
00748 res += f
00749 return res
00750
00751 def test_Lflags_backquote(self):
00752 self.rospack_succeed("backquote", "libs-only-L")
00753 self.assertEquals("odin", self.strip_opt_ros(self.run_rospack("backquote", "libs-only-L")))
00754
00755 def test_cflags_backquote(self):
00756 self.rospack_succeed("backquote", "cflags-only-I")
00757 self.assertEquals("blah backquote", self.strip_opt_ros(self.run_rospack("backquote", "cflags-only-I")))
00758
00759 def test_lflags_archive(self):
00760 self.rospack_succeed("lflags_with_archive_lib", "libs-only-l")
00761 self.assertEquals("/usr/lib/libfoo.a", self.run_rospack("lflags_with_archive_lib", "libs-only-l"))
00762 self.rospack_succeed("lflags_with_archive_lib", "libs-only-other")
00763 self.assertEquals("/a/bad/flag", self.run_rospack("lflags_with_archive_lib", "libs-only-other"))
00764
00765 def test_lflags_deps(self):
00766 self.rospack_succeed("deps", "libs-only-l")
00767 self.assertEquals("loki foo bar", self.run_rospack("deps", "libs-only-l"))
00768
00769 def test_lflags_deps_only(self):
00770 self.rospack_succeed("deps", "libs-only-l --deps-only")
00771 self.assertEquals("foo bar", self.run_rospack("deps", "libs-only-l --deps-only"))
00772
00773 def test_empty_lflags(self):
00774 tests = [([], "deps_empty")]
00775 commands = ["libs-only-l", "libs-only-L", "libs-only-other"]
00776 for c in commands:
00777 self.check_ordered_list(c, tests)
00778
00779 def test_empty_cflags(self):
00780 tests = [([], "deps_empty")]
00781 commands = ["cflags-only-I", "cflags-only-other"]
00782 for c in commands:
00783 self.check_ordered_list(c, tests)
00784
00785 def test_empty_vcs(self):
00786 self.rospack_succeed("empty", "vcs0")
00787 self.assertEquals("type: \turl:", self.run_rospack("empty", "vcs0"))
00788 self.rospack_succeed("deps_empty", "vcs")
00789 self.assertEquals("type: svn\turl: \ntype: \turl:", self.run_rospack("deps_empty", "vcs"))
00790
00791 def test_vcs_no_type_or_url(self):
00792 self.rospack_succeed("vc_no_type_or_url", "vcs0")
00793 self.assertEquals("", self.run_rospack("vc_no_type_or_url", "vcs0"))
00794
00795 def test_lflags_no_package_attrib(self):
00796 self.rospack_fail("no_package_attribute", "libs-only-l")
00797
00798 def test_lflags_invalid(self):
00799 self.rospack_fail("invalid", "libs-only-l")
00800
00801 def test_vcs_invalid(self):
00802 self.rospack_fail("invalid", "vcs")
00803
00804 def test_deps1_invalid(self):
00805 self.rospack_fail("invalid", "deps1")
00806
00807 def test_vcs0_deps(self):
00808 self.rospack_succeed("deps", "vcs0")
00809 self.failIf(self.run_rospack("deps", "vcs0"))
00810
00811 def test_vcs_deps(self):
00812 self.rospack_succeed("deps", "vcs")
00813 self.assertEquals("type: svn\turl: https://ros.svn.sourceforge.net/svnroot/ros/trunk\n"+
00814 "type: svn\turl: https://ros.svn.sourceforge.net/svnroot/ros/branches", self.run_rospack("deps", "vcs"))
00815
00816 def test_deps_manifests(self):
00817 self.rospack_succeed("deps", "deps-manifests")
00818 testp = os.path.abspath('test')
00819 expected = os.path.join(testp, 'base/manifest.xml') + ' ' + os.path.join(testp, 'base_two/manifest.xml')
00820 self.assertEquals(expected,
00821 self.run_rospack("deps", "deps-manifests"))
00822
00823 def test_deps_indent(self):
00824 self.rospack_succeed("deps_higher", "deps-indent")
00825 testp = os.path.abspath('test')
00826 expected = 'deps\n base\n base_two'
00827 self.assertEquals(expected,
00828 self.run_rospack("deps_higher", "deps-indent"))
00829
00830 def _rospack_langs(self, ros_root, ros_package_path, ros_lang_disable):
00831 env = os.environ.copy()
00832 if ros_root is not None:
00833 env[ROS_ROOT] = ros_root
00834 else:
00835 del env[ROS_ROOT]
00836 if ros_package_path is not None:
00837 env[ROS_PACKAGE_PATH] = ros_package_path
00838 elif ROS_PACKAGE_PATH in env:
00839 del env[ROS_PACKAGE_PATH]
00840 if ros_lang_disable is not None:
00841 env[ROS_LANG_DISABLE] = ros_lang_disable
00842 elif ROS_LANG_DISABLE in env:
00843 del env[ROS_LANG_DISABLE]
00844 args = ["rospack", 'langs']
00845 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00846 retval = p.communicate()[0]
00847 return p.returncode, retval.strip()
00848
00849 def test_langs(self):
00850 rr = os.path.abspath('test')
00851 retcode, retval = self._rospack_langs(rr, None, None)
00852 self.assertEquals(0, retcode)
00853
00854 l = retval.split()
00855 s = set(l)
00856 expected = set(['rosfoo', 'rosbar'])
00857 self.assertEquals(s, expected)
00858
00859 def test_langs_disable(self):
00860 rr = os.path.abspath('test')
00861 disable = 'rosfoo'
00862 retcode, retval = self._rospack_langs(rr, None, disable)
00863 self.assertEquals(0, retcode)
00864
00865 l = retval.split()
00866 s = set(l)
00867 expected = set(['rosbar'])
00868 self.assertEquals(s, expected)
00869
00870 def test_langs_empty(self):
00871 rr = os.path.abspath('test2')
00872 retcode, retval = self._rospack_langs(rr, None, None)
00873 self.assertEquals(0, retcode)
00874 self.failIf(retval, "rospack langs on empty directory returned value %s"%retval)
00875
00876
00877 def test_msg_gen(self):
00878 test_path = os.path.abspath('test')
00879 pkgs = ['msg_gen_no_export', 'msg_gen_no_cpp', 'msg_gen_no_cflags']
00880 for p in pkgs:
00881 self.rospack_succeed(p, "cflags-only-I")
00882 self.assertEquals(os.path.join(test_path, p, "msg_gen/cpp/include"), self.strip_opt_ros(self.run_rospack(p, "cflags-only-I")))
00883
00884
00885 def test_quiet_option(self):
00886 ros_root = os.path.abspath('test')
00887
00888
00889 status_code, stdout, stderr = self._run_rospack(ros_root, None, 'nonexistentpackage', 'find -q')
00890 self.assertNotEquals(0, status_code)
00891 self.assertEquals(0, len(stderr))
00892
00893
00894 status_code, stdout, stderr = self._run_rospack(ros_root, None, 'nonexistentpackage', 'find')
00895 self.assertNotEquals(0, status_code)
00896 self.assertNotEquals(0, len(stderr))
00897
00898 if __name__ == "__main__":
00899 import rosunit
00900 rosunit.unitrun(PKG, 'rospack_exe_process', RospackTestCase)