Example #1
0
def test_110_no_write_with_exception_on_install(database):
    def fail_while_writing():
        with database.write_transaction():
            _mock_install('cmake')
            raise Exception()

    with database.read_transaction():
        assert database.query('cmake', installed=any) == []

    with pytest.raises(Exception):
        fail_while_writing()

    # reload DB and make sure cmake was not written.
    with database.read_transaction():
        assert database.query('cmake', installed=any) == []
Example #2
0
def test_100_no_write_with_exception_on_remove(database):
    def fail_while_writing():
        with database.write_transaction():
            _mock_remove('mpileaks ^zmpi')
            raise Exception()

    with database.read_transaction():
        assert len(database.query('mpileaks ^zmpi', installed=any)) == 1

    with pytest.raises(Exception):
        fail_while_writing()

    # reload DB and make sure zmpi is still there.
    with database.read_transaction():
        assert len(database.query('mpileaks ^zmpi', installed=any)) == 1
Example #3
0
def test_080_root_ref_counts(database):
    rec = database.get_record('mpileaks ^mpich')

    # Remove a top-level spec from the DB
    database.remove('mpileaks ^mpich')

    # record no longer in DB
    assert database.query('mpileaks ^mpich', installed=any) == []

    # record's deps have updated ref_counts
    assert database.get_record('callpath ^mpich').ref_count == 0
    assert database.get_record('mpich').ref_count == 1

    # Put the spec back
    database.add(rec.spec, spack.store.layout)

    # record is present again
    assert len(database.query('mpileaks ^mpich', installed=any)) == 1

    # dependencies have ref counts updated
    assert database.get_record('callpath ^mpich').ref_count == 1
    assert database.get_record('mpich').ref_count == 2
Example #4
0
def test_query_installed_when_package_unknown(database):
    """Test that we can query the installation status of a spec
    when we don't know its package.py
    """
    with spack.repo.use_repositories(MockPackageMultiRepo()):
        specs = database.query('mpileaks')
        for s in specs:
            # Assert that we can query the installation methods even though we
            # don't have the package.py available
            assert s.installed
            assert not s.installed_upstream
            with pytest.raises(spack.repo.UnknownNamespaceError):
                s.package
Example #5
0
def _check_db_sanity(database):
    """Utility function to check db against install layout."""
    pkg_in_layout = sorted(spack.store.layout.all_specs())
    actual = sorted(database.query())

    externals = sorted([x for x in actual if x.external])
    nexpected = len(pkg_in_layout) + len(externals)

    assert nexpected == len(actual)

    non_external_in_db = sorted([x for x in actual if not x.external])

    for e, a in zip(pkg_in_layout, non_external_in_db):
        assert e == a

    _check_merkleiness()
Example #6
0
def test_050_basic_query(database):
    """Ensure querying database is consistent with what is installed."""
    # query everything
    total_specs = len(spack.store.db.query())
    assert total_specs == 17

    # query specs with multiple configurations
    mpileaks_specs = database.query('mpileaks')
    callpath_specs = database.query('callpath')
    mpi_specs = database.query('mpi')

    assert len(mpileaks_specs) == 3
    assert len(callpath_specs) == 3
    assert len(mpi_specs) == 3

    # query specs with single configurations
    dyninst_specs = database.query('dyninst')
    libdwarf_specs = database.query('libdwarf')
    libelf_specs = database.query('libelf')

    assert len(dyninst_specs) == 1
    assert len(libdwarf_specs) == 1
    assert len(libelf_specs) == 1

    # Query by dependency
    assert len(database.query('mpileaks ^mpich')) == 1
    assert len(database.query('mpileaks ^mpich2')) == 1
    assert len(database.query('mpileaks ^zmpi')) == 1

    # Query by date
    assert len(database.query(start_date=datetime.datetime.min)) == total_specs
    assert len(database.query(start_date=datetime.datetime.max)) == 0
    assert len(database.query(end_date=datetime.datetime.min)) == 0
    assert len(database.query(end_date=datetime.datetime.max)) == total_specs