summaryrefslogtreecommitdiff
path: root/Lib/test/test_fileio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-03-13 22:33:17 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2009-03-13 22:33:17 +0000
commit0ae29cf6176d3f80c1845cf23716a708acbe598b (patch)
treef6f6463670ede6c7e4ab0c15867bfe6c0764e3d8 /Lib/test/test_fileio.py
parent652e7076fee59d92d19a0d6e326b9069a2aa09e4 (diff)
downloadcpython-git-0ae29cf6176d3f80c1845cf23716a708acbe598b.tar.gz
The error detection code in FileIO.close() could fail to reflect the `errno` value, and report it as -1 instead.
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r--Lib/test/test_fileio.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 498d3fc5a5..9f94053e47 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -2,6 +2,7 @@
import sys
import os
+import errno
import unittest
from array import array
from weakref import proxy
@@ -113,6 +114,20 @@ class AutoFileTests(unittest.TestCase):
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):