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 cache_path = os.path.join(d,'rospack_cache')
00259 self.rospack_succeed(None, "profile")
00260 self.assertEquals(True, os.path.exists(cache_path))
00261
00262 shutil.rmtree(d)
00263 self.rospack_succeed(None, "profile")
00264 self.assertEquals(True, os.path.exists(cache_path))
00265
00266 f = open(cache_path, 'w')
00267 f.write('#SOMETHING\n')
00268 f.close()
00269 self.rospack_succeed(None, "list")
00270
00271 os.chmod(d, 0000)
00272 self.rospack_succeed(None, "profile")
00273
00274
00275
00276 if os.path.exists(d):
00277 os.chmod(d, 0700)
00278 shutil.rmtree(d)
00279
00280 f = open(d, 'w')
00281 f.close()
00282 os.chmod(d, 0700)
00283 self.rospack_succeed(None, "profile")
00284
00285 del os.environ['ROS_HOME']
00286 del os.environ['HOME']
00287 self.rospack_succeed(None, "profile")
00288
00289
00290 os.unlink(d)
00291 os.environ = env
00292
00293 def test_no_package_allowed(self):
00294 self.rospack_succeed(None, "help")
00295 self.rospack_succeed(None, "profile")
00296 self.rospack_succeed(None, "list")
00297 self.rospack_succeed(None, "list-names")
00298 self.rospack_succeed(None, "list-duplicates")
00299 self.rospack_succeed(None, "langs")
00300
00301 def test_no_package_allowed_bad(self):
00302 self.rospack_fail("deps", "help")
00303 self.rospack_fail("deps", "profile")
00304 self.rospack_fail("deps", "list")
00305 self.rospack_fail("deps", "list-names")
00306 self.rospack_fail("deps", "list-duplicates")
00307 self.rospack_fail("deps", "langs")
00308
00309 def test_invalid_option_order(self):
00310 self.rospack_fail("deps", "--lang=cpp --attrib=lflags export")
00311 self.rospack_fail("deps", "--lang=cpp export --attrib=lflags")
00312 self.rospack_fail("deps", "--deps-only cflags-only-I")
00313
00314 def test_export_bad(self):
00315 self.rospack_fail("base", "export --lang= --attrib=lflags")
00316 self.rospack_fail("base", "export --lang=cpp --attrib=")
00317 self.rospack_fail("base", "export --attrib=lflags")
00318 self.rospack_fail("base", "export --lang=cpp")
00319 self.rospack_fail("base", "export --lang=cpp --lang=python --attrib=lflags")
00320 self.rospack_fail("base", "export --lang=cpp --attrib=lflags --attrib=cflags")
00321 self.rospack_fail("base", "export --lang=cpp --attrib=cflags --top=foo")
00322
00323 def test_plugins_bad(self):
00324 self.rospack_fail("base", "plugins")
00325 self.rospack_fail("base", "plugins --lang=cpp")
00326 self.rospack_fail("base", "plugins --attrib=")
00327 self.rospack_fail("base", "plugins --top=foo")
00328
00329 def test_rosdep(self):
00330 self.rospack_succeed("base", "rosdep")
00331 self.assertEquals("name: foo", self.run_rospack("base", "rosdep"))
00332 self.rospack_succeed("deps", "rosdep0")
00333 self.assertEquals("name: bar", self.run_rospack("deps", "rosdep0"))
00334 self.check_unordered_list("rosdep", [(["name: foo", "name: bar"], "deps")])
00335
00336
00337
00338
00339 def test_export_cpp(self):
00340 package = 'base'
00341 tests = [("-lfoo", "export --lang=cpp --attrib=lflags"),
00342 ("-lfoo", "export --attrib=lflags --lang=cpp"),
00343 ("-Isomething", "export --lang=cpp --attrib=cflags"),
00344 ("-Isomething", "export --attrib=cflags --lang=cpp"),
00345 ]
00346 for retval, arg in tests:
00347 self.rospack_succeed(package, arg)
00348 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00349 self.assertEquals("-lfoo -lbar", self.strip_opt_ros(self.run_rospack("deps", "export --lang=cpp --attrib=lflags --deps-only")))
00350
00351
00352 def test_export_roslang(self):
00353 package = 'base'
00354 tests = [("something.cmake", "export --lang=roslang --attrib=cmake")]
00355 for retval, arg in tests:
00356 self.rospack_succeed(package, arg)
00357 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00358
00359 def test_export_non_existent_attrib(self):
00360 self.rospack_succeed("base", "export --lang=cpp --attrib=fake")
00361 self.failIf(self.run_rospack("base", "export --lang=cpp --attrib=fake"))
00362
00363
00364
00365
00366 def test_plugins(self):
00367 tests = [(["deps foo.cmake", "plugins bat.cmake"], "base")]
00368 self.check_unordered_list("plugins --attrib=cmake", tests)
00369
00370 package = 'base'
00371 tests = [("deps foo.cmake", "plugins --attrib=cmake --top=deps")]
00372 for retval, arg in tests:
00373 self.rospack_succeed(package, arg)
00374 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00375 package = 'base_two'
00376 tests = [("deps bar.cmake", "plugins --attrib=cmake")]
00377 for retval, arg in tests:
00378 self.rospack_succeed(package, arg)
00379 self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg)))
00380
00381
00382
00383
00384 def test_no_ros_root(self):
00385 testp = os.path.abspath('test')
00386 self.erospack_fail(None, testp, "deps", "deps")
00387
00388 def test_bad_ros_root(self):
00389
00390 non_existent1 = os.path.abspath('non_existent1')
00391 testp = os.path.abspath("test")
00392 self.assertNotEquals(0, self.erun_rospack_status(non_existent1, testp, "deps", "deps"))
00393
00394
00395 def test_ros_root_ros_package_path_identical(self):
00396
00397
00398 testp = os.path.abspath('test')
00399 tests = [
00400 (["base", "base_two"], testp, testp, "deps"),
00401 ]
00402 self.echeck_ordered_list("deps", tests)
00403
00404
00405 def test_empty_ros_package_path(self):
00406 testp = os.path.abspath('test')
00407 tests = [
00408 (["base", "base_two"], testp, '', "deps"),
00409 ]
00410 self.echeck_ordered_list("deps", tests)
00411
00412
00413 def test_ros_package_path_precedence(self):
00414 teste = os.path.abspath('test_empty')
00415 testp = os.path.abspath('test')
00416 test2p = os.path.abspath('test2')
00417 testp_roslang = os.path.join(testp, 'roslang')
00418 test2p_roslang = os.path.join(test2p, 'roslang')
00419 tests = [([testp_roslang], teste, ':'.join([testp, test2p]), "roslang"),
00420 ([testp_roslang], teste, ':'.join([testp, test2p_roslang]), "roslang"),
00421 ([testp_roslang], teste, ':'.join([testp_roslang, test2p]), "roslang"),
00422 ([testp_roslang], teste, ':'.join([testp_roslang, test2p_roslang]), "roslang")]
00423 self.echeck_unordered_list('find', tests)
00424
00425
00426 def test_ros_package_path_precedence_1(self):
00427 testp = os.path.abspath('test')
00428 test2p = os.path.abspath('test2')
00429 test3p = os.path.abspath('test3')
00430 tests = [
00431 (["test"], testp, test2p, "precedence1"),
00432 (["test2"], test2p, testp, "precedence1"),
00433 (["test2"], testp, "%s:%s"%(test2p, test3p), "precedence2"),
00434 (["test3"], testp, "%s:%s"%(test3p, test2p), "precedence2"),
00435 ]
00436 self.echeck_ordered_list('libs-only-l', tests)
00437
00438
00439 def test_list_duplicates(self):
00440 testp = os.path.abspath('test')
00441 test2p = os.path.abspath('test2')
00442 test3p = os.path.abspath('test3')
00443 self.erospack_succeed(testp, None, None, 'list-duplicates')
00444 self.erospack_fail(testp, '%s:%s'%(test2p,test3p), None, 'list-duplicates')
00445
00446
00447 def test_ros_package_path_direct_package(self):
00448 testp = os.path.abspath('test')
00449 test2p = os.path.abspath('test2')
00450 test3p = os.path.abspath('test3')
00451
00452 rpp = ':'.join([os.path.join(test2p, 'precedence2'),os.path.join(test3p, 'precedence3')])
00453 tests = [
00454 (["test2"], testp, rpp, "precedence2"),
00455 (["test3"], testp, rpp, "precedence3"),
00456 ]
00457 self.echeck_ordered_list('libs-only-l', tests)
00458
00459 def test_ros_package_path_colons(self):
00460
00461 testp = os.path.abspath('test')
00462 test2p = os.path.abspath('test2')
00463
00464 test3p = os.path.abspath('test3') + '/'
00465 tests = [
00466 (["base","base_two"], testp, "::%s:::"%testp, "deps"),
00467 (["base","base_two"], testp, "::", "deps"),
00468 ]
00469 self.echeck_ordered_list('deps', tests)
00470 tests = [
00471 (["test"], testp, ":::%s:"%test2p, "precedence1"),
00472 (["test2"],testp, "::%s::%s::"%(test2p,test3p), "precedence2"),
00473 ]
00474 self.echeck_ordered_list("libs-only-l", tests)
00475
00476 def test_ros_package_path_bad_paths(self):
00477 testp = os.path.abspath('test')
00478 test2p = os.path.abspath('test2')
00479 non_existentp = os.path.abspath('test')
00480 tests = [
00481 (["test"], testp, non_existentp, "precedence1"),
00482 (["test2"],testp, ":%s:%s"%(non_existentp, test2p), "precedence2"),
00483 (["test2"],testp, ":%s:%s"%(test2p, non_existentp), "precedence2"),
00484 ]
00485 self.echeck_ordered_list("libs-only-l", tests)
00486
00487
00488 def test_ros_in_package(self):
00489 pwd = os.getcwd()
00490 ros_root = os.path.join(pwd, 'test')
00491 os.chdir(os.path.abspath(os.path.join('test', 'deps')))
00492 self.erospack_succeed(ros_root, None, None, 'depends1')
00493 self.echeck_unordered_list('depends1', [(["base", "base_two"], ros_root, None, None)])
00494
00495 d = tempfile.mkdtemp()
00496 os.chdir(d)
00497 os.rmdir(d)
00498 self.erospack_fail(ros_root, None, None, 'depends1')
00499 os.chdir(pwd)
00500
00501
00502
00503
00504 def _rospack_list(self, ros_root, ros_package_path):
00505 env = os.environ.copy()
00506 if ros_root is not None:
00507 env[ROS_ROOT] = ros_root
00508 else:
00509 del env[ROS_ROOT]
00510 if ros_package_path is not None:
00511 env[ROS_PACKAGE_PATH] = ros_package_path
00512 elif ROS_PACKAGE_PATH in env:
00513 del env[ROS_PACKAGE_PATH]
00514 args = ["rospack", 'list']
00515 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00516 retval = p.communicate()[0]
00517 return p.returncode, retval.strip()
00518
00519 def _check_rospack_list(self, expected, retval):
00520 lines = [l for l in retval.split('\n') if l]
00521 packages = [l[:l.find(' ')] for l in lines]
00522
00523 paths = [os.path.abspath(l[l.find(' ')+1:]) for l in lines]
00524 result = {}
00525 for pack, path in zip(packages, paths):
00526 result[pack] = os.path.abspath(path)
00527 self.failIf(set(expected.keys()) ^ set(packages), "package lists do not match (expected vs. actual): %s vs %s"%(expected.keys(), packages))
00528 for pack,path in expected.iteritems():
00529 self.assertEquals(path, result[pack])
00530
00531
00532 def test_rospack_list_empty(self):
00533 rr = os.path.abspath('test_empty')
00534 retcode, retval = self._rospack_list(rr, None)
00535 self.assertEquals(0, retcode)
00536 self.failIf(retval, "rospack list on empty directory returned value %s"%retval)
00537
00538
00539 def test_rospack_depends_on_not_a_package(self):
00540 pwd = os.getcwd()
00541 ros_root = os.path.abspath('test')
00542 os.chdir(os.path.abspath('test_empty'))
00543 self.erospack_fail(ros_root, None, None, 'depends-on1')
00544 os.chdir(pwd)
00545
00546
00547 def test_rospack_list_dups(self):
00548
00549 rr = os.path.abspath('structure_test')
00550 retcode, retval = self._rospack_list(rr, None)
00551 self.assertEquals(0, retcode)
00552 retcode2, retval2 = self._rospack_list(rr, rr)
00553 self.assertEquals(0, retcode2)
00554 self.assertEquals(retval, retval2, "rospack list did not remove duplicates")
00555
00556 def test_rospack_list_no_rpp(self):
00557 rr = os.path.abspath('structure_test')
00558 expected = structure_test.copy()
00559 retcode, retval = self._rospack_list(rr, None)
00560 self.assertEquals(0, retcode)
00561 self._check_rospack_list(expected, retval)
00562
00563
00564
00565
00566
00567
00568
00569 def _rospack_list_names(self, ros_root, ros_package_path):
00570 env = os.environ.copy()
00571 if ros_root is not None:
00572 env[ROS_ROOT] = ros_root
00573 else:
00574 del env[ROS_ROOT]
00575 if ros_package_path is not None:
00576 env[ROS_PACKAGE_PATH] = ros_package_path
00577 elif ROS_PACKAGE_PATH in env:
00578 del env[ROS_PACKAGE_PATH]
00579 args = ["rospack", 'list-names']
00580 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00581 retval = p.communicate()[0]
00582 return p.returncode, retval.strip()
00583
00584
00585 def test_rospack_list_names_empty(self):
00586 rr = os.path.abspath('test_empty')
00587 retcode, retval = self._rospack_list_names(rr, None)
00588 self.assertEquals(0, retcode)
00589 self.failIf(retval, "rospack list-names on empty directory returned value %s"%retval)
00590
00591
00592 def test_rospack_list_names_dups(self):
00593
00594 rr = os.path.abspath('structure_test')
00595 retcode, retval = self._rospack_list_names(rr, None)
00596 self.assertEquals(0, retcode)
00597 retcode2, retval2 = self._rospack_list_names(rr, rr)
00598 self.assertEquals(0, retcode2)
00599 self.assertEquals(retval, retval2, "rospack list-names did not remove duplicates")
00600
00601 def test_rospack_list_names_no_rpp(self):
00602 rr = os.path.abspath('structure_test')
00603 expected = set(structure_test.copy().keys())
00604 retcode, retval = self._rospack_list_names(rr, None)
00605 self.assertEquals(0, retcode)
00606 self.assertEquals(expected, set(retval.split()))
00607
00608
00609
00610
00611
00612
00613
00614
00615 def test_rospack_find_fail(self):
00616 rr = os.path.abspath('test_empty')
00617 self.erospack_fail(rr, None, 'package', 'find')
00618
00619
00620 def test_rospack_find_direct(self):
00621 testp = os.path.abspath('test')
00622 package1p = os.path.abspath(os.path.join('structure_test', 'package1'))
00623 self.erospack_succeed(testp, package1p, 'package1', 'find')
00624 self.assertEquals(package1p, self.erun_rospack(testp, package1p, 'package1', 'find'))
00625
00626
00627
00628 def test_rospack_find_direct_with_rospack_nosubdirs(self):
00629 testp = os.path.abspath('test')
00630 package2p = os.path.abspath(os.path.join('structure_test', 'package2'))
00631 self.erospack_succeed(testp, package2p, 'package2', 'find')
00632 self.assertEquals(package2p, self.erun_rospack(testp, package2p, 'package2', 'find'))
00633
00634 def test_rospack_find_no_rpp(self):
00635 rr = os.path.abspath('structure_test')
00636 expected = structure_test.copy()
00637 for package,path in expected.iteritems():
00638 self.erospack_succeed(rr, None, package, 'find')
00639 self.assertEquals(path, os.path.abspath(self.erun_rospack(rr, None, package, 'find')))
00640
00641
00642
00643
00644
00645
00646
00647 def test_deps(self):
00648 depth_list = ['depth-%s'%i for i in xrange(1, 101)]
00649 depth_list.reverse()
00650 tests = [
00651 (["base","base_two"], "deps"),
00652 (["base","base_two","deps"], "deps_higher"),
00653 (["base","base_two","deps","deps_higher"],"deps_dup"),
00654 (depth_list, "depth-0")
00655 ]
00656 self.check_ordered_list('deps', tests)
00657
00658 def test_deps1(self):
00659 tests = [
00660 (["base","base_two"], "deps"),
00661 (["deps"], "deps_higher"),
00662 (["depth-1"], "depth-0"),
00663 (["depth-99"], "depth-98"),
00664 ]
00665 self.check_ordered_list('deps1',tests)
00666
00667 def test_deps_invalid(self):
00668 self.rospack_fail("deps_invalid", "deps")
00669
00670 def test_depends_on(self):
00671 depth_list = ['depth-%s'%i for i in xrange(0, 100)]
00672 depth_list.reverse()
00673
00674 self.rospack_succeed("deps", "depends-on")
00675 tests = [
00676 (["plugins", "deps_dup", "deps", "deps_higher"], "base"),
00677 (["deps_higher","deps_dup"], "deps"),
00678 ([], "depth-0"),
00679 (depth_list, "depth-100"),
00680 ]
00681 self.check_unordered_list("depends-on", tests)
00682
00683 def test_depends_on1(self):
00684
00685 self.rospack_succeed("deps", "depends-on")
00686 tests = [
00687 (["deps_higher"], "deps"),
00688 (["deps", "deps_dup", "plugins"], "base"),
00689 (["deps", "deps_dup"], "base_two"),
00690 ]
00691 self.check_unordered_list("depends-on1", tests)
00692
00693 def test_depends_on_nonexistent(self):
00694 self.rospack_fail("deps", "deps_nonexistent")
00695 self.rospack_fail("deps", "nonexistentpackage")
00696 tests = [
00697 (["deps_nonexistent"], "nonexistentpackage"),
00698 ]
00699 self.check_ordered_list("depends-on", tests)
00700
00701 def test_lflags_base(self):
00702 self.rospack_succeed("base", "libs-only-l")
00703 self.assertEquals("foo", self.run_rospack("base", "libs-only-l"))
00704
00705 def test_circular(self):
00706 testp = os.path.abspath("test")
00707 self.erospack_fail(testp, os.path.abspath("test_circular/cycle0"), "self_ref", "deps")
00708 self.erospack_fail(testp, os.path.abspath("test_circular/cycle1"), "friend1", "deps")
00709 self.erospack_fail(testp, os.path.abspath("test_circular/cycle1"), "friend2", "deps")
00710 self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend1", "deps")
00711 self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend2", "deps")
00712 self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend3", "deps")
00713
00714
00715
00716 self.erospack_succeed(testp, os.path.abspath("test_circular/cycle2"), "friend3", "depends-on")
00717
00718 def test_lflags_backquote(self):
00719 self.rospack_succeed("backquote", "libs-only-l")
00720 self.assertEquals("loki foo backquote", self.run_rospack("backquote", "libs-only-l"))
00721
00722 def test_backquote_invalid(self):
00723 self.rospack_fail("backquote_invalid", "libs-only-other")
00724
00725
00726 def strip_opt_ros(self, flags):
00727 prefix = '/opt/ros'
00728 if 'ROS_BINDEPS_PATH' in os.environ:
00729 prefix = os.environ['ROS_BINDEPS_PATH']
00730 tostrip = [prefix + '/lib',
00731 prefix + '/include',
00732 '-L' + prefix + '/lib',
00733 '-I' + prefix + '/include',
00734 '-Wl,-rpath,' + prefix + '/lib']
00735 res = ''
00736 for f in flags.split(' '):
00737 if f and f not in tostrip:
00738 if len(res) > 0:
00739 res += ' '
00740 res += f
00741 return res
00742
00743 def test_Lflags_backquote(self):
00744 self.rospack_succeed("backquote", "libs-only-L")
00745 self.assertEquals("odin", self.strip_opt_ros(self.run_rospack("backquote", "libs-only-L")))
00746
00747 def test_cflags_backquote(self):
00748 self.rospack_succeed("backquote", "cflags-only-I")
00749 self.assertEquals("blah backquote", self.strip_opt_ros(self.run_rospack("backquote", "cflags-only-I")))
00750
00751 def test_lflags_archive(self):
00752 self.rospack_succeed("lflags_with_archive_lib", "libs-only-l")
00753 self.assertEquals("/usr/lib/libfoo.a", self.run_rospack("lflags_with_archive_lib", "libs-only-l"))
00754 self.rospack_succeed("lflags_with_archive_lib", "libs-only-other")
00755 self.assertEquals("/a/bad/flag", self.run_rospack("lflags_with_archive_lib", "libs-only-other"))
00756
00757 def test_lflags_deps(self):
00758 self.rospack_succeed("deps", "libs-only-l")
00759 self.assertEquals("loki foo bar", self.run_rospack("deps", "libs-only-l"))
00760
00761 def test_lflags_deps_only(self):
00762 self.rospack_succeed("deps", "libs-only-l --deps-only")
00763 self.assertEquals("foo bar", self.run_rospack("deps", "libs-only-l --deps-only"))
00764
00765 def test_empty_lflags(self):
00766 tests = [([], "deps_empty")]
00767 commands = ["libs-only-l", "libs-only-L", "libs-only-other"]
00768 for c in commands:
00769 self.check_ordered_list(c, tests)
00770
00771 def test_empty_cflags(self):
00772 tests = [([], "deps_empty")]
00773 commands = ["cflags-only-I", "cflags-only-other"]
00774 for c in commands:
00775 self.check_ordered_list(c, tests)
00776
00777 def test_empty_vcs(self):
00778 self.rospack_succeed("empty", "vcs0")
00779 self.assertEquals("type: \turl:", self.run_rospack("empty", "vcs0"))
00780 self.rospack_succeed("deps_empty", "vcs")
00781 self.assertEquals("type: svn\turl: \ntype: \turl:", self.run_rospack("deps_empty", "vcs"))
00782
00783 def test_vcs_no_type_or_url(self):
00784 self.rospack_succeed("vc_no_type_or_url", "vcs0")
00785 self.assertEquals("", self.run_rospack("vc_no_type_or_url", "vcs0"))
00786
00787 def test_lflags_no_package_attrib(self):
00788 self.rospack_fail("no_package_attribute", "libs-only-l")
00789
00790 def test_lflags_invalid(self):
00791 self.rospack_fail("invalid", "libs-only-l")
00792
00793 def test_vcs_invalid(self):
00794 self.rospack_fail("invalid", "vcs")
00795
00796 def test_deps1_invalid(self):
00797 self.rospack_fail("invalid", "deps1")
00798
00799 def test_vcs0_deps(self):
00800 self.rospack_succeed("deps", "vcs0")
00801 self.failIf(self.run_rospack("deps", "vcs0"))
00802
00803 def test_vcs_deps(self):
00804 self.rospack_succeed("deps", "vcs")
00805 self.assertEquals("type: svn\turl: https://ros.svn.sourceforge.net/svnroot/ros/trunk\n"+
00806 "type: svn\turl: https://ros.svn.sourceforge.net/svnroot/ros/branches", self.run_rospack("deps", "vcs"))
00807
00808 def test_deps_manifests(self):
00809 self.rospack_succeed("deps", "deps-manifests")
00810 testp = os.path.abspath('test')
00811 expected = os.path.join(testp, 'base/manifest.xml') + ' ' + os.path.join(testp, 'base_two/manifest.xml')
00812 self.assertEquals(expected,
00813 self.run_rospack("deps", "deps-manifests"))
00814
00815 def test_deps_indent(self):
00816 self.rospack_succeed("deps_higher", "deps-indent")
00817 testp = os.path.abspath('test')
00818 expected = 'deps\n base\n base_two'
00819 self.assertEquals(expected,
00820 self.run_rospack("deps_higher", "deps-indent"))
00821
00822 def _rospack_langs(self, ros_root, ros_package_path, ros_lang_disable):
00823 env = os.environ.copy()
00824 if ros_root is not None:
00825 env[ROS_ROOT] = ros_root
00826 else:
00827 del env[ROS_ROOT]
00828 if ros_package_path is not None:
00829 env[ROS_PACKAGE_PATH] = ros_package_path
00830 elif ROS_PACKAGE_PATH in env:
00831 del env[ROS_PACKAGE_PATH]
00832 if ros_lang_disable is not None:
00833 env[ROS_LANG_DISABLE] = ros_lang_disable
00834 elif ROS_LANG_DISABLE in env:
00835 del env[ROS_LANG_DISABLE]
00836 args = ["rospack", 'langs']
00837 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env)
00838 retval = p.communicate()[0]
00839 return p.returncode, retval.strip()
00840
00841 def test_langs(self):
00842 rr = os.path.abspath('test')
00843 retcode, retval = self._rospack_langs(rr, None, None)
00844 self.assertEquals(0, retcode)
00845
00846 l = retval.split()
00847 s = set(l)
00848 expected = set(['rosfoo', 'rosbar'])
00849 self.assertEquals(s, expected)
00850
00851 def test_langs_disable(self):
00852 rr = os.path.abspath('test')
00853 disable = 'rosfoo'
00854 retcode, retval = self._rospack_langs(rr, None, disable)
00855 self.assertEquals(0, retcode)
00856
00857 l = retval.split()
00858 s = set(l)
00859 expected = set(['rosbar'])
00860 self.assertEquals(s, expected)
00861
00862 def test_langs_empty(self):
00863 rr = os.path.abspath('test2')
00864 retcode, retval = self._rospack_langs(rr, None, None)
00865 self.assertEquals(0, retcode)
00866 self.failIf(retval, "rospack langs on empty directory returned value %s"%retval)
00867
00868
00869 def test_msg_gen(self):
00870 test_path = os.path.abspath('test')
00871 pkgs = ['msg_gen_no_export', 'msg_gen_no_cpp', 'msg_gen_no_cflags']
00872 for p in pkgs:
00873 self.rospack_succeed(p, "cflags-only-I")
00874 self.assertEquals(os.path.join(test_path, p, "msg_gen/cpp/include"), self.strip_opt_ros(self.run_rospack(p, "cflags-only-I")))
00875
00876
00877 def test_quiet_option(self):
00878 ros_root = os.path.abspath('test')
00879
00880
00881 status_code, stdout, stderr = self._run_rospack(ros_root, None, 'nonexistentpackage', 'find -q')
00882 self.assertNotEquals(0, status_code)
00883 self.assertEquals(0, len(stderr))
00884
00885
00886 status_code, stdout, stderr = self._run_rospack(ros_root, None, 'nonexistentpackage', 'find')
00887 self.assertNotEquals(0, status_code)
00888 self.assertNotEquals(0, len(stderr))
00889
00890 if __name__ == "__main__":
00891 import rosunit
00892 rosunit.unitrun(PKG, 'rospack_exe_process', RospackTestCase)