00001 # Software License Agreement (BSD License) 00002 # 00003 # Copyright (c) 2008, Willow Garage, Inc. 00004 # All rights reserved. 00005 # 00006 # Redistribution and use in source and binary forms, with or without 00007 # modification, are permitted provided that the following conditions 00008 # are met: 00009 # 00010 # * Redistributions of source code must retain the above copyright 00011 # notice, this list of conditions and the following disclaimer. 00012 # * Redistributions in binary form must reproduce the above 00013 # copyright notice, this list of conditions and the following 00014 # disclaimer in the documentation and/or other materials provided 00015 # with the distribution. 00016 # * Neither the name of Willow Garage, Inc. nor the names of its 00017 # contributors may be used to endorse or promote products derived 00018 # from this software without specific prior written permission. 00019 # 00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 # POSSIBILITY OF SUCH DAMAGE. 00032 # 00033 # Author: Brian Gerkey/Ken Conley 00034 00035 PKG = 'test_rospack' 00036 import roslib; roslib.load_manifest(PKG) 00037 00038 import os 00039 import unittest 00040 from subprocess import Popen, PIPE 00041 00042 ROS_ROOT = 'ROS_ROOT' 00043 ROS_PACKAGE_PATH = 'ROS_PACKAGE_PATH' 00044 ROS_LANG_DISABLE = 'ROS_LANG_DISABLE' 00045 00046 aliases = { 00047 'deps': 'depends', 00048 'deps1': 'depends1', 00049 'deps-manifests': 'depends-manifests', 00050 'deps-indent': 'depends-indent', 00051 } 00052 00053 ## Process-level tests of rosstack executable 00054 class RosstackTestCase(unittest.TestCase): 00055 00056 ## runs rosstack with ROS_ROOT set to ./test and ROS_PACKAGE_PATH unset 00057 ## @return int, str: return code, stdout 00058 def _run_rosstack(self, ros_root, ros_package_path, pkgname, command): 00059 env = os.environ.copy() 00060 if ros_root is not None: 00061 env[ROS_ROOT] = ros_root 00062 else: 00063 del env[ROS_ROOT] 00064 if ros_package_path is not None: 00065 env[ROS_PACKAGE_PATH] = ros_package_path 00066 elif ROS_PACKAGE_PATH in env: 00067 del env[ROS_PACKAGE_PATH] 00068 # Must split up the command string into its whitespace separated 00069 # components; otherwise you get multiple words as one element of 00070 # argv. 00071 #args = ["rospack", command, pkgname] 00072 args = ["rosstack"] 00073 if command: 00074 for s in command.split(): 00075 args.append(s) 00076 if pkgname is not None: 00077 args.append(pkgname) 00078 p = Popen(args, stdout=PIPE, stderr=PIPE, env=env) 00079 stdout, stderr = p.communicate() 00080 00081 # Also test command aliases, verifying that they give the same 00082 # return code and console output 00083 if command: 00084 cmd = command.split()[-1] 00085 if cmd in aliases: 00086 args[-2] = aliases[cmd] 00087 alias_p = Popen(args, stdout=PIPE, stderr=PIPE, env=env) 00088 alias_stdout, alias_stderr = alias_p.communicate() 00089 self.assertEquals(p.returncode, alias_p.returncode) 00090 self.assertEquals(stdout, alias_stdout) 00091 #self.assertEquals(stderr, alias_stderr) 00092 00093 return p.returncode, stdout.strip(), stderr 00094 00095 ################################################################################ 00096 # HELPER ROUTINES 00097 # NOTE: helpers with the 'e' prefix take in environment parameters 00098 00099 ## @return str: stdout 00100 def run_rosstack(self, pkgname, command): 00101 ros_root = os.path.abspath('test') 00102 return self._run_rosstack(ros_root, None, pkgname, command)[1] 00103 00104 ## @return str: stdout 00105 def erun_rosstack(self, ros_root, ros_package_path, pkgname, command): 00106 return self._run_rosstack(ros_root, ros_package_path, pkgname, command)[1] 00107 00108 ## runs rospack with ROS_ROOT set to ./test and ROS_PACKAGE_PATH unset 00109 ## @return int: status code 00110 def run_rosstack_status(self, pkgname, command): 00111 ros_root = os.path.abspath('test') 00112 return self._run_rosstack(ros_root, None, pkgname, command)[0] 00113 00114 ## @return int: status code 00115 def erun_rosstack_status(self, ros_root, ros_package_path, pkgname, command): 00116 return self._run_rosstack(ros_root, ros_package_path, pkgname, command)[0] 00117 00118 ## assert that rosstack fails on the specified args 00119 def rosstack_fail(self, package, command): 00120 ros_root = os.path.abspath('test') 00121 code, stdout, stderr = self._run_rosstack(ros_root, None, package, command) 00122 self.assertNotEquals(0, code, "rosstack [%s %s] should have failed. \n\nstdout[%s] \n\nstderr[%s]"%(command, package, stdout, stderr)) 00123 00124 ## assert that rosstack fails on the specified args. includes ROS_ROOT and ROS_PACKAGE_PATH 00125 def erosstack_fail(self, ros_root, ros_package_path, package, command): 00126 code, stdout, stderr = self._run_rosstack(ros_root, ros_package_path, package, command) 00127 self.assertNotEquals(0, code, "rosstack [%s %s] should have failed instead of returning status code 0. \n\nstdout[%s] \n\nstderr[%s]"%(command, package, stdout, stderr)) 00128 00129 ## assert that rosstack succeeds on the specified args 00130 def rosstack_succeed(self, package, command): 00131 ros_root = os.path.abspath('test') 00132 status_code, stdout, stderr = self._run_rosstack(ros_root, None, package, command) 00133 self.assertEquals(0, status_code, '"rosstack %s %s" failed with status code [%s] instead of succeeding with [0]. \n\nstdout[%s] \n\nstderr[%s]'%(command, package, status_code, stdout, stderr)) 00134 00135 ## assert that rosstack succeeds on the specified args 00136 def erosstack_succeed(self, ros_root, ros_package_path, package, command): 00137 status_code, stdout, stderr = self._run_rosstack(ros_root, ros_package_path, package, command) 00138 self.assertEquals(0, status_code, "rosstack [%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)) 00139 00140 # helper routine that does return value validation where the return value from 00141 # rosstack is an unordered, line-separated list 00142 def check_ordered_list(self, command, tests): 00143 for retlist, package in tests: 00144 expected = set(retlist) 00145 self.rosstack_succeed(package, command) 00146 retval = self.strip_opt_ros(self.run_rosstack(package, command)) 00147 retactual = [v for v in retval.split('\n') if v] 00148 self.failIf(set(retlist) ^ set(retactual), "rosstack %s %s failed: [%s] vs [%s]"%(command, package, retlist, retactual)) 00149 self.assertEquals('\n'.join(retlist), '\n'.join(retactual)) 00150 00151 # variant of check_ordered_list that allows specifying ros_root and ros_package_path. 00152 # helper routine that does return value validation where the return value from 00153 # rosstack is an unordered, line-separated list 00154 def echeck_ordered_list(self, command, tests): 00155 for retlist, ros_root, ros_package_path, package in tests: 00156 expected = set(retlist) 00157 self.erosstack_succeed(ros_root, ros_package_path, package, command) 00158 retval = self.erun_rosstack(ros_root, ros_package_path, package, command) 00159 retactual = [v for v in retval.split('\n') if v] 00160 self.failIf(set(retlist) ^ set(retactual), "[env %s %s] rosstack %s %s failed: [%s] vs [%s]"%(ros_root, ros_package_path, command, package, retlist, retactual)) 00161 00162 # variant that does not require ordering among the return values 00163 def check_unordered_list(self, command, tests): 00164 for retlist, package in tests: 00165 expected = set(retlist) 00166 self.rosstack_succeed(package, command) 00167 retval = self.run_rosstack(package, command) 00168 retactual = [v for v in retval.split('\n') if v] 00169 self.failIf(set(retlist) ^ set(retactual), "rosstack %s %s failed: [%s] vs [%s]"%(command, package, retlist, retactual)) 00170 #self.assertEquals('\n'.join(retlist), '\n'.join(retactual)) 00171 00172 # variant that does not require ordering among the return values 00173 def echeck_unordered_list(self, command, tests): 00174 for retlist, ros_root, ros_package_path, package in tests: 00175 expected = set(retlist) 00176 self.erosstack_succeed(ros_root, ros_package_path, package, command) 00177 retval = self.erun_rosstack(ros_root, ros_package_path, package, command) 00178 retactual = [v for v in retval.split('\n') if v] 00179 self.failIf(set(retlist) ^ set(retactual), "rosstack %s %s failed: [%s] vs [%s]"%(command, package, retlist, retactual)) 00180 #self.assertEquals('\n'.join(retlist), '\n'.join(retactual)) 00181 00182 00183 ################################################################################ 00184 ## ARG PARSING 00185 00186 def test_no_option(self): 00187 self.rosstack_succeed(None, None) 00188 00189 def test_fake_option(self): 00190 self.rosstack_fail("deps", "--fake deps") 00191 00192 def test_invalid_option(self): 00193 self.rosstack_fail("deps", "list --length=10") 00194 00195 def test_no_package_allowed(self): 00196 self.rosstack_succeed(None, "help") 00197 self.rosstack_succeed(None, "profile") 00198 self.rosstack_succeed(None, "list") 00199 self.rosstack_succeed(None, "list-names") 00200 00201 def test_no_package_allowed_bad(self): 00202 self.rosstack_fail("deps", "help") 00203 self.rosstack_fail("deps", "profile") 00204 self.rosstack_fail("deps", "list") 00205 self.rosstack_fail("deps", "list-names") 00206 00207 def test_contents(self): 00208 tests = [(["precedence1", "precedence2", "precedence3", "roslang"], 00209 os.path.abspath("test2"), os.path.abspath("test2"), "test2")] 00210 self.echeck_unordered_list("contents", tests) 00211 00212 # Bug #2854 00213 def test_path_precendence(self): 00214 tests = [([os.path.abspath("stack_install/stack")], 00215 os.path.abspath("test"), 00216 ':'.join([os.path.abspath("stack_install"), os.path.abspath("stack_overlay")]), "stack"), 00217 ([os.path.abspath("stack_install/stack")], 00218 os.path.abspath("test"), 00219 ':'.join([os.path.abspath("stack_install"), os.path.abspath("stack_overlay/stack")]), "stack"), 00220 ([os.path.abspath("stack_install/stack")], 00221 os.path.abspath("test"), 00222 ':'.join([os.path.abspath("stack_install/stack"), os.path.abspath("stack_overlay/stack")]), "stack"), 00223 ([os.path.abspath("stack_install/stack")], 00224 os.path.abspath("test"), 00225 ':'.join([os.path.abspath("stack_install/stack"), os.path.abspath("stack_overlay")]), "stack")] 00226 self.echeck_unordered_list("find", tests) 00227 00228 # TODO: port / adapt these rospack tests to exercise rosstack, #2009 00229 # 00230 # def test_invalid_option_order(self): 00231 # self.rospack_fail("deps", "--lang=cpp --attrib=lflags export") 00232 # self.rospack_fail("deps", "--lang=cpp export --attrib=lflags") 00233 # self.rospack_fail("deps", "--deps-only cflags-only-I") 00234 # 00235 # def test_export_bad(self): 00236 # self.rospack_fail("base", "export --lang= --attrib=lflags") 00237 # self.rospack_fail("base", "export --lang=cpp --attrib=") 00238 # self.rospack_fail("base", "export --attrib=lflags") 00239 # self.rospack_fail("base", "export --lang=cpp") 00240 # self.rospack_fail("base", "export --lang=cpp --lang=python --attrib=lflags") 00241 # self.rospack_fail("base", "export --lang=cpp --attrib=lflags --attrib=cflags") 00242 # self.rospack_fail("base", "export --lang=cpp --attrib=cflags --top=foo") 00243 # 00244 # def test_plugins_bad(self): 00245 # self.rospack_fail("base", "plugins") 00246 # self.rospack_fail("base", "plugins --lang=cpp") 00247 # self.rospack_fail("base", "plugins --attrib=") 00248 # self.rospack_fail("base", "plugins --top=foo") 00249 # 00250 # ################################################################################ 00251 # ## EXPORT 00252 # 00253 # def test_export_cpp(self): 00254 # package = 'base' 00255 # tests = [("-lfoo", "export --lang=cpp --attrib=lflags"), 00256 # ("-lfoo", "export --attrib=lflags --lang=cpp"), 00257 # ("-Isomething", "export --lang=cpp --attrib=cflags"), 00258 # ("-Isomething", "export --attrib=cflags --lang=cpp"), 00259 # ] 00260 # for retval, arg in tests: 00261 # self.rospack_succeed(package, arg) 00262 # self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg))) 00263 # #TODO: test export with $prefix 00264 # #TODO: test export with non-cpp attribs 00265 # 00266 # def test_export_non_existent_attrib(self): 00267 # self.rospack_succeed("base", "export --lang=cpp --attrib=fake") 00268 # self.failIf(self.run_rospack("base", "export --lang=cpp --attrib=fake")) 00269 # 00270 # ################################################################################ 00271 # ## Plugins 00272 # 00273 # def test_plugins(self): 00274 # tests = [(["deps foo.cmake", "plugins bat.cmake"], "base")] 00275 # self.check_unordered_list("plugins --attrib=cmake", tests) 00276 # 00277 # package = 'base' 00278 # tests = [("deps foo.cmake", "plugins --attrib=cmake --top=deps")] 00279 # for retval, arg in tests: 00280 # self.rospack_succeed(package, arg) 00281 # self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg))) 00282 # package = 'base_two' 00283 # tests = [("deps bar.cmake", "plugins --attrib=cmake")] 00284 # for retval, arg in tests: 00285 # self.rospack_succeed(package, arg) 00286 # self.assertEquals(retval, self.strip_opt_ros(self.run_rospack(package, arg))) 00287 # 00288 # ################################################################################ 00289 # ## ENVIRONMENT TEST 00290 # 00291 # def test_no_ros_root(self): 00292 # testp = os.path.abspath('test') 00293 # self.erospack_fail(None, testp, "deps", "deps") 00294 # 00295 # def test_bad_ros_root(self): 00296 # # #468 test. this is the chosen exit code, distinguish against segfault 00297 # non_existent1 = os.path.abspath('non_existent1') 00298 # testp = os.path.abspath("test") 00299 # self.assertNotEquals(0, self.erun_rospack_status(non_existent1, testp, "deps", "deps")) 00300 # 00301 # ## test rospack with ROS_ROOT=ROS_PACKAGE_PATH 00302 # def test_ros_root__ros_package_path_identical(self): 00303 # #implicitly depending on the deps test here 00304 # #set ros_package_path to be identical to ros_root 00305 # testp = os.path.abspath('test') 00306 # tests = [ 00307 # (["base", "base_two"], testp, testp, "deps"), 00308 # ] 00309 # self.echeck_ordered_list("deps", tests) 00310 # 00311 # ## test rospack with ROS_PACKAGE_PATH set to the empty string 00312 # def test_empty_ros_package_path(self): 00313 # testp = os.path.abspath('test') 00314 # tests = [ 00315 # (["base", "base_two"], testp, '', "deps"), 00316 # ] 00317 # self.echeck_ordered_list("deps", tests) 00318 # 00319 # ## tests rpp vs rr precedence 00320 # def test_ros_package_path_precedence_1(self): 00321 # testp = os.path.abspath('test') 00322 # test2p = os.path.abspath('test2') 00323 # test3p = os.path.abspath('test3') 00324 # tests = [ 00325 # (["test"], testp, test2p, "precedence1"), 00326 # (["test2"], test2p, testp, "precedence1"), 00327 # (["test2"], testp, "%s:%s"%(test2p, test3p), "precedence2"), 00328 # (["test3"], testp, "%s:%s"%(test3p, test2p), "precedence2"), 00329 # ] 00330 # self.echeck_ordered_list('libs-only-l', tests) 00331 # 00332 # # test ability to point ros_package_path directly at package 00333 # def test_ros_package_path_direct_package(self): 00334 # testp = os.path.abspath('test') 00335 # test2p = os.path.abspath('test2') 00336 # test3p = os.path.abspath('test3') 00337 # # point directly at precedence 2/3 00338 # rpp = ':'.join([os.path.join(test2p, 'precedence2'),os.path.join(test3p, 'precedence3')]) 00339 # tests = [ 00340 # (["test2"], testp, rpp, "precedence2"), 00341 # (["test3"], testp, rpp, "precedence3"), 00342 # ] 00343 # self.echeck_ordered_list('libs-only-l', tests) 00344 # 00345 # def test_ros_package_path_colons(self): 00346 # # scatter some colons into ros package path to make sure rospack doesn't mind 00347 # testp = os.path.abspath('test') 00348 # test2p = os.path.abspath('test2') 00349 # test3p = os.path.abspath('test3') 00350 # tests = [ 00351 # (["base","base_two"], testp, "::%s:::"%testp, "deps"), 00352 # (["base","base_two"], testp, "::", "deps"), 00353 # ] 00354 # self.echeck_ordered_list('deps', tests) 00355 # tests = [ 00356 # (["test"], testp, ":::%s:"%test2p, "precedence1"), 00357 # (["test2"],testp, "::%s::%s::"%(test2p,test3p), "precedence2"), 00358 # ] 00359 # self.echeck_ordered_list("libs-only-l", tests) 00360 # 00361 # def test_ros_package_path_bad_paths(self): 00362 # testp = os.path.abspath('test') 00363 # test2p = os.path.abspath('test2') 00364 # non_existentp = os.path.abspath('test') 00365 # tests = [ 00366 # (["test"], testp, non_existentp, "precedence1"), 00367 # (["test2"],testp, ":%s:%s"%(non_existentp, test2p), "precedence2"), 00368 # (["test2"],testp, ":%s:%s"%(test2p, non_existentp), "precedence2"), 00369 # ] 00370 # self.echeck_ordered_list("libs-only-l", tests) 00371 # 00372 # ################################################################################ 00373 # ## rospack list 00374 # 00375 # def _rospack_list(self, ros_root, ros_package_path): 00376 # env = os.environ.copy() 00377 # if ros_root is not None: 00378 # env[ROS_ROOT] = ros_root 00379 # else: 00380 # del env[ROS_ROOT] 00381 # if ros_package_path is not None: 00382 # env[ROS_PACKAGE_PATH] = ros_package_path 00383 # elif ROS_PACKAGE_PATH in env: 00384 # del env[ROS_PACKAGE_PATH] 00385 # args = ["rospack", 'list'] 00386 # p = Popen(args, stdout=PIPE, stderr=PIPE, env=env) 00387 # retval = p.communicate()[0] 00388 # return p.returncode, retval.strip() 00389 # 00390 # def _check_rospack_list(self, expected, retval): 00391 # lines = [l for l in retval.split('\n') if l] 00392 # packages = [l[:l.find(' ')] for l in lines] 00393 # # canonicalize paths 00394 # paths = [os.path.abspath(l[l.find(' ')+1:]) for l in lines] 00395 # result = {} 00396 # for pack, path in zip(packages, paths): 00397 # result[pack] = os.path.abspath(path) 00398 # self.failIf(set(expected.keys()) ^ set(packages), "package lists do not match (expected vs. actual): %s vs %s"%(expected.keys(), packages)) 00399 # for pack,path in expected.iteritems(): 00400 # self.assertEquals(path, result[pack]) 00401 # 00402 # ## test rospack list on an empty tree 00403 # def test_rospack_list_empty(self): 00404 # rr = os.path.abspath('test_empty') 00405 # retcode, retval = self._rospack_list(rr, None) 00406 # self.assertEquals(0, retcode) 00407 # self.failIf(retval, "rospack list on empty directory returned value %s"%retval) 00408 # 00409 # # test that rospack list removes duplicates 00410 # def test_rospack_list_dups(self): 00411 # # make sure result is same if ROS_ROOT=ROS_PACKAGE_PATH 00412 # rr = os.path.abspath('structure_test') 00413 # retcode, retval = self._rospack_list(rr, None) 00414 # self.assertEquals(0, retcode) 00415 # retcode2, retval2 = self._rospack_list(rr, rr) 00416 # self.assertEquals(0, retcode2) 00417 # self.assertEquals(retval, retval2, "rospack list did not remove duplicates") 00418 # 00419 # def test_rospack_list_no_rpp(self): 00420 # rr = os.path.abspath('structure_test') 00421 # expected = structure_test.copy() 00422 # retcode, retval = self._rospack_list(rr, None) 00423 # self.assertEquals(0, retcode) 00424 # self._check_rospack_list(expected, retval) 00425 # 00426 # #TODO: symlink test 00427 # #TODO: test with ros package path 00428 # 00429 # ################################################################################ 00430 # ## rospack list-names 00431 # 00432 # def _rospack_list_names(self, ros_root, ros_package_path): 00433 # env = os.environ.copy() 00434 # if ros_root is not None: 00435 # env[ROS_ROOT] = ros_root 00436 # else: 00437 # del env[ROS_ROOT] 00438 # if ros_package_path is not None: 00439 # env[ROS_PACKAGE_PATH] = ros_package_path 00440 # elif ROS_PACKAGE_PATH in env: 00441 # del env[ROS_PACKAGE_PATH] 00442 # args = ["rospack", 'list-names'] 00443 # p = Popen(args, stdout=PIPE, stderr=PIPE, env=env) 00444 # retval = p.communicate()[0] 00445 # return p.returncode, retval.strip() 00446 # 00447 # ## test rospack list-names on an empty tree 00448 # def test_rospack_list_names_empty(self): 00449 # rr = os.path.abspath('test_empty') 00450 # retcode, retval = self._rospack_list_names(rr, None) 00451 # self.assertEquals(0, retcode) 00452 # self.failIf(retval, "rospack list-names on empty directory returned value %s"%retval) 00453 # 00454 # # test that rospack list removes duplicates 00455 # def test_rospack_list_names_dups(self): 00456 # # make sure result is same if ROS_ROOT=ROS_PACKAGE_PATH 00457 # rr = os.path.abspath('structure_test') 00458 # retcode, retval = self._rospack_list_names(rr, None) 00459 # self.assertEquals(0, retcode) 00460 # retcode2, retval2 = self._rospack_list_names(rr, rr) 00461 # self.assertEquals(0, retcode2) 00462 # self.assertEquals(retval, retval2, "rospack list-names did not remove duplicates") 00463 # 00464 # def test_rospack_list_names_no_rpp(self): 00465 # rr = os.path.abspath('structure_test') 00466 # expected = set(structure_test.copy().keys()) 00467 # retcode, retval = self._rospack_list_names(rr, None) 00468 # self.assertEquals(0, retcode) 00469 # self.assertEquals(expected, set(retval.split())) 00470 # 00471 # #TODO: symlink test 00472 # #TODO: test with ros package path 00473 # 00474 # ################################################################################ 00475 # ## rospack find 00476 # 00477 # ## test rospack find on non-existent package 00478 # def test_rospack_find_fail(self): 00479 # rr = os.path.abspath('test_empty') 00480 # self.erospack_fail(rr, None, 'package', 'find') 00481 # 00482 # ## test rospack find with ros_package_path set directly to a package 00483 # def test_rospack_find_direct(self): 00484 # testp = os.path.abspath('test') 00485 # package1p = os.path.abspath(os.path.join('structure_test', 'package1')) 00486 # self.erospack_succeed(testp, package1p, 'package1', 'find') 00487 # self.assertEquals(package1p, self.erun_rospack(testp, package1p, 'package1', 'find')) 00488 # 00489 # def test_rospack_find_no_rpp(self): 00490 # rr = os.path.abspath('structure_test') 00491 # expected = structure_test.copy() 00492 # for package,path in expected.iteritems(): 00493 # self.erospack_succeed(rr, None, package, 'find') 00494 # self.assertEquals(path, os.path.abspath(self.erun_rospack(rr, None, package, 'find'))) 00495 # 00496 # #TODO: symlink test 00497 # #TODO: test with ros package path 00498 # 00499 # ################################################################################ 00500 # ## DEPENDENCIES 00501 # 00502 # def test_deps(self): 00503 # depth_list = ['depth-%s'%i for i in xrange(1, 101)] 00504 # depth_list.reverse() 00505 # tests = [ 00506 # (["base","base_two"], "deps"), 00507 # (["base","base_two","deps"], "deps_higher"), 00508 # (["base","base_two","deps","deps_higher"],"deps_dup"), 00509 # (depth_list, "depth-0") 00510 # ] 00511 # self.check_ordered_list('deps', tests) 00512 # 00513 # def test_deps1(self): 00514 # tests = [ 00515 # (["base","base_two"], "deps"), 00516 # (["deps"], "deps_higher"), 00517 # (["depth-1"], "depth-0"), 00518 # (["depth-99"], "depth-98"), 00519 # ] 00520 # self.check_ordered_list('deps1',tests) 00521 # 00522 # def test_deps_invalid(self): 00523 # self.rospack_fail("deps_invalid", "deps") 00524 # 00525 # def test_depends_on(self): 00526 # depth_list = ['depth-%s'%i for i in xrange(0, 100)] 00527 # depth_list.reverse() 00528 # 00529 # self.rospack_succeed("deps", "depends-on") 00530 # tests = [ 00531 # (["deps_higher","deps_dup"], "deps"), 00532 # ([], "depth-0"), 00533 # (depth_list, "depth-100"), 00534 # ] 00535 # self.check_ordered_list("depends-on", tests) 00536 # 00537 # def test_depends_on1(self): 00538 # # sanity check first 00539 # self.rospack_succeed("deps", "depends-on") 00540 # tests = [ 00541 # (["deps_higher"], "deps"), 00542 # (["deps", "deps_dup", "plugins"], "base"), 00543 # (["deps", "deps_dup"], "base_two"), 00544 # ] 00545 # self.check_unordered_list("depends-on1", tests) 00546 # 00547 # def test_depends_on_nonexistent(self): 00548 # self.rospack_fail("deps", "deps_nonexistent") 00549 # self.rospack_fail("deps", "nonexistentpackage") 00550 # tests = [ 00551 # (["deps_nonexistent"], "nonexistentpackage"), 00552 # ] 00553 # self.check_ordered_list("depends-on", tests) 00554 # 00555 # def test_lflags_base(self): 00556 # self.rospack_succeed("base", "libs-only-l") 00557 # self.assertEquals("foo", self.run_rospack("base", "libs-only-l")) 00558 # 00559 # def test_circular(self): 00560 # testp = os.path.abspath("test") 00561 # self.erospack_fail(testp, os.path.abspath("test_circular/cycle0"), "self_ref", "deps") 00562 # self.erospack_fail(testp, os.path.abspath("test_circular/cycle1"), "friend1", "deps") 00563 # self.erospack_fail(testp, os.path.abspath("test_circular/cycle1"), "friend2", "deps") 00564 # self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend1", "deps") 00565 # self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend2", "deps") 00566 # self.erospack_fail(testp, os.path.abspath("test_circular/cycle2"), "friend3", "deps") 00567 # 00568 # def test_lflags_backquote(self): 00569 # self.rospack_succeed("backquote", "libs-only-l") 00570 # self.assertEquals("loki foo backquote", self.run_rospack("backquote", "libs-only-l")) 00571 # 00572 # def test_backquote_invalid(self): 00573 # self.rospack_fail("backquote_invalid", "libs-only-other") 00574 # 00575 # # Strip out '/opt/ros' and friends from flags before checking them 00576 # def strip_opt_ros(self, flags): 00577 # prefix = '/opt/ros' 00578 # if 'ROS_BINDEPS_PATH' in os.environ: 00579 # prefix = os.environ['ROS_BINDEPS_PATH'] 00580 # tostrip = [prefix + '/lib', 00581 # prefix + '/include', 00582 # '-L' + prefix + '/lib', 00583 # '-I' + prefix + '/include', 00584 # '-Wl,-rpath,' + prefix + '/lib'] 00585 # res = '' 00586 # for f in flags.split(' '): 00587 # if f and f not in tostrip: 00588 # if len(res) > 0: 00589 # res += ' ' 00590 # res += f 00591 # return res 00592 # 00593 # def test_Lflags_backquote(self): 00594 # self.rospack_succeed("backquote", "libs-only-L") 00595 # self.assertEquals("odin", self.strip_opt_ros(self.run_rospack("backquote", "libs-only-L"))) 00596 # 00597 # def test_cflags_backquote(self): 00598 # self.rospack_succeed("backquote", "cflags-only-I") 00599 # self.assertEquals("blah backquote", self.strip_opt_ros(self.run_rospack("backquote", "cflags-only-I"))) 00600 # 00601 # def test_lflags_deps(self): 00602 # self.rospack_succeed("deps", "libs-only-l") 00603 # self.assertEquals("loki foo bar", self.run_rospack("deps", "libs-only-l")) 00604 # 00605 # def test_lflags_deps_only(self): 00606 # self.rospack_succeed("deps", "libs-only-l --deps-only") 00607 # self.assertEquals("foo bar", self.run_rospack("deps", "libs-only-l --deps-only")) 00608 # 00609 # def test_empty_lflags(self): 00610 # tests = [([], "deps_empty")] 00611 # commands = ["libs-only-l", "libs-only-L", "libs-only-other"] 00612 # for c in commands: 00613 # self.check_ordered_list(c, tests) 00614 # 00615 # def test_empty_cflags(self): 00616 # tests = [([], "deps_empty")] 00617 # commands = ["cflags-only-I", "cflags-only-other"] 00618 # for c in commands: 00619 # self.check_ordered_list(c, tests) 00620 # 00621 # def test_empty_vcs(self): 00622 # self.rospack_succeed("empty", "vcs0") 00623 # self.assertEquals("type: \turl:", self.run_rospack("empty", "vcs0")) 00624 # self.rospack_succeed("deps_empty", "vcs") 00625 # self.assertEquals("type: svn\turl: \ntype: \turl:", self.run_rospack("deps_empty", "vcs")) 00626 # 00627 # def test_lflags_invalid(self): 00628 # self.rospack_fail("invalid", "libs-only-l") 00629 # 00630 # def test_vcs_invalid(self): 00631 # self.rospack_fail("invalid", "vcs") 00632 # 00633 # def test_deps1_invalid(self): 00634 # self.rospack_fail("invalid", "deps1") 00635 # 00636 # def test_vcs0_deps(self): 00637 # self.rospack_succeed("deps", "vcs0") 00638 # self.failIf(self.run_rospack("deps", "vcs0")) 00639 # 00640 # def test_vcs_deps(self): 00641 # self.rospack_succeed("deps", "vcs") 00642 # self.assertEquals("type: svn\turl: https://ros.svn.sourceforge.net/svnroot/ros/trunk\n"+ 00643 # "type: svn\turl: https://ros.svn.sourceforge.net/svnroot/ros/branches", self.run_rospack("deps", "vcs")) 00644 # 00645 # def test_deps_manifests(self): 00646 # self.rospack_succeed("deps", "deps-manifests") 00647 # testp = os.path.abspath('test') 00648 # expected = os.path.join(testp, 'base/manifest.xml') + ' ' + os.path.join(testp, 'base_two/manifest.xml') 00649 # self.assertEquals(expected, 00650 # self.run_rospack("deps", "deps-manifests")) 00651 # 00652 # def test_deps_indent(self): 00653 # self.rospack_succeed("deps_higher", "deps-indent") 00654 # testp = os.path.abspath('test') 00655 # expected = 'deps\n base\n base_two' 00656 # self.assertEquals(expected, 00657 # self.run_rospack("deps_higher", "deps-indent")) 00658 # 00659 # def _rospack_langs(self, ros_root, ros_package_path, ros_lang_disable): 00660 # env = os.environ.copy() 00661 # if ros_root is not None: 00662 # env[ROS_ROOT] = ros_root 00663 # else: 00664 # del env[ROS_ROOT] 00665 # if ros_package_path is not None: 00666 # env[ROS_PACKAGE_PATH] = ros_package_path 00667 # elif ROS_PACKAGE_PATH in env: 00668 # del env[ROS_PACKAGE_PATH] 00669 # if ros_lang_disable is not None: 00670 # env[ROS_LANG_DISABLE] = ros_lang_disable 00671 # elif ROS_LANG_DISABLE in env: 00672 # del env[ROS_LANG_DISABLE] 00673 # args = ["rospack", 'langs'] 00674 # p = Popen(args, stdout=PIPE, stderr=PIPE, env=env) 00675 # retval = p.communicate()[0] 00676 # return p.returncode, retval.strip() 00677 # 00678 # def test_langs(self): 00679 # rr = os.path.abspath('test') 00680 # retcode, retval = self._rospack_langs(rr, None, None) 00681 # self.assertEquals(0, retcode) 00682 # # No guarantees on ordering of lang result 00683 # l = retval.split() 00684 # s = set(l) 00685 # expected = set(['rosfoo', 'rosbar']) 00686 # self.assertEquals(s, expected) 00687 # 00688 # def test_langs_disable(self): 00689 # rr = os.path.abspath('test') 00690 # disable = 'rosfoo' 00691 # retcode, retval = self._rospack_langs(rr, None, disable) 00692 # self.assertEquals(0, retcode) 00693 # # No guarantees on ordering of lang result 00694 # l = retval.split() 00695 # s = set(l) 00696 # expected = set(['rosbar']) 00697 # self.assertEquals(s, expected) 00698 # 00699 # def test_langs_empty(self): 00700 # rr = os.path.abspath('test2') 00701 # retcode, retval = self._rospack_langs(rr, None, None) 00702 # self.assertEquals(0, retcode) 00703 # self.failIf(retval, "rospack langs on empty directory returned value %s"%retval) 00704 00705 00706 if __name__ == "__main__": 00707 import rosunit 00708 rosunit.unitrun(PKG, 'rospack_exe_process', RosstackTestCase)