Ejemplo n.º 1
0
def test_lazy_proxy_dict_prevents_creation_with_artifacts_of_same_name(repo):
    foo = repo.put(artifact_record(name='foo', value=42))
    foo2 = repo.put(artifact_record(name='foo', value=100))

    msg = """Only artifacts with distinct names can be used in a lazy_proxy_dict.
Offending names: {'foo': 2}
Use the option `group_artifacts_of_same_name=True` if you want a list of proxies to be returned under the respective key.
"""
    with pytest.raises(ValueError) as excinfo:
        p.lazy_proxy_dict([foo, foo2])

    assert msg in str(excinfo.value)
Ejemplo n.º 2
0
def test_removing_artifact_from_set():
    a = artifact_record(id='foo')
    b = artifact_record(id='blah')
    artifact_set = r.ArtifactSet([a.id, b.id], labels='myset')
    updated_set = artifact_set.remove(b)

    assert b not in updated_set
    assert updated_set.name is None

    updated_named_set = artifact_set.remove(b, labels='myset')
    assert b not in updated_named_set
    assert updated_named_set.name == 'myset'
Ejemplo n.º 3
0
def test_set_renaming(repo):
    a = artifact_record(id='foo')
    b = artifact_record(id='blah')
    repo.put(a)
    repo.put(b)
    named_set = r.create_set([a, b], 'foobar')

    assert repo.get_set_by_labels('foobar') == named_set
    renamed_set = r.label_set(named_set, 'baz')

    # we don't delete the old one
    assert repo.get_set_by_labels('foobar') == named_set
    assert repo.get_set_by_labels('baz') == renamed_set
Ejemplo n.º 4
0
def test_basic_repo_ops(repo):
    artifact = artifact_record()

    assert artifact.id not in repo
    repo.put(artifact)

    assert artifact.id in repo
    assert artifact in repo

    with pytest.raises(cs.KeyExistsError) as e:
        repo.put(artifact)

    assert repo.get_by_id(artifact.id).id == artifact.id
    assert repo[artifact.id].id == artifact.id
    assert repo.get_by_value_id(artifact.value_id).id == artifact.id

    repo.delete(artifact.id)
    assert artifact.id not in repo
    if hasattr(repo, 'blobstore'):
        assert artifact.id not in repo.blobstore
        assert artifact.value_id not in repo.blobstore

    with pytest.raises(KeyError) as e:
        repo.delete(artifact.id)

    with pytest.raises(KeyError) as e:
        repo.get_by_id(artifact.id)

    with pytest.raises(KeyError) as e:
        repo.get_by_value_id(artifact.id)
Ejemplo n.º 5
0
def test_chained_read_through_write():
    foo = artifact_record(id='foo')
    read_repo = r.MemoryRepo([foo], read=True, write=False)
    repo_ahead = r.MemoryRepo(read=True, write=True, read_through_write=True)
    read_through_write_repo = r.MemoryRepo(read=True,
                                           write=True,
                                           read_through_write=True)
    no_read_through_write_repo = r.MemoryRepo(read=True,
                                              write=True,
                                              read_through_write=False)
    repos = [
        no_read_through_write_repo, read_through_write_repo, read_repo,
        repo_ahead
    ]
    chained_repo = r.ChainedRepo(repos)

    assert 'foo' not in read_through_write_repo
    assert 'foo' not in no_read_through_write_repo
    assert 'foo' not in repo_ahead
    # verify we read from the read-only store
    assert chained_repo['foo'].id == foo.id

    assert 'foo' in read_through_write_repo
    assert 'foo' not in repo_ahead
    assert 'foo' not in no_read_through_write_repo
Ejemplo n.º 6
0
def test_repo_contains_set(repo):
    assert not repo.contains_set('foo')

    artifact = artifact_record(id='123')
    repo.put(artifact)
    artifact_set = r.ArtifactSet([artifact.id], 'foo')

    repo.put_set(artifact_set)
    assert repo.contains_set(artifact_set.id)
Ejemplo n.º 7
0
def test_set_unions():
    a, b, c, d = [artifact_record(id=item) for item in 'abcd']
    set_one = r.ArtifactSet([a, b], labels='set one')
    set_two = r.ArtifactSet([c, d], labels='set two')
    set_three = set_one.union(set_two, labels='set three')

    assert set_three.name == 'set three'

    assert set_three.artifact_ids == {'a', 'b', 'c', 'd'}
    assert (set_one | set_two).artifact_ids == {'a', 'b', 'c', 'd'}
Ejemplo n.º 8
0
def test_repo_delete_set(repo):
    artifact = artifact_record(id='123')
    repo.put(artifact)
    artifact_set = r.ArtifactSet(['123'], 'foo')
    repo.put_set(artifact_set)

    repo.delete_set(artifact_set.id)

    with pytest.raises(KeyError) as e:
        repo.get_set_by_id(artifact_set.id)
Ejemplo n.º 9
0
def test_repo_set_put_and_finding(repo):
    artifact = artifact_record(id='123')
    repo.put(artifact)
    artifact_set = r.ArtifactSet([artifact.id], 'foo')
    repo.put_set(artifact_set)

    assert repo.get_set_by_id(artifact_set.id) == artifact_set
    found_set = repo.get_set_by_labels('foo')
    assert found_set.name == 'foo'
    assert found_set.artifact_ids == {'123'}
Ejemplo n.º 10
0
def test_chained_writes_may_be_allowed_on_read_throughs_only():
    foo = artifact_record(id='foo')
    read_repo = r.MemoryRepo([foo], read=True, write=False)
    read_through_write_only_repo = r.MemoryRepo(read=True, write=False, read_through_write=True)
    write_repo = r.MemoryRepo(read=True, write=True, read_through_write=False)
    repos = [write_repo, read_through_write_only_repo, read_repo]
    chained_repo = r.ChainedRepo(repos)

    # verify we read from the read-only repo
    assert chained_repo['foo'].id == foo.id

    assert 'foo' in read_through_write_only_repo
    assert 'foo' not in write_repo

    bar = artifact_record(id='bar')
    chained_repo.put(bar)
    assert 'bar' in chained_repo
    assert 'bar' not in read_through_write_only_repo
    assert 'bar' in write_repo
Ejemplo n.º 11
0
def test_chained_with_readonly():
    read_repo = r.MemoryRepo([artifact_record(id='foo')],
                             read=True, write=False, delete=False)
    write_repo = r.MemoryRepo(read=True, write=True, delete=False)
    repos = [read_repo, write_repo]
    chained = r.ChainedRepo(repos)

    # verify we read from the read-only store
    assert 'foo' in chained

    # but that it is not written to
    record = artifact_record(id='bar', value_id='baz')
    chained.put(record)
    assert 'bar' in chained
    assert 'bar' in write_repo
    assert 'bar' not in read_repo
    assert chained.get_by_value_id(record.value_id).id == record.id
    assert chained.get_by_id(record.id).id == record.id
    assert chained.get_value(record) == record.value
Ejemplo n.º 12
0
def test_set_intersections():
    a, b, c, d = [artifact_record(id=item) for item in 'abcd']
    set_one = r.ArtifactSet([a, b, c], labels='set one')
    set_two = r.ArtifactSet([c, d], labels='set two')
    set_three = set_one.intersection(set_two, labels='set three')

    assert set_three.name == 'set three'

    assert set_three.artifact_ids == {'c'}
    # check that the operator works too
    assert (set_one & set_two).artifact_ids == {'c'}
Ejemplo n.º 13
0
def test_set_differences():
    a, b, c, d = [artifact_record(id=item) for item in 'abcd']
    set_one = r.ArtifactSet([a, b, c], labels='set one')
    set_two = r.ArtifactSet([c, d], labels='set two')
    set_three = set_one.difference(set_two, labels='set three')

    assert set_three.name == 'set three'
    assert set_three.labels == {'name': 'set three'}
    expected_set = {'a', 'b', 'c'} - {'c', 'd'}
    assert set_three.artifact_ids == expected_set
    # check that the operator works too
    assert (set_one - set_two).artifact_ids == expected_set
Ejemplo n.º 14
0
def test_permissions(atomic_repo):
    repo = atomic_repo
    artifact = artifact_record()

    repo._write = False
    assert not repo._write

    with pytest.raises(cs.PermissionError) as e:
        repo.put(artifact)
    assert artifact not in repo
    
    repo._write = True
    repo.put(artifact)

    repo._read = False

    with pytest.raises(cs.PermissionError) as e:
        repo.get_by_id(artifact.id)

    with pytest.raises(cs.PermissionError) as e:
        repo.get_by_value_id(artifact.value_id)

    with pytest.raises(cs.PermissionError) as e:
        repo.get_value(artifact.id)

    with pytest.raises(cs.PermissionError) as e:
        repo.get_inputs(artifact)

    with pytest.raises(cs.PermissionError) as e:
        artifact.id in repo


    repo._read = True
    assert repo.get_by_id(artifact.id)
    assert artifact.id in repo

    repo._delete = False
    with pytest.raises(cs.PermissionError) as e:
        repo.delete(artifact.id)


    repo._delete = True
    repo.delete(artifact.id)
    assert artifact.id not in repo