class AnyDBMTestCase:
- _dict = {'0': b'',
- 'a': b'Python:',
+ _dict = {'a': b'Python:',
'b': b'Programming',
'c': b'the',
'd': b'way',
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')
self.assertEqual(self.d[b'xxx'], b'foo')
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: