Add a unit test for bug fix #1396678.
authorGeorg Brandl <georg@python.org>
Sun, 19 Feb 2006 01:21:11 +0000 (01:21 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 19 Feb 2006 01:21:11 +0000 (01:21 +0000)
Lib/bsddb/__init__.py
Lib/bsddb/test/test_misc.py

index 781a22bb7bb0fe4cf23ac86d9f4925fbe6b47cac..4903584a66ebe524ec2e9aa888f68ec370d6d9f5 100644 (file)
@@ -111,11 +111,10 @@ class _iter_mixin(UserDict.DictMixin):
             return
 
     def iteritems(self):
+        if not self.db:
+            return
         try:
-            try:
-                cur = self._make_iter_cursor()
-            except AttributeError:
-                return
+            cur = self._make_iter_cursor()
 
             # FIXME-20031102-greg: race condition.  cursor could
             # be closed by another thread before this call.
index a66b1de8a7c75c701a823755b4c24ba40a195630..88f700b46979aa218e1c99251694ed5dc78d26d5 100644 (file)
@@ -7,10 +7,10 @@ import unittest
 
 try:
     # For Pythons w/distutils pybsddb
-    from bsddb3 import db, dbshelve
+    from bsddb3 import db, dbshelve, hashopen
 except ImportError:
     # For Python 2.3
-    from bsddb import db, dbshelve
+    from bsddb import db, dbshelve, hashopen
 
 #----------------------------------------------------------------------
 
@@ -46,6 +46,12 @@ class MiscTestCase(unittest.TestCase):
         env.open(self.homeDir, db.DB_CREATE)
         assert self.homeDir == env.db_home
 
+    def test03_repr_closed_db(self):
+        db = hashopen(self.filename)
+        db.close()
+        rp = repr(db)
+        self.assertEquals(rp, "{}")
+
 
 #----------------------------------------------------------------------