Skip to content

Commit

Permalink
[3.5] bpo-31026: Fix test_dbm if dbm.ndbm is build with Berkeley DB. (G…
Browse files Browse the repository at this point in the history
…H-6632)

(cherry picked from commit 70af06c)
  • Loading branch information
serhiy-storchaka authored and larryhastings committed Oct 29, 2019
1 parent 3fe1b19 commit d7b336f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Lib/test/test_dbm.py
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_dbm_ndbm.py
Expand Up @@ -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:
Expand Down

0 comments on commit d7b336f

Please sign in to comment.