Exemplo n.º 1
0
def test_delete_artifact(art_repo: ArtifactRepository, model: Model):
    art_repo.push_artifact(model, {})
    art_repo.get_artifact(model)
    art_repo.delete_artifact(model)
    with pytest.raises(NoSuchArtifactError):
        art_repo.get_artifact(model)
    art_repo.push_artifact(model, {})
Exemplo n.º 2
0
def test_get_artifact(art_repo: ArtifactRepository, model: Model,
                      blobs: Dict[str, InMemoryBlob]):
    artifact: ArtifactCollection = art_repo.push_artifact(model, blobs)

    new_artifact = art_repo.get_artifact(model)

    assert new_artifact == artifact
Exemplo n.º 3
0
def test_push_artifact(art_repo: ArtifactRepository, model: Model, blobs: Dict[str, InMemoryBlob], tmpdir):
    artifact: ArtifactCollection = art_repo.push_artifact(model, blobs)

    assert artifact is not None
    with artifact.blob_dict() as bd:
        assert len(bd) == len(blobs)

    assert artifact.bytes_dict() == {n: b.payload for n, b in blobs.items()}

    artifact.materialize(tmpdir)
    assert set(os.listdir(tmpdir)) == set(list(blobs.keys()))

    for name, blob in blobs.items():
        with open(os.path.join(tmpdir, name), 'rb') as f:
            payload = f.read()
        assert payload == blob.payload

        with blob.bytestream() as p:
            assert p.read() == blob.payload
Exemplo n.º 4
0
def test_materialize_blobs_long_path(art_repo: ArtifactRepository, model: Model, blobs: Dict[str, InMemoryBlob], tmp_path):
    artifact: ArtifactCollection = art_repo.push_artifact(model, blobs)

    assert artifact is not None
    with artifact.blob_dict() as bd:
        assert len(bd) == len(blobs)

    if os.path.isdir(tmp_path):
        os.rmdir(tmp_path)

    tmp_path.mkdir()
    long_path = tmp_path / 'sub'
    with artifact.blob_dict() as bd:
        for name, blob in bd.items():
            blob_path = str(long_path / name)
            blob.materialize(blob_path)
            with open(blob_path, 'rb') as f:
                payload = f.read()
            with blob.bytestream() as blob_payload:
                assert payload == blob_payload.read()
Exemplo n.º 5
0
def test_delete_non_existing_artifact(art_repo: ArtifactRepository,
                                      model: Model):
    with pytest.raises(NoSuchArtifactError):
        art_repo.delete_artifact(model)
Exemplo n.º 6
0
def test_delete_artifact__non_saved_model(art_repo: ArtifactRepository,
                                          model: Model):
    model._id = None

    with pytest.raises(ValueError):
        art_repo.delete_artifact(model)
Exemplo n.º 7
0
def test_push_duplicate_artifact(art_repo: ArtifactRepository, model: Model):
    art_repo.push_artifact(model, {})
    with pytest.raises(ArtifactExistsError):
        art_repo.push_artifact(model, {})
Exemplo n.º 8
0
def test_push_non_existing_artifact(art_repo: ArtifactRepository,
                                    model: Model):
    with pytest.raises(NoSuchArtifactError):
        art_repo.get_model_artifact(model)