mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
59ee5b1293
commit
9df346bf98
5 changed files with 18 additions and 2 deletions
|
@ -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__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue