import sys
import os
+import errno
import unittest
from array import array
from weakref import proxy
else:
self.fail("Should have raised IOError")
+ def testErrnoOnClose(self):
+ # Test that the IOError's `errno` attribute is correctly set when
+ # close() fails. Here we first close the file descriptor ourselves so
+ # that close() fails with EBADF ('Bad file descriptor').
+ f = self.f
+ os.close(f.fileno())
+ self.f = None
+ try:
+ f.close()
+ except IOError as e:
+ self.assertEqual(e.errno, errno.EBADF)
+ else:
+ self.fail("Should have raised IOError")
+
class OtherFileTests(unittest.TestCase):
Library
-------
+- The error detection code in FileIO.close() could fail to reflect the `errno`
+ value, and report it as -1 instead.
+
What's New in Python 3.1 alpha 1
================================
Py_RETURN_NONE;
}
errno = internal_close(self);
- if (errno < 0) {
- PyErr_SetFromErrno(PyExc_IOError);
+ if (errno < 0)
return NULL;
- }
return PyObject_CallMethod((PyObject*)&PyRawIOBase_Type,
"close", "O", self);