示例#1
0
def test_create_and_load_file():
    b = BPlusTree(filename)
    assert isinstance(b._mem, FileMemory)
    b.insert(5, b'foo')
    b.close()

    b = BPlusTree(filename)
    assert isinstance(b._mem, FileMemory)
    assert b.get(5) == b'foo'
    b.close()
示例#2
0
def test_iter_slice(b):
    with pytest.raises(ValueError):
        next(b._iter_slice(slice(None, None, -1)))

    with pytest.raises(ValueError):
        next(b._iter_slice(slice(10, 0, None)))

    # Contains from 0 to 9 included
    for i in range(10):
        b.insert(i, str(i).encode())

    iter = b._iter_slice(slice(None, 2))
    assert next(iter).key == 0
    assert next(iter).key == 1
    with pytest.raises(StopIteration):
        next(iter)

    iter = b._iter_slice(slice(5, 7))
    assert next(iter).key == 5
    assert next(iter).key == 6
    with pytest.raises(StopIteration):
        next(iter)

    iter = b._iter_slice(slice(8, 9))
    assert next(iter).key == 8
    with pytest.raises(StopIteration):
        next(iter)

    iter = b._iter_slice(slice(9, 12))
    assert next(iter).key == 9
    with pytest.raises(StopIteration):
        next(iter)

    iter = b._iter_slice(slice(15, 17))
    with pytest.raises(StopIteration):
        next(iter)

    iter = b._iter_slice(slice(-2, 17))
    assert next(iter).key == 0

    # Contains from 10, 20, 30 .. 200
    b2 = BPlusTree(order=5)
    for i in range(10, 201, 10):
        b.insert(i, str(i).encode())

    iter = b._iter_slice(slice(65, 85))
    assert next(iter).key == 70
    assert next(iter).key == 80
    with pytest.raises(StopIteration):
        next(iter)

    b2.close()
示例#3
0
def test_insert_split_in_tree(iterator, order, page_size, k_size, v_size,
                              serialize_class, cache_size):

    inserted = list()
    for i in iterator:
        v = str(i).encode()
        k = i
        if serialize_class is StrSerializer:
            k = str(i)
        inserted.append((k, v))

    b = BPlusTree(filename,
                  order=order,
                  page_size=page_size,
                  key_size=k_size,
                  value_size=v_size,
                  cache_size=cache_size,
                  serializer=serialize_class())

    if sorted(inserted) == inserted:
        b.batch_insert(inserted)
    else:
        for k, v in inserted:
            b.insert(k, v)

    # Reload tree from file before checking values
    b.close()
    b = BPlusTree(filename,
                  order=order,
                  page_size=page_size,
                  key_size=k_size,
                  value_size=v_size,
                  cache_size=cache_size,
                  serializer=serialize_class())

    for k, v in inserted:
        assert b.get(k) == v

    b.close()
示例#4
0
def b():
    b = BPlusTree()
    yield b
    b.close()
示例#5
0
def b():
    b = BPlusTree(filename, key_size=16, value_size=16, order=4)
    yield b
    b.close()