summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dbm_dumb.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-04-29 11:50:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-04-29 11:50:26 (GMT)
commitee95feb69d937149bef3d245e87df1aef412b7fc (patch)
treee006b3c754dff27577a127ec85a5f6fda873f9db /Lib/test/test_dbm_dumb.py
parent1487c37e7e85e7221adc3030f0f7de023cc99ced (diff)
downloadcpython-ee95feb69d937149bef3d245e87df1aef412b7fc.zip
cpython-ee95feb69d937149bef3d245e87df1aef412b7fc.tar.gz
cpython-ee95feb69d937149bef3d245e87df1aef412b7fc.tar.bz2
[3.7] bpo-33383: Fix crash in get() of the dbm.ndbm database object. (GH-6630) (GH-6631)
(cherry picked from commit 2e38cc39330bd7f3003652869b644110a97a78d8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_dbm_dumb.py')
-rw-r--r--Lib/test/test_dbm_dumb.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py
index fa14238..7f5c09f 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.assertWarnsRegex(DeprecationWarning,
'The database is opened for reading only'):
del f[b'a']
+ # get() works as in the dict interface
+ self.assertEqual(f.get(b'b'), self._dict[b'b'])
+ 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):