diff options
author | Zsolt Cserna <cserna.zsolt@gmail.com> | 2018-09-27 19:54:34 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2018-09-27 19:54:34 (GMT) |
commit | 9df346bf98069a87de14a3c2f69009d800994c63 (patch) | |
tree | a05c995a24c0182d60b80eebbe0009dcd506117e /Lib/test/test_dbm_ndbm.py | |
parent | 59ee5b12938efbf534f2a19300a847bf6b23a77d (diff) | |
download | cpython-9df346bf98069a87de14a3c2f69009d800994c63.zip cpython-9df346bf98069a87de14a3c2f69009d800994c63.tar.gz cpython-9df346bf98069a87de14a3c2f69009d800994c63.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/test_dbm_ndbm.py')
-rw-r--r-- | Lib/test/test_dbm_ndbm.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_ndbm.py b/Lib/test/test_dbm_ndbm.py index 49b88f5..bd411da 100644 --- a/Lib/test/test_dbm_ndbm.py +++ b/Lib/test/test_dbm_ndbm.py @@ -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__': |