Ejemplo n.º 1
0
def test_xylemInstaller_install_resolved():
    from xylem import create_default_installer_context
    from xylem.lookup import xylemLookup
    from xylem.installers import xylemInstaller
    from xylem.platforms.debian import APT_INSTALLER
    
    from xylem.lookup import xylemLookup
    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 = xylemLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader)
    context = create_default_installer_context()
    context.set_os_override('ubuntu', 'lucid')
    installer = xylemInstaller(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, ['xylem-fake1', 'xylem-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 xylem-fake1',
                            'sudo apt-get install xylem-fake2',
                            ], ("%s: %s"%(stdout.getvalue(), stdout_lines))
Ejemplo n.º 2
0
def test_xylemInstaller_get_uninstalled_unconfigured():
    from xylem import create_default_installer_context, xylemInternalError
    from xylem.lookup import xylemLookup, ResolutionError
    from xylem.installers import xylemInstaller, PackageManagerInstaller
    from xylem.platforms.debian import APT_INSTALLER
    
    from xylem.lookup import xylemLookup
    rospack, rosstack = get_test_rospkgs()
    
    sources_loader = create_test_SourcesListLoader()
    # create our test fixture.  we want to setup a fixture that cannot resolve the xylem data in order to test error conditions
    lookup = xylemLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader)
    context = create_default_installer_context()
    context.set_os_override('ubuntu', 'lucid')
    installer = xylemInstaller(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 xylemInternalError as e:
        assert 'apt' in str(e)
    
    # annoying mock to test generally impossible error condition
    from mock import Mock
    lookup = Mock(spec=xylemLookup)
    lookup.resolve_all.return_value = ([('bad-key', ['stuff'])], [])
    
    installer = xylemInstaller(context, lookup)
    try:
        installer.get_uninstalled(['roscpp_fake'])
        assert False, "should have raised"
    except xylemInternalError:
        pass
Ejemplo n.º 3
0
def test_xylemInstaller_ctor():
    # tripwire/coverage
    from xylem import create_default_installer_context
    from xylem.lookup import xylemLookup
    from xylem.installers import xylemInstaller
    lookup = xylemLookup.create_from_rospkg()
    context = create_default_installer_context()
    installer = xylemInstaller(context, lookup)
    assert lookup == installer.lookup
    assert context == installer.installer_context
Ejemplo n.º 4
0
def test_xylemInstaller_ctor():
    # tripwire/coverage
    from xylem import create_default_installer_context
    from xylem.lookup import xylemLookup
    from xylem.installers import xylemInstaller
    lookup = xylemLookup.create_from_rospkg()
    context = create_default_installer_context()
    installer = xylemInstaller(context, lookup)
    assert lookup == installer.lookup
    assert context == installer.installer_context    
Ejemplo n.º 5
0
def test_xylemInstaller_install_resolved():
    from xylem import create_default_installer_context
    from xylem.lookup import xylemLookup
    from xylem.installers import xylemInstaller
    from xylem.platforms.debian import APT_INSTALLER

    from xylem.lookup import xylemLookup
    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 = xylemLookup.create_from_rospkg(rospack=rospack,
                                            rosstack=rosstack,
                                            sources_loader=sources_loader)
    context = create_default_installer_context()
    context.set_os_override('ubuntu', 'lucid')
    installer = xylemInstaller(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,
                                   ['xylem-fake1', 'xylem-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 xylem-fake1',
        'sudo apt-get install xylem-fake2',
    ], ("%s: %s" % (stdout.getvalue(), stdout_lines))
Ejemplo n.º 6
0
def test_xylemInstaller_get_uninstalled_unconfigured():
    from xylem import create_default_installer_context, xylemInternalError
    from xylem.lookup import xylemLookup, ResolutionError
    from xylem.installers import xylemInstaller, PackageManagerInstaller
    from xylem.platforms.debian import APT_INSTALLER

    from xylem.lookup import xylemLookup
    rospack, rosstack = get_test_rospkgs()

    sources_loader = create_test_SourcesListLoader()
    # create our test fixture.  we want to setup a fixture that cannot resolve the xylem data in order to test error conditions
    lookup = xylemLookup.create_from_rospkg(rospack=rospack,
                                            rosstack=rosstack,
                                            sources_loader=sources_loader)
    context = create_default_installer_context()
    context.set_os_override('ubuntu', 'lucid')
    installer = xylemInstaller(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 xylemInternalError as e:
        assert 'apt' in str(e)

    # annoying mock to test generally impossible error condition
    from mock import Mock
    lookup = Mock(spec=xylemLookup)
    lookup.resolve_all.return_value = ([('bad-key', ['stuff'])], [])

    installer = xylemInstaller(context, lookup)
    try:
        installer.get_uninstalled(['roscpp_fake'])
        assert False, "should have raised"
    except xylemInternalError:
        pass
Ejemplo n.º 7
0
def test_xylemInstaller_get_uninstalled():
    from xylem import create_default_installer_context
    from xylem.lookup import xylemLookup
    from xylem.installers import xylemInstaller
    from xylem.platforms.debian import APT_INSTALLER

    from xylem.lookup import xylemLookup
    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 = xylemLookup.create_from_rospkg(rospack=rospack,
                                            rosstack=rosstack,
                                            sources_loader=sources_loader)
    context = create_default_installer_context()
    context.set_os_override('ubuntu', 'lucid')
    installer = xylemInstaller(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
Ejemplo n.º 8
0
def test_xylemInstaller_get_uninstalled():
    from xylem import create_default_installer_context
    from xylem.lookup import xylemLookup
    from xylem.installers import xylemInstaller
    from xylem.platforms.debian import APT_INSTALLER
    
    from xylem.lookup import xylemLookup
    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 = xylemLookup.create_from_rospkg(rospack=rospack, rosstack=rosstack, sources_loader=sources_loader)
    context = create_default_installer_context()
    context.set_os_override('ubuntu', 'lucid')
    installer = xylemInstaller(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