Example #1
0
import pytest

from bptree.entry import Record, Reference, OpaqueData, NOT_LOADED
from bptree.const import TreeConf
from bptree.serializer import IntSerializer, StrSerializer

tree_conf = TreeConf(4096, 4, 16, 16, IntSerializer())


def test_record_int_serialization():
    r1 = Record(tree_conf, 42, b'foo')
    data = r1.dump()

    r2 = Record(tree_conf, data=data)
    assert r1 == r2
    assert r1.value == r2.value
    assert r1.overflow_page == r2.overflow_page


def test_record_str_serialization():
    tree_conf = TreeConf(4096, 4, 40, 40, StrSerializer())
    r1 = Record(tree_conf, '0', b'0')
    data = r1.dump()

    r2 = Record(tree_conf, data=data)
    assert r1 == r2
    assert r1.value == r2.value
    assert r1.overflow_page == r2.overflow_page


def test_record_int_serialization_overflow_value():
Example #2
0
def test_serializer_slots():
    s = IntSerializer()
    with pytest.raises(AttributeError):
        s.foo = True
Example #3
0
def test_get_node_from_page_data():
    data = (2).to_bytes(1, ENDIAN) + bytes(4096 - 1)
    tree_conf = TreeConf(4096, 7, 16, 16, IntSerializer())
    assert isinstance(Node.from_page_data(tree_conf, data, 4), RootNode)
Example #4
0
def test_int_serializer():
    s = IntSerializer()
    assert s.serialize(42, 2) == b'*\x00'
    assert s.deserialize(b'*\x00') == 42
    assert repr(s) == 'IntSerializer()'
Example #5
0
def test_node_limit_children(klass, order, min_children, max_children):
    node = klass(TreeConf(4096, order, 16, 16, IntSerializer()))
    assert node.min_children == min_children
    assert node.max_children == max_children