summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dbm_ndbm.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-04-29 09:38:06 (GMT)
committerGitHub <noreply@github.com>2018-04-29 09:38:06 (GMT)
commit2e38cc39330bd7f3003652869b644110a97a78d8 (patch)
tree5f1a63d9c23d486cdbf8a588e442d3c307917b07 /Lib/test/test_dbm_ndbm.py
parent577948329976985ea9bef23d9a6c3dd7108211bf (diff)
downloadcpython-2e38cc39330bd7f3003652869b644110a97a78d8.zip
cpython-2e38cc39330bd7f3003652869b644110a97a78d8.tar.gz
cpython-2e38cc39330bd7f3003652869b644110a97a78d8.tar.bz2
bpo-33383: Fix crash in get() of the dbm.ndbm database object. (#6630)
Diffstat (limited to 'Lib/test/test_dbm_ndbm.py')
-rw-r--r--Lib/test/test_dbm_ndbm.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py
index fb7d0e8..f921167 100644
--- a/Lib/test/test_dbm_ndbm.py
+++ b/Lib/test/test_dbm_ndbm.py
@@ -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):