def test_get_stack_version(): from rospkg import get_stack_version_by_dir, RosStack path = os.path.join(get_stack_test_path(), 's1') r = RosStack(ros_paths=[path]) # test by dir option directly foo_dir = r.get_path('foo') assert get_stack_version_by_dir(foo_dir) == '1.6.0-manifest' bar_dir = r.get_path('bar') assert get_stack_version_by_dir(bar_dir) == '1.5.0-cmake' # test via rosstack assert r.get_stack_version('foo') == '1.6.0-manifest' assert r.get_stack_version('bar') == '1.5.0-cmake' path = os.path.join(get_stack_test_path(), 's2') r = RosStack(ros_paths=[path]) foo_dir = r.get_path('foo') assert get_stack_version_by_dir(foo_dir) is None, get_stack_version_by_dir( foo_dir) # test reading from stack.yaml baz_dir = r.get_path('baz') assert get_stack_version_by_dir( baz_dir) == '1-manifest', get_stack_version_by_dir(baz_dir) assert r.get_stack_version('baz') == '1-manifest'
def test_unary(): from rospkg import RosStack, RosPack path = get_unary_test_path() rospack = RosPack(ros_paths=[path]) rosstack = RosStack(ros_paths=[path]) assert rospack.get_path('unary') == rosstack.get_path('unary') assert rosstack.packages_of('unary') == ['unary'] assert rospack.stack_of('unary') == 'unary'
def __init__(self, alt_paths = None): self.packages = [] self.rospack = RosPack.get_instance() self.rosstack = RosStack.get_instance() if alt_paths is None: self.altpack = self.rospack self.altstack = self.rosstack else: self.altpack = RosPack.get_instance(alt_paths) self.altstack = RosStack.get_instance(alt_paths)
def _get_packages_in_environment(): global _packages_in_environment if _packages_in_environment is None: if ROS_PACKAGE_PATH not in os.environ or not os.environ[ROS_PACKAGE_PATH]: raise RuntimeError("The environment variable '%s' must be set when using '%s'" % (ROS_PACKAGE_PATH, ARG_CURRENT_ENVIRONMENT)) _packages_in_environment = set([]) rs = RosStack() _packages_in_environment.update(set(rs.list())) rp = RosPack() _packages_in_environment.update(set(rp.list())) return _packages_in_environment
def get_test_rospkgs(): test_dir = get_test_tree_dir() ros_root = os.path.join(test_dir, 'ros') ros_package_path = os.path.join(test_dir, 'stacks') ros_paths = [ros_root, ros_package_path] rospack = RosPack(ros_paths=ros_paths) rosstack = RosStack(ros_paths=ros_paths) return rospack, rosstack
def get_rospkg(): # configure inside of the test tree test_dir = get_test_dir() ros_root = os.path.join(test_dir, 'ros') ros_package_path = os.path.join(test_dir, 'stacks') ros_paths = [ros_root, ros_package_path] rospack = RosPack(ros_paths=ros_paths) rosstack = RosStack(ros_paths=ros_paths) return rospack, rosstack
def test_RosStack_get_depends_explicit(): from rospkg import RosStack, ResourceNotFound, get_ros_paths path = get_stack_test_path() s1 = os.path.join(path, 's1') s3 = os.path.join(path, 's3') r = RosStack(ros_paths=[s1, s3]) implicit = False assert set(r.get_depends('baz', implicit)) == set(['bar', 'foo']) assert r.get_depends('bar', implicit) == ['foo'] assert r.get_depends('foo', implicit) == [] # stress test: test default environment against rospack if get_ros_paths(): r = RosStack() for p in rosstack_list(): retval = set(r.get_depends(p, implicit)) rospackval = set(rosstack_depends1(p)) assert retval == rospackval, "[%s]: %s vs. %s"%(p, retval, rospackval)
def test_RosStack_get_depends(): from rospkg import RosStack, ResourceNotFound, get_ros_paths path = get_stack_test_path() s1 = os.path.join(path, 's1') s3 = os.path.join(path, 's3') r = RosStack(ros_paths=[s1, s3]) # TODO: need one more step assert set(r.get_depends('baz')) == set(['foo', 'bar']) assert r.get_depends('bar') == ['foo'] assert r.get_depends('foo') == [] if get_ros_paths(): # stress test: test default environment against rosstack r = RosStack() for p in rosstack_list(): retval = set(r.get_depends(p)) rospackval = set(rosstack_depends(p)) assert retval == rospackval, "[%s]: %s vs. %s"%(p, retval, rospackval)
def test_RosStack_list(): from rospkg import RosStack, get_ros_paths, get_ros_package_path print("ROS paths", get_ros_paths()) if get_ros_paths() is not None: r = RosStack() l = rosstack_list() retval = r.list() assert set(l) == set(retval), "%s vs %s"%(l, retval) # test twice for caching retval = r.list() assert set(l) == set(retval), "%s vs %s"%(l, retval) # make sure stress test works with rospack_cache invalidated delete_cache() r = RosStack() retval = r.list() assert set(l) == set(retval), "%s vs %s"%(l, retval)
def create_from_rospkg(rospack=None, rosstack=None, sources_loader=None, verbose=False): """ Create :class:`RosdepLookup` based on current ROS package environment. :param rospack: (optional) Override :class:`rospkg.RosPack` instance used to crawl ROS packages. :param rosstack: (optional) Override :class:`rospkg.RosStack` instance used to crawl ROS stacks. :param sources_loader: (optional) Override SourcesLoader used for managing sources.list data sources. """ # initialize the loader if rospack is None: rospack = RosPack() if rosstack is None: rosstack = RosStack() if sources_loader is None: sources_loader = SourcesListLoader.create_default(verbose=verbose) rosdep_db = RosdepDatabase() # Use sources list to initialize rosdep_db. Underlay has no # notion of specific resources, and its view keys are just the # individual sources it can load from. SourcesListLoader # cannot do delayed evaluation of OS setting due to matcher. underlay_key = SourcesListLoader.ALL_VIEW_KEY # Create the rospkg loader on top of the underlay loader = RosPkgLoader(rospack=rospack, rosstack=rosstack, underlay_key=underlay_key) # create our actual instance lookup = RosdepLookup(rosdep_db, loader) # load in the underlay lookup._load_all_views(loader=sources_loader) # use dependencies to implement precedence view_dependencies = sources_loader.get_loadable_views() rosdep_db.set_view_data(underlay_key, {}, view_dependencies, underlay_key) return lookup
def test_ManifestManager_constructor(): from rospkg import RosPack, RosStack, get_ros_paths r = RosPack() assert r._manifest_name == 'manifest.xml' r = RosStack() assert r._manifest_name == 'stack.xml' for c in [RosPack, RosStack]: r = c() assert r.ros_paths == get_ros_paths() tmp = tempfile.gettempdir() r = c(ros_paths=[tmp]) assert r.ros_paths == [tmp] # make sure we can't accidentally mutate the actual data r.ros_paths.append('foo') assert r.ros_paths == [tmp]
def test_expand_to_packages(): from rospkg import expand_to_packages, RosPack, RosStack path = os.path.join(get_stack_test_path(), 's1') rospack = RosPack(ros_paths=[path]) rosstack = RosStack(ros_paths=[path]) try: expand_to_packages('foo', rospack, rosstack) assert False, "should have raised ValueError" except ValueError: pass valid, invalid = expand_to_packages(['foo'], rospack, rosstack) assert set(valid) == set(['foo_pkg', 'foo_pkg_2']) assert not invalid valid, invalid = expand_to_packages(['foo_pkg'], rospack, rosstack) assert set(valid) == set(['foo_pkg']) assert not invalid valid, invalid = expand_to_packages(['foo', 'foo_pkg'], rospack, rosstack) assert set(valid) == set(['foo_pkg', 'foo_pkg_2']) assert not invalid valid, invalid = expand_to_packages(['foo', 'bar'], rospack, rosstack) assert set(valid) == set(['foo_pkg', 'foo_pkg_2', 'bar_pkg']) assert not invalid valid, invalid = expand_to_packages(['foo', 'bar_pkg'], rospack, rosstack) assert set(valid) == set(['foo_pkg', 'foo_pkg_2', 'bar_pkg']) assert not invalid valid, invalid = expand_to_packages(['foo', 'bar_pkg', 'bar'], rospack, rosstack) assert set(valid) == set(['foo_pkg', 'foo_pkg_2', 'bar_pkg']) assert not invalid valid, invalid = expand_to_packages( ['foo', 'fake1', 'bar_pkg', 'bar', 'fake2'], rospack, rosstack) assert set(valid) == set(['foo_pkg', 'foo_pkg_2', 'bar_pkg']) assert set(invalid) == set(['fake1', 'fake2'])
def test_RosStack_get_depends_explicit(): from rospkg import RosStack, ResourceNotFound, get_ros_paths path = get_stack_test_path() s1 = os.path.join(path, 's1') s3 = os.path.join(path, 's3') r = RosStack(ros_paths=[s1, s3]) implicit = False assert set(r.get_depends('baz', implicit)) == set(['bar', 'foo']) assert r.get_depends('bar', implicit) == ['foo'] assert r.get_depends('foo', implicit) == [] # stress test: test default environment against rospack if get_ros_paths() and rosstack_is_available(): r = RosStack() for p in rosstack_list(): retval = set(r.get_depends(p, implicit)) rospackval = set(rosstack_depends1(p)) assert retval == rospackval, "[%s]: %s vs. %s"%(p, retval, rospackval)
def test_RosStack_get_depends(): from rospkg import get_ros_paths, RosStack path = get_stack_test_path() s1 = os.path.join(path, 's1') s3 = os.path.join(path, 's3') r = RosStack(ros_paths=[s1, s3]) # TODO: need one more step assert set(r.get_depends('baz')) == set(['foo', 'bar']) assert r.get_depends('bar') == ['foo'] assert r.get_depends('foo') == [] if get_ros_paths() and rosstack_is_available(): # stress test: test default environment against rosstack r = RosStack() for p in rosstack_list(): retval = set(r.get_depends(p)) rospackval = set(rosstack_depends(p)) assert retval == rospackval, "[%s]: %s vs. %s" % (p, retval, rospackval)
def test_RosStack_list(): from rospkg import get_ros_paths, RosStack print("ROS paths", get_ros_paths()) if get_ros_paths() is not None and rosstack_is_available(): r = RosStack() l = rosstack_list() retval = r.list() assert set(l) == set(retval), "%s vs %s" % (l, retval) # test twice for caching retval = r.list() assert set(l) == set(retval), "%s vs %s" % (l, retval) # make sure stress test works with rospack_cache invalidated delete_cache() r = RosStack() retval = r.list() assert set(l) == set(retval), "%s vs %s" % (l, retval)
def test_get_stack_version(): from rospkg import get_stack_version_by_dir, RosStack path = os.path.join(get_stack_test_path(), 's1') r = RosStack(ros_paths=[path]) # test by dir option directly foo_dir = r.get_path('foo') assert get_stack_version_by_dir(foo_dir) == '1.6.0-manifest' bar_dir = r.get_path('bar') assert get_stack_version_by_dir(bar_dir) == '1.5.0-cmake' # test via rosstack assert r.get_stack_version('foo') == '1.6.0-manifest' assert r.get_stack_version('bar') == '1.5.0-cmake' path = os.path.join(get_stack_test_path(), 's2') r = RosStack(ros_paths=[path]) foo_dir = r.get_path('foo') assert get_stack_version_by_dir(foo_dir) == None, get_stack_version_by_dir(foo_dir) # test reading from stack.yaml baz_dir = r.get_path('baz') assert get_stack_version_by_dir(baz_dir) == '1.7.3', get_stack_version_by_dir(baz_dir) assert r.get_stack_version('baz') == '1.7.3'
def test_RosStack_get_path(): from rospkg import RosStack, ResourceNotFound, get_ros_paths path = get_stack_test_path() bar_path = os.path.join(path, 's1', 'bar') baz_path = os.path.join(path, 's2', 'baz') # point ROS_ROOT at top, should spider entire tree print("ROS_PATHS: %s"%str([path])) print("ROS_PACKAGE_PATH: ") r = RosStack(ros_paths=[path]) assert bar_path == r.get_path('bar'), "%s vs. %s"%(bar_path, r.get_path('bar')) try: r.get_path('fake') assert False except ResourceNotFound: pass # divide tree in half to test precedence print("ROS PATH 1: %s"%(os.path.join(path, 'p1'))) print("ROS PATH 2: %s"%(os.path.join(path, 'p2'))) foo_path = os.path.join(path, 's1', 'foo') r = RosStack(ros_paths=[os.path.join(path, 's1'), os.path.join(path, 's2')]) assert foo_path == r.get_path('foo'), "%s vs. %s"%(foo_path, r.get_path('foo')) assert bar_path == r.get_path('bar') assert baz_path == r.get_path('baz') # divide tree in half again and test precedence of ROS_PACKAGE_PATH (foo should switch) print("ROS_ROOT: %s"%(os.path.join(path, 'p1'))) print("ROS_PACKAGE_PATH: %s"%(os.path.join(path, 'p2'))) foo_path = os.path.join(path, 's2', 'foo') ros_paths = [os.path.join(path, 'notapath'), os.path.join(path, 's2'), os.path.join(path, 's1')] r = RosStack(ros_paths=ros_paths) assert foo_path == r.get_path('foo'), "%s vs. %s"%(foo_path, r.get_path('foo')) if get_ros_paths(): # stresstest against rospack r = RosStack() listval = rosstack_list() for p in listval: retval = r.get_path(p) rospackval = rosstack_find(p) assert retval == rospackval, "[%s]: %s vs. %s"%(p, retval, rospackval) # stresstest with cache invalidated delete_cache() r = RosStack() for p in listval: retval = r.get_path(p) rospackval = rosstack_find(p) assert retval == rospackval, "[%s]: %s vs. %s"%(p, retval, rospackval)
def test_RosStack_get_path(): from rospkg import RosStack, ResourceNotFound, get_ros_paths path = get_stack_test_path() bar_path = os.path.join(path, 's1', 'bar') baz_path = os.path.join(path, 's2', 'baz') # point ROS_ROOT at top, should spider entire tree print("ROS_PATHS: %s" % str([path])) print("ROS_PACKAGE_PATH: ") r = RosStack(ros_paths=[path]) assert bar_path == r.get_path('bar'), "%s vs. %s" % (bar_path, r.get_path('bar')) try: r.get_path('fake') assert False except ResourceNotFound: pass # divide tree in half to test precedence print("ROS PATH 1: %s" % (os.path.join(path, 'p1'))) print("ROS PATH 2: %s" % (os.path.join(path, 'p2'))) foo_path = os.path.join(path, 's1', 'foo') r = RosStack( ros_paths=[os.path.join(path, 's1'), os.path.join(path, 's2')]) assert foo_path == r.get_path('foo'), "%s vs. %s" % (foo_path, r.get_path('foo')) assert bar_path == r.get_path('bar') assert baz_path == r.get_path('baz') # divide tree in half again and test precedence of ROS_PACKAGE_PATH (foo should switch) print("ROS_ROOT: %s" % (os.path.join(path, 'p1'))) print("ROS_PACKAGE_PATH: %s" % (os.path.join(path, 'p2'))) foo_path = os.path.join(path, 's2', 'foo') ros_paths = [ os.path.join(path, 'notapath'), os.path.join(path, 's2'), os.path.join(path, 's1') ] r = RosStack(ros_paths=ros_paths) assert foo_path == r.get_path('foo'), "%s vs. %s" % (foo_path, r.get_path('foo')) if get_ros_paths() and rosstack_is_available(): # stresstest against rospack r = RosStack() listval = rosstack_list() for p in listval: retval = r.get_path(p) rospackval = rosstack_find(p) assert retval == rospackval, "[%s]: %s vs. %s" % (p, retval, rospackval) # stresstest with cache invalidated delete_cache() r = RosStack() for p in listval: retval = r.get_path(p) rospackval = rosstack_find(p) assert retval == rospackval, "[%s]: %s vs. %s" % (p, retval, rospackval)