diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-04-29 12:38:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-29 12:38:06 +0300 |
commit | 2e38cc39330bd7f3003652869b644110a97a78d8 (patch) | |
tree | 5f1a63d9c23d486cdbf8a588e442d3c307917b07 /Lib/test/test_dbm_dumb.py | |
parent | 577948329976985ea9bef23d9a6c3dd7108211bf (diff) | |
download | cpython-2e38cc39330bd7f3003652869b644110a97a78d8.tar.gz cpython-2e38cc39330bd7f3003652869b644110a97a78d8.zip |
bpo-33383: Fix crash in get() of the dbm.ndbm database object. (#6630)
Diffstat (limited to 'Lib/test/test_dbm_dumb.py')
-rw-r--r-- | Lib/test/test_dbm_dumb.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py index 652a355d990..58b9d174656 100644 --- a/Lib/test/test_dbm_dumb.py +++ b/Lib/test/test_dbm_dumb.py @@ -73,6 +73,9 @@ class DumbDBMTestCase(unittest.TestCase): f = dumbdbm.open(_fname, 'w') self._dict[b'g'] = f[b'g'] = b"indented" self.read_helper(f) + # setdefault() works as in the dict interface + self.assertEqual(f.setdefault(b'xxx', b'foo'), b'foo') + self.assertEqual(f[b'xxx'], b'foo') f.close() def test_dumbdbm_read(self): @@ -85,6 +88,12 @@ class DumbDBMTestCase(unittest.TestCase): with self.assertRaisesRegex(ValueError, 'The database is opened for reading only'): del f[b'a'] + # get() works as in the dict interface + self.assertEqual(f.get(b'a'), self._dict[b'a']) + self.assertEqual(f.get(b'xxx', b'foo'), b'foo') + self.assertIsNone(f.get(b'xxx')) + with self.assertRaises(KeyError): + f[b'xxx'] f.close() def test_dumbdbm_keys(self): |