[Python-checkins] [3.5] bpo-31026: Fix test_dbm if dbm.ndbm is build with Berkeley DB. (GH-6632)

Larry Hastings webhook-mailer at python.org
Tue Oct 29 04:00:51 EDT 2019


https://github.com/python/cpython/commit/d7b336fe5d54f73c758802df426e06e8a674bd63
commit: d7b336fe5d54f73c758802df426e06e8a674bd63
branch: 3.5
author: Serhiy Storchaka <storchaka at gmail.com>
committer: Larry Hastings <larry at hastings.org>
date: 2019-10-28T22:56:33-07:00
summary:

[3.5] bpo-31026: Fix test_dbm if dbm.ndbm is build with Berkeley DB. (GH-6632)
(cherry picked from commit 70af06cdc4e8fbee0b9d7d46bdc193097d4bc71f)

files:
M Lib/test/test_dbm.py
M Lib/test/test_dbm_ndbm.py

diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index 623d9929d58f7..81857e6f88525 100644
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -39,8 +39,7 @@ def delete_files():
 
 
 class AnyDBMTestCase:
-    _dict = {'0': b'',
-             'a': b'Python:',
+    _dict = {'a': b'Python:',
              'b': b'Programming',
              'c': b'the',
              'd': b'way',
@@ -101,6 +100,20 @@ def test_anydbm_keys(self):
         keys = self.keys_helper(f)
         f.close()
 
+    def test_empty_value(self):
+        if getattr(dbm._defaultmod, 'library', None) == 'Berkeley DB':
+            self.skipTest("Berkeley DB doesn't distinguish the empty value "
+                          "from the absent one")
+        f = dbm.open(_fname, 'c')
+        self.assertEqual(f.keys(), [])
+        f[b'empty'] = b''
+        self.assertEqual(f.keys(), [b'empty'])
+        self.assertIn(b'empty', f)
+        self.assertEqual(f[b'empty'], b'')
+        self.assertEqual(f.get(b'empty'), b'')
+        self.assertEqual(f.setdefault(b'empty'), b'')
+        f.close()
+
     def test_anydbm_access(self):
         self.init_db()
         f = dbm.open(_fname, 'r')
diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py
index 2291561defc4d..463dd38f254ec 100644
--- a/Lib/test/test_dbm_ndbm.py
+++ b/Lib/test/test_dbm_ndbm.py
@@ -29,6 +29,20 @@ def test_keys(self):
         self.assertEqual(self.d[b'bytes'], b'data')
         self.d.close()
 
+    def test_empty_value(self):
+        if dbm.ndbm.library == 'Berkeley DB':
+            self.skipTest("Berkeley DB doesn't distinguish the empty value "
+                          "from the absent one")
+        self.d = dbm.ndbm.open(self.filename, 'c')
+        self.assertEqual(self.d.keys(), [])
+        self.d['empty'] = ''
+        self.assertEqual(self.d.keys(), [b'empty'])
+        self.assertIn(b'empty', self.d)
+        self.assertEqual(self.d[b'empty'], b'')
+        self.assertEqual(self.d.get(b'empty'), b'')
+        self.assertEqual(self.d.setdefault(b'empty'), b'')
+        self.d.close()
+
     def test_modes(self):
         for mode in ['r', 'rw', 'w', 'n']:
             try:



More information about the Python-checkins mailing list