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(gdbm.error) as cm:
+ gdbm.open(nonexisting_file)
+ self.assertIn(nonexisting_file, str(cm.exception))
+ self.assertEqual(cm.exception.filename, nonexisting_file)
+
if __name__ == '__main__':
unittest.main()
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__':
--- /dev/null
+Report filename in the exception raised when the database file cannot be opened
+by :func:`dbm.gnu.open` and :func:`dbm.ndbm.open` due to OS-related error.
+Patch by Zsolt Cserna.
dp->di_size = -1;
/* See issue #19296 */
if ( (dp->di_dbm = dbm_open((char *)file, flags, mode)) == 0 ) {
- PyErr_SetFromErrno(DbmError);
+ PyErr_SetFromErrnoWithFilename(DbmError, file);
Py_DECREF(dp);
return NULL;
}
errno = 0;
if ((dp->di_dbm = gdbm_open((char *)file, 0, flags, mode, NULL)) == 0) {
if (errno != 0)
- PyErr_SetFromErrno(DbmError);
+ PyErr_SetFromErrnoWithFilename(DbmError, file);
else
PyErr_SetString(DbmError, gdbm_strerror(gdbm_errno));
Py_DECREF(dp);