def test_RosdepLookup_create_from_rospkg(): from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() # these are just tripwire, can't actually test as it depends on external env lookup = RosdepLookup.create_from_rospkg() lookup = RosdepLookup.create_from_rospkg(rospack=rospack) assert rospack == lookup.loader._rospack lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack) assert rospack == lookup.loader._rospack assert rosstack == lookup.loader._rosstack
def test_RosdepInstaller_install_resolved(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup from rosdep2.installers import RosdepInstaller from rosdep2.platforms.debian import APT_INSTALLER from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() # create our test fixture. use most of the default toolchain, but # replace the apt installer with one that we can have more fun # with. we will do all tests with ubuntu lucid keys -- other # tests should cover different resolution cases. sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) context = create_default_installer_context() context.set_os_override('ubuntu', 'lucid') installer = RosdepInstaller(context, lookup) with fakeout() as (stdout, stderr): installer.install_resolved(APT_INSTALLER, [], simulate=True, verbose=False) with fakeout() as (stdout, stderr): installer.install_resolved(APT_INSTALLER, [], simulate=True, verbose=True) assert stdout.getvalue().strip() == '#No packages to install' with fakeout() as (stdout, stderr): installer.install_resolved(APT_INSTALLER, ['rosdep-fake1', 'rosdep-fake2'], simulate=True, verbose=True) stdout_lines = [x.strip() for x in stdout.getvalue().split('\n') if x.strip()] assert stdout_lines == ['#[apt] Installation commands:', 'sudo apt-get install rosdep-fake1', 'sudo apt-get install rosdep-fake2', ], ("%s: %s"%(stdout.getvalue(), stdout_lines))
def check_duplicates(sources, os_name, os_codename): # output debug info print('checking sources') for source in sources: print('- %s' % source.url) # create loopkup sources_loader = SourcesListLoader(sources) lookup = RosdepLookup.create_from_rospkg(sources_loader=sources_loader) # check if duplicates print("checking duplicates") db_name_view = {} has_duplicates = False view = lookup.get_rosdep_view(DEFAULT_VIEW_KEY, verbose=None) # to call init for view_key in lookup.rosdep_db.get_view_dependencies(DEFAULT_VIEW_KEY): db_entry = lookup.rosdep_db.get_view_data(view_key) print('* %s' % view_key) for dep_name, dep_data in db_entry.rosdep_data.items(): # skip unknown os names if os_name not in dep_data.keys(): continue # skip unknown os codenames if ( isinstance(dep_data[os_name], dict) and os_codename not in dep_data[os_name].keys() ): continue if dep_name in db_name_view: print('%s is multiply defined in\n\t%s and \n\t%s\n' % (dep_name, db_name_view[dep_name], view_key)) has_duplicates = True db_name_view[dep_name] = view_key return not has_duplicates
def test_RosdepLookup_get_rosdep_view_for_resource(): from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY, RosPkgLoader rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # assumption of our tests assert isinstance(lookup.loader, RosPkgLoader) # depends on nothing cache_raw = get_cache_raw() py_cache_raw = get_cache_raw_python() # - first pass: no cache ros_view = lookup.get_rosdep_view_for_resource('roscpp_fake') libtool = ros_view.lookup('testlibtool') assert BASE_URL == libtool.origin assert cache_raw['testlibtool'] == libtool.data python = ros_view.lookup('testpython') assert PYTHON_URL == python.origin assert py_cache_raw['testpython'] == python.data # package not in stack, should return assert lookup.get_rosdep_view_for_resource('just_a_package').name is DEFAULT_VIEW_KEY
def test_RosdepLookup_get_rosdeps(): from rosdep2.loader import RosdepLoader from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) assert lookup.get_loader() is not None assert isinstance(lookup.get_loader(), RosdepLoader) print(lookup.get_rosdeps('empty_package')) assert lookup.get_rosdeps('empty_package') == [] try: assert lookup.get_rosdeps('not a resource') == [] assert False, "should have raised" except ResourceNotFound: pass print(lookup.get_rosdeps('stack1_p1')) assert set(lookup.get_rosdeps('stack1_p1')) == set( ['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) assert set(lookup.get_rosdeps('stack1_p1', implicit=False)) == set( ['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) print(lookup.get_rosdeps('stack1_p2')) assert set(lookup.get_rosdeps('stack1_p2', implicit=False)) == set( ['stack1_dep1', 'stack1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2')) assert set(lookup.get_rosdeps('stack1_p2', implicit=True)) == set([ 'stack1_dep1', 'stack1_dep2', 'stack1_p1_dep1', 'stack1_p1_dep2', 'stack1_p2_dep1' ]), set(lookup.get_rosdeps('stack1_p2')) # catkin print(lookup.get_rosdeps('simple_catkin_package')) assert set(lookup.get_rosdeps('simple_catkin_package')) == set( ['catkin', 'testboost']) assert set(lookup.get_rosdeps('simple_catkin_package', implicit=False)) == set( ['catkin', 'testboost']) print(lookup.get_rosdeps('another_catkin_package')) assert set(lookup.get_rosdeps('another_catkin_package')) == set( ['catkin', 'simple_catkin_package']) # implicit deps won't get included assert set(lookup.get_rosdeps('another_catkin_package', implicit=False)) == set( ['catkin', 'simple_catkin_package']) print(lookup.get_rosdeps('metapackage_with_deps')) assert set(lookup.get_rosdeps('metapackage_with_deps')) == set( ['catkin', 'simple_catkin_package', 'another_catkin_package']) # implicit deps won't get included assert set(lookup.get_rosdeps('metapackage_with_deps', implicit=False)) == set([ 'catkin', 'simple_catkin_package', 'another_catkin_package' ])
def get_rosdep(quiet): from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY from rosdep2.sources_list import SourcesListLoader sources_loader = SourcesListLoader.create_default() lookup = RosdepLookup.create_from_rospkg(sources_loader=sources_loader) return Rosdep(view=lookup.get_rosdep_view(DEFAULT_VIEW_KEY), quiet=quiet)
def test_RosdepLookup_get_rosdeps(): from rosdep2.loader import RosdepLoader from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rospack, sources_loader=sources_loader) assert lookup.get_loader() is not None assert isinstance(lookup.get_loader(), RosdepLoader) print(lookup.get_rosdeps('empty_package')) assert lookup.get_rosdeps('empty_package') == [] try: assert lookup.get_rosdeps('not a resource') == [] assert False, "should have raised" except ResourceNotFound: pass print(lookup.get_rosdeps('stack1_p1')) assert set(lookup.get_rosdeps('stack1_p1')) == set( ['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) assert set(lookup.get_rosdeps('stack1_p1', implicit=False)) == set( ['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) print(lookup.get_rosdeps('stack1_p2')) assert set(lookup.get_rosdeps('stack1_p2', implicit=False)) == set( ['stack1_dep1', 'stack1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2')) assert set(lookup.get_rosdeps('stack1_p2', implicit=True)) == set([ 'stack1_dep1', 'stack1_dep2', 'stack1_p1_dep1', 'stack1_p1_dep2', 'stack1_p2_dep1' ]), set(lookup.get_rosdeps('stack1_p2'))
def test_RosdepLookup_get_rosdep_view_for_resource(): from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY, RosPkgLoader rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # assumption of our tests assert isinstance(lookup.loader, RosPkgLoader) # depends on nothing cache_raw = get_cache_raw() py_cache_raw = get_cache_raw_python() # - first pass: no cache ros_view = lookup.get_rosdep_view_for_resource('roscpp_fake') libtool = ros_view.lookup('testlibtool') assert BASE_URL == libtool.origin assert cache_raw['testlibtool'] == libtool.data python = ros_view.lookup('testpython') assert PYTHON_URL == python.origin assert py_cache_raw['testpython'] == python.data # package not in stack, should return assert lookup.get_rosdep_view_for_resource( 'just_a_package').name is DEFAULT_VIEW_KEY # meta-packages should return default view as well assert lookup.get_rosdep_view_for_resource( 'metapackage_with_deps').name is DEFAULT_VIEW_KEY
def test_RosdepLookup_resolve(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) installer_context = create_default_installer_context() installer_context.set_os_override('ubuntu', 'lucid') # repeat for caching for count in xrange(0, 2): installer_key, resolution, dependencies = lookup.resolve('testtinyxml', 'rospack_fake', installer_context) assert 'apt' == installer_key assert ['libtinyxml-dev'] == resolution assert [] == dependencies installer_key, resolution, dependencies = lookup.resolve('testboost', 'roscpp_fake', installer_context) assert 'apt' == installer_key assert ['libboost1.40-all-dev'] == resolution assert [] == dependencies installer_key, resolution, dependencies = lookup.resolve('testlibtool', 'roscpp_fake', installer_context) assert 'apt' == installer_key assert set(['libtool', 'libltdl-dev']) == set(resolution) assert [] == dependencies
def test_RosdepLookup_resolve(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) installer_context = create_default_installer_context() installer_context.set_os_override('ubuntu', 'lucid') # repeat for caching for count in range(0, 2): installer_key, resolution, dependencies = lookup.resolve( 'testtinyxml', 'rospack_fake', installer_context) assert 'apt' == installer_key assert ['libtinyxml-dev'] == resolution assert [] == dependencies installer_key, resolution, dependencies = lookup.resolve( 'testboost', 'roscpp_fake', installer_context) assert 'apt' == installer_key assert ['libboost1.40-all-dev'] == resolution assert [] == dependencies installer_key, resolution, dependencies = lookup.resolve( 'testlibtool', 'roscpp_fake', installer_context) assert 'apt' == installer_key assert set(['libtool', 'libltdl-dev']) == set(resolution) assert [] == dependencies
def test_RosdepLookup_resolve_all(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) installer_context = create_default_installer_context() installer_context.set_os_override('ubuntu', 'lucid') # repeat for caching lookup.verbose = True for count in range(0, 2): resolutions, errors = lookup.resolve_all( ['rospack_fake', 'roscpp_fake'], installer_context) assert not errors, errors installer_keys, resolveds = zip(*resolutions) assert 'apt' in installer_keys apt_resolutions = [] for k, v in resolutions: if k == 'apt': apt_resolutions.extend(v) assert set(apt_resolutions) == set([ 'libtinyxml-dev', 'libboost1.40-all-dev', 'libtool', 'libltdl-dev' ]), set(apt_resolutions)
def test_RosdepLookup_get_rosdeps(): from rosdep2.loader import RosdepLoader from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rospack, sources_loader=sources_loader) assert lookup.get_loader() is not None assert isinstance(lookup.get_loader(), RosdepLoader) print(lookup.get_rosdeps('empty_package')) assert lookup.get_rosdeps('empty_package') == [] try: assert lookup.get_rosdeps('not a resource') == [] assert False, "should have raised" except ResourceNotFound: pass print(lookup.get_rosdeps('stack1_p1')) assert set(lookup.get_rosdeps('stack1_p1')) == set(['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) assert set(lookup.get_rosdeps('stack1_p1', implicit=False)) == set(['stack1_dep1', 'stack1_p1_dep1', 'stack1_p1_dep2']) print(lookup.get_rosdeps('stack1_p2')) assert set(lookup.get_rosdeps('stack1_p2', implicit=False)) == set(['stack1_dep1', 'stack1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2')) assert set(lookup.get_rosdeps('stack1_p2', implicit=True)) == set(['stack1_dep1', 'stack1_dep2', 'stack1_p1_dep1', 'stack1_p1_dep2', 'stack1_p2_dep1']), set(lookup.get_rosdeps('stack1_p2'))
def resolve_rosdep_key(key, quiet=False): sources_loader = SourcesListLoader.create_default( sources_cache_dir=get_sources_cache_dir(), os_override=None, verbose=False) lookup = RosdepLookup.create_from_rospkg(sources_loader=sources_loader) lookup.verbose = False installer_context = create_default_installer_context(verbose=False) installer, installer_keys, default_key, \ os_name, os_version = get_default_installer( installer_context=installer_context, verbose=False) view = lookup.get_rosdep_view(DEFAULT_VIEW_KEY, verbose=False) try: d = view.lookup(key) except KeyError as e: sys.stderr.write('Invalid key "{}": {}\n'.format(key, e)) return rule_installer, rule = d.get_rule_for_platform(os_name, os_version, installer_keys, default_key) installer = installer_context.get_installer(rule_installer) resolved = installer.resolve(rule) for error in lookup.get_errors(): if not quiet: print('WARNING: %s' % (error), file=sys.stderr) return {installer: resolved}
def get_rosdep(quiet): # pragma: no cover from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY from rosdep2.sources_list import SourcesListLoader sources_loader = SourcesListLoader.create_default() lookup = RosdepLookup.create_from_rospkg(sources_loader=sources_loader) return Rosdep(view=lookup.get_rosdep_view(DEFAULT_VIEW_KEY), quiet=quiet)
def get_rosdep(quiet): from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY from rosdep2.sources_list import SourcesListLoader dummy = DummyRospkg() sources_loader = SourcesListLoader.create_default() lookup = RosdepLookup.create_from_rospkg(rospack=dummy, rosstack=dummy, sources_loader=sources_loader) return Rosdep(view=lookup.get_rosdep_view(DEFAULT_VIEW_KEY), quiet=quiet)
def test_RosdepInstaller_get_uninstalled_unconfigured(): from rosdep2 import create_default_installer_context, RosdepInternalError from rosdep2.lookup import RosdepLookup, ResolutionError from rosdep2.installers import RosdepInstaller, PackageManagerInstaller from rosdep2.platforms.debian import APT_INSTALLER from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() # create our test fixture. we want to setup a fixture that cannot resolve the rosdep data in order to test error conditions lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) context = create_default_installer_context() context.set_os_override('ubuntu', 'lucid') installer = RosdepInstaller(context, lookup) # - delete the apt installer context.set_installer(APT_INSTALLER, None) for verbose in [True, False]: uninstalled, errors = installer.get_uninstalled(['empty'], verbose) assert not uninstalled, uninstalled assert not errors # make sure there is an error when we lookup something that resolves to an apt depend uninstalled, errors = installer.get_uninstalled(['roscpp_fake'], verbose) assert not uninstalled, uninstalled assert errors.keys() == ['roscpp_fake'] uninstalled, errors = installer.get_uninstalled(['roscpp_fake', 'stack1_p1'], verbose) assert not uninstalled, uninstalled assert set(errors.keys()) == set(['roscpp_fake', 'stack1_p1']) print(errors) assert isinstance(errors['roscpp_fake'], ResolutionError), errors['roscpp_fake'][0] # fake/bad installer to test that we re-cast general installer issues class BadInstaller(PackageManagerInstaller): def __init__(self): super(BadInstaller, self).__init__(lambda x: x) def get_packages_to_install(*args): raise Exception("deadbeef") context.set_installer(APT_INSTALLER, BadInstaller()) try: installer.get_uninstalled(['roscpp_fake']) assert False, "should have raised" except RosdepInternalError as e: assert 'apt' in str(e) # annoying mock to test generally impossible error condition from mock import Mock lookup = Mock(spec=RosdepLookup) lookup.resolve_all.return_value = ([('bad-key', ['stuff'])], []) installer = RosdepInstaller(context, lookup) try: installer.get_uninstalled(['roscpp_fake']) assert False, "should have raised" except RosdepInternalError: pass
def test_RosdepInstaller_ctor(): # tripwire/coverage from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup from rosdep2.installers import RosdepInstaller lookup = RosdepLookup.create_from_rospkg() context = create_default_installer_context() installer = RosdepInstaller(context, lookup) assert lookup == installer.lookup assert context == installer.installer_context
def test_RosdepLookup_get_resources_that_need(): from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) assert lookup.get_resources_that_need('fake') == [] assert set(lookup.get_resources_that_need('stack1_dep1')) == set(['stack1_p1', 'stack1_p2']) assert lookup.get_resources_that_need('stack1_dep2') == ['stack1_p2'] assert lookup.get_resources_that_need('stack1_p1_dep1') == ['stack1_p1']
def test_RosdepLookup_get_resources_that_need(): from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rospack, sources_loader=sources_loader) assert lookup.get_resources_that_need('fake') == [] assert set(lookup.get_resources_that_need('stack1_dep1')) == set(['stack1_p1', 'stack1_p2']) assert lookup.get_resources_that_need('stack1_dep2') == ['stack1_p2'] assert lookup.get_resources_that_need('stack1_p1_dep1') == ['stack1_p1']
def test_RosdepInstaller_get_uninstalled(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup from rosdep2.installers import RosdepInstaller from rosdep2.platforms.debian import APT_INSTALLER from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() # create our test fixture. use most of the default toolchain, but # replace the apt installer with one that we can have more fun # with. we will do all tests with ubuntu lucid keys -- other # tests should cover different resolution cases. sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) context = create_default_installer_context() context.set_os_override('ubuntu', 'lucid') installer = RosdepInstaller(context, lookup) # in this first test, detect_fn detects everything as installed fake_apt = get_fake_apt(lambda x: x) context.set_installer(APT_INSTALLER, fake_apt) for verbose in [True, False]: tests = [['roscpp_fake'], ['roscpp_fake', 'rospack_fake'], ['empty_package'], ['roscpp_fake', 'rospack_fake', 'empty_package'], ['roscpp_fake', 'rospack_fake'], ] for test in tests: uninstalled, errors = installer.get_uninstalled(test, verbose) assert not uninstalled, uninstalled assert not errors, errors # in this second test, detect_fn detects nothing as installed fake_apt = get_fake_apt(lambda x: []) context.set_installer(APT_INSTALLER, fake_apt) for verbose in [True, False]: uninstalled, errors = installer.get_uninstalled(['empty'], verbose) assert not uninstalled, uninstalled assert not errors expected = set(['libltdl-dev', 'libboost1.40-all-dev', 'libtool']) uninstalled, errors = installer.get_uninstalled(['roscpp_fake'], verbose) assert uninstalled.keys() == [APT_INSTALLER] assert set(uninstalled[APT_INSTALLER]) == expected assert not errors expected = ['libtinyxml-dev'] uninstalled, errors = installer.get_uninstalled(['rospack_fake'], verbose) assert uninstalled.keys() == [APT_INSTALLER] assert uninstalled[APT_INSTALLER] == expected, uninstalled assert not errors
def test_RosdepLookup_get_errors(): from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() tree_dir = get_test_tree_dir() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # shouldn't be any errors (yet) assert lookup.get_errors() == [] # force errors lookup._load_all_views(lookup.loader)
def test_RosdepInstaller_install_resolved(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup from rosdep2.installers import RosdepInstaller from rosdep2.platforms.debian import APT_INSTALLER from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() # create our test fixture. use most of the default toolchain, but # replace the apt installer with one that we can have more fun # with. we will do all tests with ubuntu lucid keys -- other # tests should cover different resolution cases. sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) context = create_default_installer_context() context.set_os_override('ubuntu', 'lucid') installer = RosdepInstaller(context, lookup) with fakeout() as (stdout, stderr): installer.install_resolved(APT_INSTALLER, [], simulate=True, verbose=False) with fakeout() as (stdout, stderr): installer.install_resolved(APT_INSTALLER, [], simulate=True, verbose=True) assert stdout.getvalue().strip() == '#No packages to install' with fakeout() as (stdout, stderr): try: installer.install_resolved(APT_INSTALLER, ['rosdep-fake1', 'rosdep-fake2'], simulate=True, verbose=True) except OSError as e: if str(e).count('[Errno 2] No such file or directory') == 0: raise return True stdout_lines = [ x.strip() for x in stdout.getvalue().split('\n') if x.strip() ] assert stdout_lines == [ '#[apt] Installation commands:', 'sudo apt-get install rosdep-fake1', 'sudo apt-get install rosdep-fake2', ], ("%s: %s" % (stdout.getvalue(), stdout_lines))
def testRosdepKey(self): ret = True sources_loader = SourcesListLoader.create_default(sources_cache_dir=get_sources_cache_dir()) lookup = RosdepLookup.create_from_rospkg(sources_loader=sources_loader) view = lookup.get_rosdep_view(DEFAULT_VIEW_KEY, verbose=None) # to call init db_name_view = dict() for view_key in lookup.rosdep_db.get_view_dependencies(DEFAULT_VIEW_KEY): db_entry=lookup.rosdep_db.get_view_data(view_key) for dep_name, dep_data in db_entry.rosdep_data.items(): if dep_name in db_name_view: print("%s is multiply defined in\n\t%s and \n\t%s\n"%(dep_name, db_name_view[dep_name], view_key)) ret = False db_name_view[dep_name] = view_key self.assertTrue(ret)
def test_RosdepLookup_resolve_all_errors(): from rosdep2.installers import InstallerContext from rosdep2.lookup import RosdepLookup, ResolutionError rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # the installer context has nothing in it, lookups will fail installer_context = InstallerContext() installer_context.set_os_override('ubuntu', 'lucid') resolutions, errors = lookup.resolve_all(['rospack_fake'], installer_context) assert 'rospack_fake' in errors resolutions, errors = lookup.resolve_all(['not_a_resource'], installer_context) assert 'not_a_resource' in errors, errors
def test_RosdepLookup_get_views_that_define(): from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() tree_dir = get_test_tree_dir() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) val = lookup.get_views_that_define('testboost') assert len(val) == 1 entry = val[0] assert entry == (BASE_URL, BASE_URL), entry val = lookup.get_views_that_define('testpython') assert len(val) == 1 entry = val[0] assert entry == (PYTHON_URL, PYTHON_URL), entry
def test_RosdepLookup_resolve_all(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) installer_context = create_default_installer_context() installer_context.set_os_override('ubuntu', 'lucid') # repeat for caching lookup.verbose = True for count in xrange(0, 2): resolutions, errors = lookup.resolve_all(['rospack_fake', 'roscpp_fake'], installer_context) assert not errors, errors assert 'apt' in resolutions assert set(resolutions['apt']) == set(['libtinyxml-dev', 'libboost1.40-all-dev', 'libtool', 'libltdl-dev']), set(resolutions['apt'])
def __init__(self, rosdep_view=None): self.manifests = {} self.known_catkin_pkgs = set([]) self.known_other_pkgs = set([]) if rosdep_view is None: try: from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY from rosdep2.sources_list import SourcesListLoader sources_loader = SourcesListLoader.create_default() lookup = RosdepLookup.create_from_rospkg(sources_loader=sources_loader) self.rosdep_view = lookup.get_rosdep_view(DEFAULT_VIEW_KEY) except Exception as err: sys.stderr.write("catkin_lint: cannot load rosdep database: %s\n" % str(err)) sys.stderr.write("catkin_lint: unknown dependencies will be ignored\n") self.rosdep_view = {} else: self.rosdep_view = rosdep_view self.cache = {}
def __init__(self): self.cached_installers = {} gc.disable() try: import sys from . import dummy_pkg_resources sys.modules["pkg_resources"] = dummy_pkg_resources from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY from rosdep2 import get_default_installer, create_default_installer_context self.lookup = RosdepLookup.create_from_rospkg(rospack=DummyRospkg(), rosstack=DummyRospkg()) self.view = self.lookup.get_rosdep_view(DEFAULT_VIEW_KEY) self.installer_ctx = create_default_installer_context() _, self.installer_keys, self.default_key, \ self.os_name, self.os_version = get_default_installer(self.installer_ctx) except Exception as e: error("failed to initialize rosdep: %s" % str(e)) self.view = None gc.enable()
def __init__(self): self.cached_installers = {} gc.disable() try: import sys from . import dummy_pkg_resources sys.modules["pkg_resources"] = dummy_pkg_resources from rosdep2.lookup import RosdepLookup from rosdep2.rospkg_loader import DEFAULT_VIEW_KEY from rosdep2 import get_default_installer, create_default_installer_context self.lookup = RosdepLookup.create_from_rospkg( rospack=DummyRospkg(), rosstack=DummyRospkg()) self.view = self.lookup.get_rosdep_view(DEFAULT_VIEW_KEY) self.installer_ctx = create_default_installer_context() _, self.installer_keys, self.default_key, \ self.os_name, self.os_version = get_default_installer(self.installer_ctx) except Exception as e: error("failed to initialize rosdep: %s" % str(e)) self.view = None gc.enable()
def test_RosdepLookup_get_rosdep_view(): from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # depends on nothing cache_raw = get_cache_raw() py_cache_raw = get_cache_raw_python() # - first pass: no cache ros_view = lookup.get_rosdep_view('ros') libtool = ros_view.lookup('testlibtool') assert BASE_URL == libtool.origin assert cache_raw['testlibtool'] == libtool.data python = ros_view.lookup('testpython') assert PYTHON_URL == python.origin assert py_cache_raw['testpython'] == python.data, python.data # - second pass: with cache ros_view = lookup.get_rosdep_view('ros') libtool = ros_view.lookup('testlibtool') assert BASE_URL == libtool.origin assert cache_raw['testlibtool'] == libtool.data # depends on ros stack1_view = lookup.get_rosdep_view('stack1') stack1_rosdep_path = os.path.join(rosstack.get_path('stack1'), 'rosdep.yaml') # - make sure ros data is available libtool = stack1_view.lookup('testlibtool') assert BASE_URL == libtool.origin assert cache_raw['testlibtool'] == libtool.data python = stack1_view.lookup('testpython') assert PYTHON_URL == python.origin assert py_cache_raw['testpython'] == python.data
def test_RosdepLookup_resolve_errors(): from rosdep2.installers import InstallerContext from rosdep2.lookup import RosdepLookup, ResolutionError rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # the installer context has nothing in it, lookups will fail installer_context = InstallerContext() installer_context.set_os_override('ubuntu', 'lucid') try: lookup.resolve('testtinyxml', 'rospack_fake', installer_context) assert False, 'should have raised' except ResolutionError as e: assert 'Unsupported OS' in str(e), str(e) try: lookup.resolve('fakedep', 'rospack_fake', installer_context) assert False, 'should have raised' except ResolutionError as e: assert 'Cannot locate rosdep definition' in str(e), str(e)
def test_RosdepLookup_resolve_errors(): from rosdep2.installers import InstallerContext from rosdep2.lookup import RosdepLookup, ResolutionError rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) # the installer context has nothing in it, lookups will fail installer_context = InstallerContext() installer_context.set_os_override('ubuntu', 'lucid') try: lookup.resolve('testtinyxml', 'rospack_fake', installer_context) assert False, "should have raised" except ResolutionError as e: assert "Unsupported OS" in str(e), str(e) try: lookup.resolve('fakedep', 'rospack_fake', installer_context) assert False, "should have raised" except ResolutionError as e: assert "Cannot locate rosdep definition" in str(e), str(e)
def test_RosdepInstaller_get_uninstalled_unconfigured(): from rosdep2 import create_default_installer_context, RosdepInternalError from rosdep2.lookup import RosdepLookup, ResolutionError from rosdep2.installers import RosdepInstaller, PackageManagerInstaller from rosdep2.platforms.debian import APT_INSTALLER from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() # create our test fixture. we want to setup a fixture that cannot resolve the rosdep data in order to test error conditions lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) context = create_default_installer_context() context.set_os_override('ubuntu', 'lucid') installer = RosdepInstaller(context, lookup) # - delete the apt installer context.set_installer(APT_INSTALLER, None) for verbose in [True, False]: uninstalled, errors = installer.get_uninstalled(['empty'], verbose) assert not uninstalled, uninstalled assert not errors # make sure there is an error when we lookup something that resolves to an apt depend uninstalled, errors = installer.get_uninstalled(['roscpp_fake'], verbose) assert not uninstalled, uninstalled assert list(errors.keys()) == ['roscpp_fake'] uninstalled, errors = installer.get_uninstalled( ['roscpp_fake', 'stack1_p1'], verbose) assert not uninstalled, uninstalled assert set(errors.keys()) == set(['roscpp_fake', 'stack1_p1']) print(errors) assert isinstance(errors['roscpp_fake'], ResolutionError), errors['roscpp_fake'][0] # fake/bad installer to test that we re-cast general installer issues class BadInstaller(PackageManagerInstaller): def __init__(self): super(BadInstaller, self).__init__(lambda x: x) def get_packages_to_install(*args): raise Exception("deadbeef") context.set_installer(APT_INSTALLER, BadInstaller()) try: installer.get_uninstalled(['roscpp_fake']) assert False, "should have raised" except RosdepInternalError as e: assert 'apt' in str(e) # annoying mock to test generally impossible error condition from mock import Mock lookup = Mock(spec=RosdepLookup) lookup.resolve_all.return_value = ([('bad-key', ['stuff'])], []) installer = RosdepInstaller(context, lookup) try: installer.get_uninstalled(['roscpp_fake']) assert False, "should have raised" except RosdepInternalError: pass
def test_RosdepInstaller_get_uninstalled(): from rosdep2 import create_default_installer_context from rosdep2.lookup import RosdepLookup from rosdep2.installers import RosdepInstaller from rosdep2.platforms.debian import APT_INSTALLER from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() # create our test fixture. use most of the default toolchain, but # replace the apt installer with one that we can have more fun # with. we will do all tests with ubuntu lucid keys -- other # tests should cover different resolution cases. sources_loader = create_test_SourcesListLoader() lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) context = create_default_installer_context() context.set_os_override('ubuntu', 'lucid') installer = RosdepInstaller(context, lookup) # in this first test, detect_fn detects everything as installed fake_apt = get_fake_apt(lambda x: x) context.set_installer(APT_INSTALLER, fake_apt) for verbose in [True, False]: tests = [ ['roscpp_fake'], ['roscpp_fake', 'rospack_fake'], ['empty_package'], ['roscpp_fake', 'rospack_fake', 'empty_package'], ['roscpp_fake', 'rospack_fake'], ] for test in tests: uninstalled, errors = installer.get_uninstalled(test, verbose) assert not uninstalled, uninstalled assert not errors, errors # in this second test, detect_fn detects nothing as installed fake_apt = get_fake_apt(lambda x: []) context.set_installer(APT_INSTALLER, fake_apt) for verbose in [True, False]: uninstalled, errors = installer.get_uninstalled(['empty'], verbose) assert not uninstalled, uninstalled assert not errors expected = set(['libltdl-dev', 'libboost1.40-all-dev', 'libtool']) uninstalled, errors = installer.get_uninstalled(['roscpp_fake'], verbose) keys, values = zip(*uninstalled) apt_uninstalled = [] for k, v in uninstalled: if k == APT_INSTALLER: apt_uninstalled.extend(v) assert list(set(keys)) == [APT_INSTALLER] assert set(apt_uninstalled) == expected assert not errors expected = ['libtinyxml-dev'] uninstalled, errors = installer.get_uninstalled(['rospack_fake'], verbose) keys, values = zip(*uninstalled) apt_uninstalled = [] for k, v in uninstalled: if k == APT_INSTALLER: apt_uninstalled.extend(v) assert list(set(keys)) == [APT_INSTALLER] assert apt_uninstalled == expected, uninstalled assert not errors
def __init__(self): self.installer_context = create_default_installer_context() _, self.installer_keys, self.default_key, self.os_name, self.os_version = get_default_installer( installer_context=self.installer_context) self.lookup = RosdepLookup.create_from_rospkg() self.rosdep_view = self.lookup.get_rosdep_view(DEFAULT_VIEW_KEY)
def test_RosdepLookup_dependency_types(): from rosdep2.loader import RosdepLoader from rosdep2.lookup import RosdepLookup rospack, rosstack = get_test_rospkgs() sources_loader = create_test_SourcesListLoader() default_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader) buildtool_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['buildtool']) build_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['build']) build_export_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['build_export']) exec_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['exec']) run_lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['run']) test_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['test']) doc_lookup = RosdepLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['doc']) mix_lookup = RosdepLookup.create_from_rospkg( rospack=rospack, rosstack=rosstack, sources_loader=sources_loader, dependency_types=['build', 'build_export']) buildtool_deps = ['catkin'] build_deps = ['testboost', 'eigen'] build_export_deps = ['eigen', 'testtinyxml'] exec_deps = ['eigen', 'testlibtool'] run_deps = ['eigen', 'testlibtool', 'testtinyxml'] # build_export + exec test_deps = ['curl'] doc_deps = ['epydoc'] default_deps = buildtool_deps + build_deps + build_export_deps + exec_deps + test_deps assert set(buildtool_lookup.get_rosdeps( 'multi_dep_type_catkin_package')) == set(buildtool_deps) assert set(build_lookup.get_rosdeps( 'multi_dep_type_catkin_package')) == set(build_deps) assert set(build_export_lookup.get_rosdeps( 'multi_dep_type_catkin_package')) == set(build_export_deps) assert set(exec_lookup.get_rosdeps( 'multi_dep_type_catkin_package')) == set(exec_deps) assert set(run_lookup.get_rosdeps('multi_dep_type_catkin_package')) == set( run_deps) assert set(test_lookup.get_rosdeps( 'multi_dep_type_catkin_package')) == set(test_deps) assert set(mix_lookup.get_rosdeps('multi_dep_type_catkin_package')) == set( build_deps + build_export_deps) assert set(default_lookup.get_rosdeps( 'multi_dep_type_catkin_package')) == set(default_deps) assert set(doc_lookup.get_rosdeps('multi_dep_type_catkin_package')) == set( doc_deps)