Ejemplo n.º 1
0
def test_no_duplicate(tmpdir, sample_run):
    obs = FileStorageObserver(tmpdir, copy_artifacts=False)
    file = Path(str(tmpdir / "koko.txt"))
    file.touch()
    obs.started_event(**sample_run)
    obs.resource_event(str(file))
    assert not os.path.exists(tmpdir / "_resources")

    # Test the test: that the resource would otherwise have been created.
    obs = FileStorageObserver(tmpdir, copy_artifacts=True)
    sample_run["_id"] = sample_run["_id"] + "_2"
    obs.started_event(**sample_run)
    obs.resource_event(str(file))
    assert os.path.exists(tmpdir / "_resources")
    assert any(x.startswith("koko") for x in os.listdir(tmpdir / "_resources"))
Ejemplo n.º 2
0
def test_fs_observer_resource_event_does_not_duplicate(dir_obs, sample_run, tmpfile):
    basedir, obs = dir_obs
    obs2 = FileStorageObserver(obs.basedir)
    obs.started_event(**sample_run)

    obs.resource_event(tmpfile.name)
    # let's have another run from a different observer
    sample_run["_id"] = None
    _id = obs2.started_event(**sample_run)
    run_dir = basedir.join(str(_id))
    obs2.resource_event(tmpfile.name)

    res_dir = basedir.join("_resources")
    assert res_dir.exists()
    assert len(res_dir.listdir()) == 1
    assert res_dir.listdir()[0].read() == tmpfile.content

    run = json.loads(run_dir.join("run.json").read())
    assert len(run["resources"]) == 1
    assert run["resources"][0] == [tmpfile.name, res_dir.listdir()[0].strpath]