示例#1
0
# -*- coding: utf-8 -*-

import pytest

from gbplustree.entry import Record, Reference
from gbplustree.const import TreeConf
from gbplustree.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
示例#2
0
def test_get_node_from_page_data():
    data = int(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)
示例#3
0
def test_serializer_slots():
    s = IntSerializer()
    with pytest.raises(AttributeError):
        s.foo = True
示例#4
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
示例#5
0
def test_int_serializer():
    s = IntSerializer()
    assert s.serialize(42, 2) == b'*\x00'
    assert s.deserialize(b'*\x00') == 42
    assert repr(s) == 'IntSerializer()'