[3.7] bpo-33383: Fix crash in get() of the dbm.ndbm database object. (GH-6630) (GH-6631)

(cherry picked from commit 2e38cc3933)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-04-29 04:50:26 -07:00 committed by Serhiy Storchaka
parent 1487c37e7e
commit ee95feb69d
7 changed files with 38 additions and 7 deletions

View file

@ -18,7 +18,7 @@ class DbmTestCase(unittest.TestCase):
def test_keys(self):
self.d = dbm.ndbm.open(self.filename, 'c')
self.assertTrue(self.d.keys() == [])
self.assertEqual(self.d.keys(), [])
self.d['a'] = 'b'
self.d[b'bytes'] = b'data'
self.d['12345678910'] = '019237410982340912840198242'
@ -26,6 +26,14 @@ class DbmTestCase(unittest.TestCase):
self.assertIn('a', self.d)
self.assertIn(b'a', self.d)
self.assertEqual(self.d[b'bytes'], b'data')
# get() and setdefault() work as in the dict interface
self.assertEqual(self.d.get(b'a'), b'b')
self.assertIsNone(self.d.get(b'xxx'))
self.assertEqual(self.d.get(b'xxx', b'foo'), b'foo')
with self.assertRaises(KeyError):
self.d['xxx']
self.assertEqual(self.d.setdefault(b'xxx', b'foo'), b'foo')
self.assertEqual(self.d[b'xxx'], b'foo')
self.d.close()
def test_modes(self):