Example #1
0
def test_read_write_same_file(tmpdir):
    repo = FileSystemRepository(str(tmpdir))
    repo.write(['key'], itertools.repeat(b'first revision\n', 1024))
    first_iterator = iter(repo.read(['key']))
    second_iterator = iter(repo.read(['key']))
    assert first_iterator is not second_iterator
    first_stop = False
    second_stop = False
    first_list = []
    second_list = []
    while not (first_stop or second_stop):
        if not first_stop:
            try:
                first_chunk = next(first_iterator)
            except StopIteration:
                first_stop = True
            else:
                if not first_list:
                    repo.write(['key'], [b'second ', b'revision'])
                    third_iterator = repo.read(['key'])
                first_list.append(first_chunk)
        if not second_stop:
            try:
                second_chunk = next(second_iterator)
            except StopIteration:
                second_stop = True
            else:
                second_list.append(second_chunk)
    assert (b''.join(first_list) ==
            b''.join(second_list) ==
            b''.join(itertools.repeat(b'first revision\n', 1024)))
    assert b''.join(third_iterator) == b'second revision'
Example #2
0
def test_atomicity(tmpdir):
    repo = FileSystemRepository(str(tmpdir), atomic=True)
    repo.write(['key'], [b'first ', b'revision'])

    def gen():
        assert b''.join(repo.read(['key'])) == b'first revision'
        yield b'second '
        assert b''.join(repo.read(['key'])) == b'first revision'
        yield b'revision'
        assert b''.join(repo.read(['key'])) == b'first revision'
    repo.write(['key'], gen())
    assert b''.join(repo.read(['key'])) == b'second revision'
Example #3
0
def test_atomicity(tmpdir):
    repo = FileSystemRepository(str(tmpdir), atomic=True)
    repo.write(['key'], [b'first ', b'revision'])

    def gen():
        assert b''.join(repo.read(['key'])) == b'first revision'
        yield b'second '
        assert b''.join(repo.read(['key'])) == b'first revision'
        yield b'revision'
        assert b''.join(repo.read(['key'])) == b'first revision'
    repo.write(['key'], gen())
    assert b''.join(repo.read(['key'])) == b'second revision'
Example #4
0
def test_file_write(tmpdir):
    f = FileSystemRepository(str(tmpdir))
    f.write(['key'], [b'file ', b'content'])
    assert tmpdir.join('key').read() == 'file content'
    f.write(['dir', 'dir2', 'key'], [b'deep ', b'file ', b'content'])
    assert tmpdir.join('dir', 'dir2', 'key').read() == 'deep file content'
    with raises(RepositoryKeyError):
        f.write([], [b'file ', b'content'])
Example #5
0
def test_file_write(tmpdir):
    f = FileSystemRepository(str(tmpdir))
    f.write(['key'], [b'file ', b'content'])
    assert tmpdir.join('key').read() == 'file content'
    f.write(['dir', 'dir2', 'key'], [b'deep ', b'file ', b'content'])
    assert tmpdir.join('dir', 'dir2', 'key').read() == 'deep file content'
    with raises(RepositoryKeyError):
        f.write([], [b'file ', b'content'])