[Zodb-checkins] CVS: StandaloneZODB/BTrees/tests - testBTrees.py:1.26

Guido van Rossum guido@python.org
Fri, 25 Jan 2002 16:04:27 -0500


Update of /cvs-repository/StandaloneZODB/BTrees/tests
In directory cvs.zope.org:/tmp/cvs-serv11611

Modified Files:
	testBTrees.py 
Log Message:
Fix a problem I saw when some tests here failed: there's a pattern in
the code

    try:
        root = self._getRoot()
        ...
    except:
        self._closeDB(root)
	self._delDB()
	raise

which fails with an UnboundLocalError if the first line in the try
clause fails.  Fixed this by setting 'root = None' before each such
try clause, and adding a None check to _closeDB().  Also removed a
useless 'root = None' from the body of _closeDB().

Barry: I saw this in the saz 1.0c1 release.  Is it worth backporting?
Probably not given that we're not going to do a merge pre-1.0.


=== StandaloneZODB/BTrees/tests/testBTrees.py 1.25 => 1.26 ===
 
     def _closeDB(self, root):
-        root._p_jar._db.close()
-        root = None
+        if root is not None:
+            root._p_jar._db.close()
 
     def _delDB(self):
         for file in glob('fs_tmp__*'):
@@ -48,6 +48,7 @@
         for i in 0, 10, 1000:
             t = self.t.__class__()
             self._populate(t, i)
+            root = None
             try:
                 root = self._getRoot()
                 root[i] = t
@@ -59,6 +60,7 @@
 
             self._closeDB(root)
 
+            root = None
             try:
                 root = self._getRoot()
                 #XXX BTree stuff doesn't implement comparison
@@ -74,6 +76,7 @@
         for i in 0, 10, 1000:
             t = self.t.__class__()
             self._populate(t, i)
+            root = None
             try:
                 root = self._getRoot()
                 root[i] = t
@@ -85,6 +88,7 @@
 
             self._closeDB(root)
 
+            root = None
             try:
                 root = self._getRoot()
                 root[i]._p_changed = None