コード例 #1
0
ファイル: test_roslib_stacks.py プロジェクト: strawlab/ros
    def test_list_stacks(self):
        from roslib.stacks import list_stacks
        l = list_stacks()
        self.assert_('ros' in l)

        # test with env
        test_dir = os.path.join(roslib.packages.get_pkg_dir('roslib'), 'test', 'stack_tests', 's1')
        env = os.environ.copy()
        env['ROS_PACKAGE_PATH'] = test_dir
        val = set(list_stacks(env=env))
        # ros stack not guaranteed to list anymore as ROS_ROOT may not be set
        if 'ros' in val:
            val.remove('ros')
        self.assertEquals(set(['foo', 'bar']), val)
コード例 #2
0
    def test_list_stacks(self):
        from roslib.stacks import list_stacks
        l = list_stacks()
        self.assert_('ros' in l)

        # test with env
        test_dir = os.path.join(roslib.packages.get_pkg_dir('roslib'), 'test',
                                'stack_tests', 's1')
        env = os.environ.copy()
        env['ROS_PACKAGE_PATH'] = test_dir
        val = set(list_stacks(env=env))
        # ros stack not guaranteed to list anymore as ROS_ROOT may not be set
        if 'ros' in val:
            val.remove('ros')
        self.assertEquals(set(['foo', 'bar']), val)
コード例 #3
0
    def test_list_stacks(self):
        from roslib.stacks import list_stacks
        l = list_stacks()
        self.assert_('ros' in l)

        # make sure it is equivalent to rosstack list
        from roslib.rospack import rosstackexec
        l2 = [x for x in rosstackexec(['list']).split('\n') if x]
        l2 = [x.split()[0] for x in l2]
        self.assertEquals(set(l), set(l2), set(l) ^ set(l2))

        # test with env
        test_dir = os.path.join(roslib.packages.get_pkg_dir('test_roslib'), 'test', 'stack_tests', 's1')
        env = os.environ.copy()
        env['ROS_PACKAGE_PATH'] = test_dir
        self.assertEquals(set(['ros', 'foo', 'bar']), set(list_stacks(env=env)))
コード例 #4
0
    def test_get_stack_dir(self):
        import roslib.packages
        from roslib.stacks import get_stack_dir, InvalidROSStackException, list_stacks
        self.assertEquals(rospkg.get_ros_root(), get_stack_dir('ros'))
        try:
            get_stack_dir('non_existent')
            self.fail("should have raised")
        except roslib.stacks.InvalidROSStackException:
            pass

        # make sure it agrees with rosstack
        stacks = list_stacks()
        from roslib.rospack import rosstackexec
        for s in stacks:
            d1 = get_stack_dir(s)
            d2 = rosstackexec(['find', s])
            self.assertEquals(d1, d2, "%s vs %s"%(d1, d2))

        # now manipulate the environment to test precedence
        # - save original RPP as we popen rosstack in other tests
        rpp = os.environ.get(rospkg.environment.ROS_PACKAGE_PATH, None)
        try:
            d = roslib.packages.get_pkg_dir('test_roslib')
            d = os.path.join(d, 'test', 'stack_tests')

            # - s1/s2/s3
            print "s1/s2/s3"            
            paths = [os.path.join(d, p) for p in ['s1', 's2', 's3']]
            os.environ[rospkg.environment.ROS_PACKAGE_PATH] = os.pathsep.join(paths)
            # - run multiple times to test caching
            for i in xrange(2):
                stacks = roslib.stacks.list_stacks()
                self.assert_('foo' in stacks)
                self.assert_('bar' in stacks)

                foo_p = os.path.join(d, 's1', 'foo')
                bar_p = os.path.join(d, 's1', 'bar')
                self.assertEquals(foo_p, roslib.stacks.get_stack_dir('foo'))
                self.assertEquals(bar_p, roslib.stacks.get_stack_dir('bar'))

            # - s2/s3/s1
            print "s2/s3/s1"
            
            paths = [os.path.join(d, p) for p in ['s2', 's3', 's1']]
            os.environ[rospkg.environment.ROS_PACKAGE_PATH] = os.pathsep.join(paths)
            stacks = roslib.stacks.list_stacks()
            self.assert_('foo' in stacks)
            self.assert_('bar' in stacks)

            foo_p = os.path.join(d, 's2', 'foo')
            bar_p = os.path.join(d, 's1', 'bar')
            self.assertEquals(foo_p, roslib.stacks.get_stack_dir('foo'))
            self.assertEquals(bar_p, roslib.stacks.get_stack_dir('bar'))
        finally:
            #restore rpp
            if rpp is not None:
                os.environ[rospkg.environment.ROS_PACKAGE_PATH] = rpp
            else:
                del os.environ[rospkg.environment.ROS_PACKAGE_PATH] 
コード例 #5
0
    def test_get_stack_dir(self):
        import roslib.rosenv
        import roslib.packages
        from roslib.stacks import get_stack_dir, InvalidROSStackException, list_stacks
        self.assertEquals(roslib.rosenv.get_ros_root(), get_stack_dir('ros'))
        try:
            get_stack_dir('non_existent')
            self.fail("should have raised")
        except roslib.stacks.InvalidROSStackException:
            pass

        # make sure it agrees with rosstack
        stacks = list_stacks()
        from roslib.rospack import rosstackexec
        for s in stacks:
            self.assertEquals(get_stack_dir(s), rosstackexec(['find', s]))

        # now manipulate the environment to test precedence
        # - save original RPP as we popen rosstack in other tests
        rpp = os.environ.get(roslib.rosenv.ROS_PACKAGE_PATH, None)
        try:
            d = roslib.packages.get_pkg_dir('test_roslib')
            d = os.path.join(d, 'test', 'stack_tests')

            # - s1/s2/s3
            print "s1/s2/s3"
            paths = [os.path.join(d, p) for p in ['s1', 's2', 's3']]
            os.environ[roslib.rosenv.ROS_PACKAGE_PATH] = os.pathsep.join(paths)
            # - run multiple times to test caching
            for i in xrange(2):
                stacks = roslib.stacks.list_stacks()
                self.assert_('foo' in stacks)
                self.assert_('bar' in stacks)

                foo_p = os.path.join(d, 's1', 'foo')
                bar_p = os.path.join(d, 's1', 'bar')
                self.assertEquals(foo_p, roslib.stacks.get_stack_dir('foo'))
                self.assertEquals(bar_p, roslib.stacks.get_stack_dir('bar'))

            # - s2/s3/s1
            print "s2/s3/s1"

            paths = [os.path.join(d, p) for p in ['s2', 's3', 's1']]
            os.environ[roslib.rosenv.ROS_PACKAGE_PATH] = os.pathsep.join(paths)
            stacks = roslib.stacks.list_stacks()
            self.assert_('foo' in stacks)
            self.assert_('bar' in stacks)

            foo_p = os.path.join(d, 's2', 'foo')
            bar_p = os.path.join(d, 's1', 'bar')
            self.assertEquals(foo_p, roslib.stacks.get_stack_dir('foo'))
            self.assertEquals(bar_p, roslib.stacks.get_stack_dir('bar'))
        finally:
            #restore rpp
            if rpp is not None:
                os.environ[roslib.rosenv.ROS_PACKAGE_PATH] = rpp
            else:
                del os.environ[roslib.rosenv.ROS_PACKAGE_PATH]
コード例 #6
0
    def test_list_stacks(self):
        from roslib.stacks import list_stacks
        l = list_stacks()
        self.assert_('ros' in l)

        # make sure it is equivalent to rosstack list
        from roslib.rospack import rosstackexec
        l2 = [x for x in rosstackexec(['list']).split('\n') if x]
        l2 = [x.split()[0] for x in l2]
        self.assertEquals(set(l), set(l2), set(l) ^ set(l2))
コード例 #7
0
    def test_list_stacks(self):
        from roslib.stacks import list_stacks
        # roslib can't depend on ros and therefore can't expect it being in the environment
        # l = list_stacks()
        # self.assert_('ros' in l)

        # test with env
        test_dir = os.path.join(roslib.packages.get_pkg_dir('roslib'), 'test', 'stack_tests', 's1')
        env = os.environ.copy()
        env['ROS_PACKAGE_PATH'] = test_dir
        val = set(list_stacks(env=env))
        # ros stack not guaranteed to list anymore as ROS_ROOT may not be set
        if 'ros' in val:
            val.remove('ros')
        self.assertEquals({'foo', 'bar'}, val)