[Python-checkins] cpython (3.3): #17198: Fix a NameError in the dbm module. Patch by Valentina Mukhamedzhanova.

ezio.melotti python-checkins at python.org
Sun Jul 7 13:16:16 CEST 2013


http://hg.python.org/cpython/rev/65fce1dad331
changeset:   84484:65fce1dad331
branch:      3.3
parent:      84482:406ce103c170
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sun Jul 07 13:15:08 2013 +0200
summary:
  #17198: Fix a NameError in the dbm module.  Patch by Valentina Mukhamedzhanova.

files:
  Lib/dbm/__init__.py  |   5 +++++
  Lib/test/test_dbm.py |  18 ++++++++++++++++--
  Misc/NEWS            |   3 +++
  3 files changed, 24 insertions(+), 2 deletions(-)


diff --git a/Lib/dbm/__init__.py b/Lib/dbm/__init__.py
--- a/Lib/dbm/__init__.py
+++ b/Lib/dbm/__init__.py
@@ -44,6 +44,11 @@
 
 error = (error, IOError)
 
+try:
+    from dbm import ndbm
+except ImportError:
+    ndbm = None
+
 
 def open(file, flag='r', mode=0o666):
     """Open or create database at path given by *file*.
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -9,6 +9,11 @@
 # Skip tests if dbm module doesn't exist.
 dbm = test.support.import_module('dbm')
 
+try:
+    from dbm import ndbm
+except ImportError:
+    ndbm = None
+
 _fname = test.support.TESTFN
 
 #
@@ -130,7 +135,7 @@
             delete_files()
             f = module.open(_fname, 'c')
             f.close()
-            self.assertEqual(name, dbm.whichdb(_fname))
+            self.assertEqual(name, self.dbm.whichdb(_fname))
             # Now add a key
             f = module.open(_fname, 'w')
             f[b"1"] = b"1"
@@ -139,7 +144,15 @@
             # and read it
             self.assertTrue(f[b"1"] == b"1")
             f.close()
-            self.assertEqual(name, dbm.whichdb(_fname))
+            self.assertEqual(name, self.dbm.whichdb(_fname))
+
+    @unittest.skipUnless(ndbm, reason='Test requires ndbm')
+    def test_whichdb_ndbm(self):
+        # Issue 17198: check that ndbm which is referenced in whichdb is defined
+        db_file = '{}_ndbm.db'.format(_fname)
+        with open(db_file, 'w'):
+            self.addCleanup(test.support.unlink, db_file)
+        self.assertIsNone(self.dbm.whichdb(db_file[:-3]))
 
     def tearDown(self):
         delete_files()
@@ -149,6 +162,7 @@
         self.filename = test.support.TESTFN
         self.d = dbm.open(self.filename, 'c')
         self.d.close()
+        self.dbm = test.support.import_fresh_module('dbm')
 
     def test_keys(self):
         self.d = dbm.open(self.filename, 'c')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -41,6 +41,9 @@
 Library
 -------
 
+- Issue #17198: Fix a NameError in the dbm module.  Patch by Valentina
+  Mukhamedzhanova.
+
 - Issue #18013: Fix cgi.FieldStorage to parse the W3C sample form.
 
 - Issue #18347: ElementTree's html serializer now preserves the case of

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list