Exemplo n.º 1
0
def test_prune_missing_experiment(session_db):
    session, db = session_db
    database.build_index("test/data/indexing/broken_file", session)

    assert db.check()

    # check that we have one file
    q = session.query(database.NCFile)
    r = q.all()
    assert len(r) == 1

    # prune experiment
    experiment = "incorrect_experiment"
    with pytest.raises(RuntimeError,
                       match="No such experiment: ".format(experiment)):
        database.prune_experiment(experiment, session)
Exemplo n.º 2
0
def test_prune_broken(session_db):
    session, db = session_db
    database.build_index("test/data/indexing/broken_file", session)

    assert db.check()

    # check that we have one file
    q = session.query(database.NCFile)
    r = q.all()
    assert len(r) == 1

    # prune experiment
    database.prune_experiment("broken_file", session)

    # now the database should be empty
    q = session.query(database.NCFile)
    r = q.all()
    assert len(r) == 0
Exemplo n.º 3
0
def test_prune_delete(session_db, tmpdir):
    session, db = session_db
    expt_dir = tmpdir / "expt"
    expt_dir.mkdir()

    # copy the file to a new experiment directory and index
    shutil.copy("test/data/indexing/longnames/output000/test1.nc",
                str(expt_dir / "test1.nc"))
    database.build_index(str(expt_dir), session)

    # check that we have a valid file
    q = session.query(database.NCFile).filter(database.NCFile.present)
    r = q.all()
    assert len(r) == 1

    # remove the file and prune
    os.remove(expt_dir / "test1.nc")
    database.prune_experiment("expt", session)

    # now we should still have no files
    q = session.query(database.NCFile)
    r = q.one_or_none()
    assert r is None
Exemplo n.º 4
0
def test_prune_nodelete(session_db, tmpdir):
    session, db = session_db
    expt_dir = tmpdir / 'expt'
    expt_dir.mkdir()

    # copy the file to a new experiment directory and index
    shutil.copy('test/data/indexing/longnames/output000/test1.nc',
                str(expt_dir / 'test1.nc'))
    database.build_index(str(expt_dir), session)

    # check that we have a valid file
    q = session.query(database.NCFile).filter(database.NCFile.present)
    r = q.all()
    assert (len(r) == 1)

    # remove the file and prune
    os.remove(expt_dir / 'test1.nc')
    database.prune_experiment('expt', session, delete=False)

    # now we should still have one file, but now not present
    q = session.query(database.NCFile)
    r = q.one_or_none()
    assert (r is not None)
    assert (not r.present)