bpo-34248: Add filename to error raised in {gnu,ndbm}.open() (GH-8590)

Report the filename to the exception when raising {gdbm,dbm.ndbm}.error in
dbm.gnu.open() and dbm.ndbm.open() functions, so it gets printed when the
exception is raised, and can also be obtained by the filename attribute of the
exception object.
This commit is contained in:
Zsolt Cserna 2018-09-27 21:54:34 +02:00 committed by Berker Peksag
parent 59ee5b1293
commit 9df346bf98
5 changed files with 18 additions and 2 deletions

View file

@ -105,6 +105,12 @@ class DbmTestCase(unittest.TestCase):
self.assertTrue(b'key' in db)
self.assertEqual(db[b'key'], b'value')
def test_nonexisting_file(self):
nonexisting_file = 'nonexisting-file'
with self.assertRaises(dbm.ndbm.error) as cm:
dbm.ndbm.open(nonexisting_file)
self.assertIn(nonexisting_file, str(cm.exception))
self.assertEqual(cm.exception.filename, nonexisting_file)
if __name__ == '__main__':