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_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 install_rapp_dependencies(self, rapp_names): ''' Install the dependencies for a given list of Rapps. :param rapp_name: A C{list} of ROCON URIs :raises: NonInstallableRappException: Any of the ROCON URIs are not installable ''' deps = self.check_rapp_dependencies(rapp_names) uninstallable_rapps = [k for k, v in deps.items() if v.noninstallable] if uninstallable_rapps: raise NonInstallableRappException(uninstallable_rapps) installable = [d for v in deps.values() for d in v.installable] pkg_deps = list(set(installable)) rosdep_installer = RosdepInstaller(self.installer_context, self.lookup) rosdep_installer.install_resolved(self.default_key, pkg_deps)
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