bpo-33383: Fix crash in get() of the dbm.ndbm database object. (#6630)

This commit is contained in:
Serhiy Storchaka 2018-04-29 12:38:06 +03:00 committed by GitHub
parent 5779483299
commit 2e38cc3933
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 7 deletions

View file

@ -32,9 +32,12 @@ class TestGdbm(unittest.TestCase):
self.assertIn(key, key_set)
key_set.remove(key)
key = self.g.nextkey(key)
self.assertRaises(KeyError, lambda: self.g['xxx'])
# get() and setdefault() work as in the dict interface
self.assertEqual(self.g.get(b'a'), b'b')
self.assertIsNone(self.g.get(b'xxx'))
self.assertEqual(self.g.get(b'xxx', b'foo'), b'foo')
with self.assertRaises(KeyError):
self.g['xxx']
self.assertEqual(self.g.setdefault(b'xxx', b'foo'), b'foo')
self.assertEqual(self.g[b'xxx'], b'foo')