test_roslib: more tests for packages/stacks. needs to be more intensive

This commit is contained in:
Ken Conley 2009-12-08 01:31:59 +00:00
parent 60669b4015
commit 034a61ee76
2 changed files with 60 additions and 0 deletions

View File

@ -42,6 +42,39 @@ import rostest
class RoslibPackagesTest(unittest.TestCase):
def test_list_pkgs(self):
# should be equal to rospack list
import roslib.rospack
import roslib.packages
pkgs = [s.split()[0] for s in roslib.rospack.rospackexec(['list']).split('\n')]
retval = roslib.packages.list_pkgs()
self.assertEquals(set(pkgs), set(retval), set(pkgs) ^ set(retval))
# test twice for caching
retval = roslib.packages.list_pkgs()
self.assertEquals(set(pkgs), set(retval), set(pkgs) ^ set(retval))
def test_get_pkg_dir(self):
import roslib.packages
import roslib.rospack
path = roslib.rospack.rospackexec(['find', 'test_roslib'])
self.assertEquals(path, roslib.packages.get_pkg_dir('test_roslib'))
try:
self.assertEquals(path, roslib.packages.get_pkg_dir('fake_test_roslib'))
self.fail("should have raised")
except roslib.packages.InvalidROSPkgException: pass
def test_get_dir_pkg(self):
import roslib.packages
import roslib.rospack
path = roslib.rospack.rospackexec(['find', 'test_roslib'])
self.assertEquals((path, 'test_roslib'), roslib.packages.get_dir_pkg(path))
self.assertEquals((path, 'test_roslib'), roslib.packages.get_dir_pkg(os.path.join(path, 'test')))
# must fail on parent of test_roslib
self.assertEquals((None, None), roslib.packages.get_dir_pkg(os.path.dirname(path)))
def test_get_package_paths(self):
from roslib.packages import get_package_paths

View File

@ -42,6 +42,33 @@ import rostest
class RoslibStacksTest(unittest.TestCase):
def test_packages_of(self):
from roslib.stacks import packages_of
pkgs = packages_of('ros')
for p in ['test_roslib', 'roslib', 'rospy', 'roscpp']:
self.assert_(p in pkgs)
# due to caching behavior, test twice
pkgs = packages_of('ros')
for p in ['test_roslib', 'roslib', 'rospy', 'roscpp']:
self.assert_(p in pkgs)
try:
packages_of(None)
self.fail("should have raised ValueError")
except ValueError: pass
def test_stack_of(self):
import roslib.packages
from roslib.stacks import stack_of
self.assertEquals('ros', stack_of('test_roslib'))
# due to caching, test twice
self.assertEquals('ros', stack_of('test_roslib'))
try:
stack_of('fake_test_roslib')
self.fail("should have failed")
except roslib.packages.InvalidROSPkgException:
pass
def test_get_stack_dir(self):
# TODO setup artificial tree with more exhaustive tests
import roslib.rosenv