Commit cb8b868e authored by Jeremy Hylton's avatar Jeremy Hylton

Backport simplified versions of BTrees tests from ZOpe3.

parent 18cd8b10
...@@ -26,85 +26,64 @@ from unittest import TestCase, TestSuite, TextTestRunner, makeSuite ...@@ -26,85 +26,64 @@ from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
from glob import glob from glob import glob
from ZODB.tests.StorageTestBase import removefs from ZODB.tests.StorageTestBase import removefs
from ZODB import DB
from ZODB.MappingStorage import MappingStorage
class Base: class Base:
""" Tests common to all types: sets, buckets, and BTrees """ """ Tests common to all types: sets, buckets, and BTrees """
db = None
def tearDown(self): def tearDown(self):
self.t = None self.t = None
del self.t del self.t
if self.db is not None:
self.db.close()
def _getRoot(self): def _getRoot(self):
from ZODB.FileStorage import FileStorage if self.db is None:
from ZODB.DB import DB self.db = DB(MappingStorage())
self._fsname = 'fs_tmp__%s' % os.getpid() return self.db.open().root()
s = FileStorage(self._fsname)
db = DB(s)
root = db.open().root()
return root
def _closeDB(self, root):
if root is not None:
root._p_jar._db.close()
def _delDB(self): def _closeRoot(self, root):
removefs(self._fsname) root._p_jar.close()
def testLoadAndStore(self): def testLoadAndStore(self):
for i in 0, 10, 1000: for i in 0, 10, 1000:
t = self.t.__class__() t = self.t.__class__()
self._populate(t, i) self._populate(t, i)
root = None root = None
try:
root = self._getRoot() root = self._getRoot()
root[i] = t root[i] = t
get_transaction().commit() get_transaction().commit()
except:
self._closeDB(root)
self._delDB()
raise
self._closeDB(root)
root = None root2 = self._getRoot()
try:
root = self._getRoot()
#XXX BTree stuff doesn't implement comparison
if hasattr(t, 'items'): if hasattr(t, 'items'):
self.assertEqual(list(root[i].items()) , list(t.items())) self.assertEqual(list(root2[i].items()) , list(t.items()))
else: else:
self.assertEqual(list(root[i].keys()) , list(t.keys())) self.assertEqual(list(root2[i].keys()) , list(t.keys()))
finally:
self._closeDB(root) self._closeRoot(root)
self._delDB() self._closeRoot(root2)
def testGhostUnghost(self): def testGhostUnghost(self):
for i in 0, 10, 1000: for i in 0, 10, 1000:
t = self.t.__class__() t = self.t.__class__()
self._populate(t, i) self._populate(t, i)
root = None
try:
root = self._getRoot() root = self._getRoot()
root[i] = t root[i] = t
get_transaction().commit() get_transaction().commit()
except:
self._closeDB(root)
self._delDB()
raise
self._closeDB(root) root2 = self._getRoot()
root2[i]._p_deactivate()
root = None
try:
root = self._getRoot()
root[i]._p_changed = None
get_transaction().commit() get_transaction().commit()
if hasattr(t,'items'): if hasattr(t, 'items'):
self.assertEqual(list(root[i].items()) , list(t.items())) self.assertEqual(list(root2[i].items()) , list(t.items()))
else: else:
self.assertEqual(list(root[i].keys()) , list(t.keys())) self.assertEqual(list(root2[i].keys()) , list(t.keys()))
finally:
self._closeDB(root) self._closeRoot(root)
self._delDB() self._closeRoot(root2)
class MappingBase(Base): class MappingBase(Base):
""" Tests common to mappings (buckets, btrees) """ """ Tests common to mappings (buckets, btrees) """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment