Skip to content

Commit

Permalink
Merge 159fb22 into 910536a
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Nov 9, 2020
2 parents 910536a + 159fb22 commit 0c4c48f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 13 deletions.
1 change: 1 addition & 0 deletions BTrees/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ def _del(self, key):
self._firstbucket = child._next
removed_first_bucket = True
del data[index]
self._p_changed = True

return removed_first_bucket, value

Expand Down
29 changes: 17 additions & 12 deletions BTrees/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,14 @@ class SignedMixin(object):
KEY_RANDRANGE_ARGS = (-2000, 2001)


class Base(SignedMixin):
# Tests common to all types: sets, buckets, and BTrees
class ZODBAccess(object):

db = None

def _getTargetClass(self):
raise NotImplementedError("subclass should return the target type")

def _makeOne(self):
return self._getTargetClass()()

def setUp(self):
super(Base, self).setUp()
_skip_if_pure_py_and_py_test(self)

def tearDown(self):
if self.db is not None:
self.db.close()
del self.db

def _getRoot(self):
from ZODB import DB
Expand All @@ -131,6 +121,21 @@ def _closeRoot(self, root):
transaction.abort()
root._p_jar.close()


class Base(ZODBAccess, SignedMixin):
# Tests common to all types: sets, buckets, and BTrees

def _getTargetClass(self):
raise NotImplementedError("subclass should return the target type")

def _makeOne(self):
return self._getTargetClass()()

def setUp(self):
super(Base, self).setUp()
_skip_if_pure_py_and_py_test(self)


def testPersistentSubclass(self):
# Can we subclass this and Persistent?
# https://github.com/zopefoundation/BTrees/issues/78
Expand Down
47 changes: 47 additions & 0 deletions BTrees/tests/testPersistency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##############################################################################
#
# Copyright (c) 2020 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

from unittest import TestCase

from ..OOBTree import OOBTree, OOBTreePy
from .common import _skip_wo_ZODB, ZODBAccess


BUCKET_SIZE = OOBTreePy.max_leaf_size


class TestPersistency(ZODBAccess, TestCase):
@_skip_wo_ZODB
def test_empty_bucket_persistency(self):
from transaction import commit
root = self._getRoot()
try:
# tree with 3 buckets (internal implementation details)
tree = OOBTree(
dict((i, i) for i in range(3 * BUCKET_SIZE // 2 + 2)))
root["tree"] = tree
commit()
# almost clear the second bucket keeping the last element
for i in range(BUCKET_SIZE // 2, BUCKET_SIZE - 1):
del tree[i]
commit()
del tree[BUCKET_SIZE - 1] # remove the last element
commit()
tree._check()
tree._p_deactivate()
tree._check() # fails in case of bad persistency
finally:
self._closeRoot(root)


3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
4.7.3 (unreleased)
==================

- Fix persistency bug in the Python version
(`#118 <https://github.com/zopefoundation/BTrees/issues/118>`_).

- Fix ``Tree.__setstate__`` to no longer accept children besides
tree or bucket types to prevent crashes. See `PR 143
<https://github.com/zopefoundation/BTrees/pull/143>`_ for details.
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ envlist =
# Jython support pending 2.7 support, due 2012-07-15 or so. See:
# http://fwierzbicki.blogspot.com/2012/03/adconion-to-fund-jython-27.html
# py27,jython,pypy,coverage,docs
py27,py27-pure,py35,py35-pure,py36,py37,py38,pypy,pypy3,w_zodb,coverage,docs
py27,py27-pure,py35,py35-pure,py36,py37,py38,pypy,pypy3,w_zodb,w_zodb-pure,coverage,docs

[testenv]
usedevelop = true
Expand All @@ -29,6 +29,12 @@ basepython =
deps =
ZODB

[testenv:w_zodb-pure]
basepython =
python2.7
deps =
ZODB

[testenv:coverage]
basepython =
python3.6
Expand Down

0 comments on commit 0c4c48f

Please sign in to comment.