Example #1
0
def test_package_id(install_mockery):
    """Test to cover package_id functionality."""
    pkg = spack.repo.get('trivial-install-test-package')
    with pytest.raises(ValueError, matches='spec is not concretized'):
        inst.package_id(pkg)

    spec = spack.spec.Spec('trivial-install-test-package')
    spec.concretize()
    assert spec.concrete
    pkg = spec.package
    assert pkg.name in inst.package_id(pkg)
Example #2
0
def test_ensure_locked_have(install_mockery, tmpdir, capsys):
    """Test _ensure_locked when already have lock."""
    const_arg = installer_args(['trivial-install-test-package'], {})
    installer = create_installer(const_arg)
    spec = installer.build_requests[0].pkg.spec
    pkg_id = inst.package_id(spec.package)

    with tmpdir.as_cwd():
        # Test "downgrade" of a read lock (to a read lock)
        lock = lk.Lock('./test', default_timeout=1e-9, desc='test')
        lock_type = 'read'
        tpl = (lock_type, lock)
        installer.locks[pkg_id] = tpl
        assert installer._ensure_locked(lock_type, spec.package) == tpl

        # Test "upgrade" of a read lock without read count to a write
        lock_type = 'write'
        err = 'Cannot upgrade lock'
        with pytest.raises(ulk.LockUpgradeError, match=err):
            installer._ensure_locked(lock_type, spec.package)

        out = str(capsys.readouterr()[1])
        assert 'Failed to upgrade to a write lock' in out
        assert 'exception when releasing read lock' in out

        # Test "upgrade" of the read lock *with* read count to a write
        lock._reads = 1
        tpl = (lock_type, lock)
        assert installer._ensure_locked(lock_type, spec.package) == tpl

        # Test "downgrade" of the write lock to a read lock
        lock_type = 'read'
        tpl = (lock_type, lock)
        assert installer._ensure_locked(lock_type, spec.package) == tpl
Example #3
0
def test_install_lock_installed_requeue(install_mockery, monkeypatch, capfd):
    """Cover basic install handling for installed package."""
    const_arg = installer_args(['b'], {})
    b, _ = const_arg[0]
    installer = create_installer(const_arg)
    b_pkg_id = inst.package_id(b.package)

    def _prep(installer, task):
        installer.installed.add(b_pkg_id)
        tty.msg('{0} is installed'.format(b_pkg_id))

        # also do not allow the package to be locked again
        monkeypatch.setattr(inst.PackageInstaller, '_ensure_locked',
                            _not_locked)

    def _requeued(installer, task):
        tty.msg('requeued {0}'.format(inst.package_id(task.pkg)))

    # Flag the package as installed
    monkeypatch.setattr(inst.PackageInstaller, '_prepare_for_install', _prep)

    # Ensure don't continually requeue the task
    monkeypatch.setattr(inst.PackageInstaller, '_requeue_task', _requeued)

    installer.install()
    assert b_pkg_id not in installer.installed

    out = capfd.readouterr()[0]
    expected = ['is installed', 'read locked', 'requeued']
    for exp, ln in zip(expected, out.split('\n')):
        assert exp in ln
Example #4
0
def test_install_skip_patch(install_mockery, mock_fetch):
    """Test the path skip_patch install path."""
    spec_name = 'b'
    const_arg = installer_args([spec_name],
                               {'fake': False, 'skip_patch': True})
    installer = create_installer(const_arg)

    installer.install()

    spec, install_args = const_arg[0]
    assert inst.package_id(spec.package) in installer.installed
Example #5
0
def test_get_dependent_ids(install_mockery, mock_packages):
    # Concretize the parent package, which handle dependency too
    spec = spack.spec.Spec('a')
    spec.concretize()
    assert spec.concrete

    pkg_id = inst.package_id(spec.package)

    # Grab the sole dependency of 'a', which is 'b'
    dep = spec.dependencies()[0]

    # Ensure the parent package is a dependent of the dependency package
    assert pkg_id in inst.get_dependent_ids(dep)
Example #6
0
def test_install_dir_exists(install_mockery, monkeypatch):
    """Cover capture of install directory exists error."""
    def _install(installer, task):
        raise dl.InstallDirectoryAlreadyExistsError(task.pkg.prefix)

    # Ensure raise the desired exception
    monkeypatch.setattr(inst.PackageInstaller, '_install_task', _install)

    const_arg = installer_args(['b'], {})
    installer = create_installer(const_arg)

    err = 'already exists'
    with pytest.raises(dl.InstallDirectoryAlreadyExistsError, match=err):
        installer.install()

    b, _ = const_arg[0]
    assert inst.package_id(b.package) in installer.installed
Example #7
0
def test_install_dir_exists_multi(install_mockery, monkeypatch, capfd):
    """Cover capture of install directory exists error for multiple specs."""
    def _install(installer, task):
        raise dl.InstallDirectoryAlreadyExistsError(task.pkg.prefix)

    # Skip the actual installation though should never reach it
    monkeypatch.setattr(inst.PackageInstaller, '_install_task', _install)

    # Use two packages to ensure multiple specs
    const_arg = installer_args(['b', 'c'], {})
    installer = create_installer(const_arg)

    with pytest.raises(inst.InstallError, match='Installation request failed'):
        installer.install()

    err = capfd.readouterr()[1]
    assert 'already exists' in err
    for spec, install_args in const_arg:
        pkg_id = inst.package_id(spec.package)
        assert pkg_id in installer.installed
Example #8
0
def test_install_fail_fast_on_detect(install_mockery, monkeypatch, capsys):
    """Test fail_fast install when an install failure is detected."""
    const_arg = installer_args(['b'], {'fail_fast': False})
    const_arg.extend(installer_args(['c'], {'fail_fast': True}))
    installer = create_installer(const_arg)
    pkg_ids = [inst.package_id(spec.package) for spec, _ in const_arg]

    # Make sure all packages are identified as failed
    #
    # This will prevent b from installing, which will cause the build of a
    # to be skipped.
    monkeypatch.setattr(spack.database.Database, 'prefix_failed', _true)

    with pytest.raises(inst.InstallError, match='after first install failure'):
        installer.install()

    assert pkg_ids[0] in installer.failed, 'Expected b to be marked as failed'
    assert pkg_ids[1] not in installer.failed, \
        'Expected no attempt to install c'

    out = capsys.readouterr()[1]
    assert '{0} failed to install'.format(pkg_ids[0]) in out
Example #9
0
def test_package_id_ok(install_mockery):
    spec = spack.spec.Spec('trivial-install-test-package')
    spec.concretize()
    assert spec.concrete
    pkg = spec.package
    assert pkg.name in inst.package_id(pkg)
Example #10
0
def test_package_id_err(install_mockery):
    pkg = spack.repo.get('trivial-install-test-package')
    with pytest.raises(ValueError, match='spec is not concretized'):
        inst.package_id(pkg)
Example #11
0
 def _requeued(installer, task):
     tty.msg('requeued {0}'.format(inst.package_id(task.pkg)))
Example #12
0
def test_package_id_err(install_mockery):
    s = spack.spec.Spec('trivial-install-test-package')
    pkg_cls = spack.repo.path.get_pkg_class(s.name)
    with pytest.raises(ValueError, match='spec is not concretized'):
        inst.package_id(pkg_cls(s))