def test_root_node_serialization(): n1 = RootNode(tree_conf) n1.insert_entry(Reference(tree_conf, 43, 2, 3)) n1.insert_entry(Reference(tree_conf, 42, 1, 2)) assert n1.entries == [Reference(tree_conf, 42, 1, 2), Reference(tree_conf, 43, 2, 3)] data = n1.dump() n2 = RootNode(tree_conf, data=data) assert n1.entries == n2.entries assert n1.next_page is n2.next_page is None
def test_root_node_serialization(): n1 = RootNode(tree_conf) n1.insert_entry(Reference(tree_conf, 43, 2, 3)) n1.insert_entry(Reference(tree_conf, 42, 1, 2)) assert n1.entries == [ Reference(tree_conf, 42, 1, 2), Reference(tree_conf, 43, 2, 3) ] data = n1.dump() n2 = RootNode(tree_conf, data=data) assert n1.entries == n2.entries assert n1.next_page is n2.next_page is None
def test_smallest_biggest(): node = RootNode(tree_conf) with pytest.raises(IndexError): node.pop_smallest() r42, r43 = Reference(tree_conf, 42, 1, 2), Reference(tree_conf, 43, 2, 3) node.insert_entry(r43) node.insert_entry(r42) # Smallest assert node.smallest_entry == r42 assert node.smallest_key == 42 # Biggest assert node.biggest_entry == r43 assert node.biggest_key == 43 assert node.pop_smallest() == r42 assert node.entries == [r43]
def test_insert_find_get_remove_entries(): node = RootNode(tree_conf) # Test empty _find_entry_index, get and remove with pytest.raises(ValueError): node._find_entry_index(42) with pytest.raises(ValueError): node.get_entry(42) with pytest.raises(ValueError): node.remove_entry(42) # Test insert_entry r42, r43 = Reference(tree_conf, 42, 1, 2), Reference(tree_conf, 43, 2, 3) node.insert_entry_at_the_end(r43) node.insert_entry(r42) assert sorted(node.entries) == node.entries # Test _find_entry_index assert node._find_entry_index(42) == 0 assert node._find_entry_index(43) == 1 # Test _get_entry assert node.get_entry(42) == r42 assert node.get_entry(43) == r43 node.remove_entry(43) assert node.entries == [r42] node.remove_entry(42) assert node.entries == []
def test_node_slots(): n1 = RootNode(tree_conf) with pytest.raises(AttributeError): n1.foo = True