Пример #1
0
def test_clear_failures_success(install_mockery):
    """Test the clear_failures happy path."""

    # Set up a test prefix failure lock
    lock = lk.Lock(spack.store.db.prefix_fail_path,
                   start=1,
                   length=1,
                   default_timeout=1e-9,
                   desc='test')
    try:
        lock.acquire_write()
    except lk.LockTimeoutError:
        tty.warn('Failed to write lock the test install failure')
    spack.store.db._prefix_failures['test'] = lock

    # Set up a fake failure mark (or file)
    fs.touch(os.path.join(spack.store.db._failure_dir, 'test'))

    # Now clear failure tracking
    inst.clear_failures()

    # Ensure there are no cached failure locks or failure marks
    assert len(spack.store.db._prefix_failures) == 0
    assert len(os.listdir(spack.store.db._failure_dir)) == 0

    # Ensure the core directory and failure lock file still exist
    assert os.path.isdir(spack.store.db._failure_dir)
    assert os.path.isfile(spack.store.db.prefix_fail_path)
Пример #2
0
def test_clear_failures_errs(install_mockery, monkeypatch, capsys):
    """Test the clear_failures exception paths."""
    orig_fn = os.remove
    err_msg = 'Mock os remove'

    def _raise_except(path):
        raise OSError(err_msg)

    # Set up a fake failure mark (or file)
    fs.touch(os.path.join(spack.store.db._failure_dir, 'test'))

    monkeypatch.setattr(os, 'remove', _raise_except)

    # Clear failure tracking
    inst.clear_failures()

    # Ensure expected warning generated
    out = str(capsys.readouterr()[1])
    assert 'Unable to remove failure' in out
    assert err_msg in out

    # Restore remove for teardown
    monkeypatch.setattr(os, 'remove', orig_fn)