def test_file_memory_node(): mem = FileMemory(filename, tree_conf) with pytest.raises(ReachedEndOfFile): mem.get_node(3) mem.set_node(node) assert node == mem.get_node(3) mem.close()
def test_file_memory_write_transaction_error(): mem = FileMemory(filename, tree_conf) mem._lock = mock.Mock() mem._cache[424242] = node with pytest.raises(ValueError): with mem.write_transaction: mem.set_node(node) assert mem._wal._not_committed_pages == {3: 9} assert mem._wal._committed_pages == {} assert mem._lock.writer_lock.acquire.call_count == 1 raise ValueError('Foo') assert mem._wal._not_committed_pages == {} assert mem._wal._committed_pages == {} assert mem._lock.writer_lock.release.call_count == 1 assert mem._cache.get(424242) is None
def test_file_memory_write_transaction(): mem = FileMemory(filename, tree_conf) mem._lock = mock.Mock() assert mem._wal._not_committed_pages == {} assert mem._wal._committed_pages == {} with mem.write_transaction: mem.set_node(node) assert mem._wal._not_committed_pages == {3: 9} assert mem._wal._committed_pages == {} assert mem._lock.writer_lock.acquire.call_count == 1 assert mem._wal._not_committed_pages == {} assert mem._wal._committed_pages == {3: 9} assert mem._lock.writer_lock.release.call_count == 1 assert mem._lock.reader_lock.acquire.call_count == 0 with mem.read_transaction: assert mem._lock.reader_lock.acquire.call_count == 1 assert node == mem.get_node(3) assert mem._lock.reader_lock.release.call_count == 1 mem.close()
def test_file_memory_freelist(): mem = FileMemory(filename, tree_conf) assert mem.next_available_page == 1 assert mem._traverse_free_list() == (None, None) mem.del_page(1) assert mem._traverse_free_list() == ( None, FreelistNode(tree_conf, page=1, next_page=None) ) assert mem.next_available_page == 1 assert mem._traverse_free_list() == (None, None) mem.del_page(1) mem.del_page(2) assert mem._traverse_free_list() == ( FreelistNode(tree_conf, page=1, next_page=2), FreelistNode(tree_conf, page=2, next_page=None) ) mem.del_page(3) assert mem._traverse_free_list() == ( FreelistNode(tree_conf, page=2, next_page=3), FreelistNode(tree_conf, page=3, next_page=None) ) assert mem._pop_from_freelist() == 3 assert mem._pop_from_freelist() == 2 assert mem._pop_from_freelist() == 1 assert mem._pop_from_freelist() is None
def test_file_memory_next_available_page(): mem = FileMemory(filename, tree_conf) for i in range(1, 100): assert mem.next_available_page == i
def test_file_memory_metadata(): mem = FileMemory(filename, tree_conf) with pytest.raises(ValueError): mem.get_metadata() mem.set_metadata(6, tree_conf) assert mem.get_metadata() == (6, tree_conf)
def test_file_memory_repr(): mem = FileMemory(filename, tree_conf) assert repr(mem) == '<FileMemory: {}>'.format(filename) mem.close()