From 40e5081c43b2befe9faa1d18d0bff12fbe78ad7f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 19 Jan 2009 21:07:05 +0000 Subject: [PATCH] Merged revisions 68782 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r68782 | benjamin.peterson | 2009-01-19 15:00:09 -0600 (Mon, 19 Jan 2009) | 9 lines Merged revisions 68779 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r68779 | benjamin.peterson | 2009-01-19 11:37:42 -0600 (Mon, 19 Jan 2009) | 1 line make bad file descriptor tests more robust ........ ................ --- Lib/test/support.py | 12 ++++++++++++ Lib/test/test_fileio.py | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/test/support.py b/Lib/test/support.py index 5f8b1ba1cdd5..68791d514f96 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -344,6 +344,18 @@ def sortdict(dict): withcommas = ", ".join(reprpairs) return "{%s}" % withcommas +def make_bad_fd(): + """ + Create an invalid file descriptor by opening and closing a file and return + its fd. + """ + file = open(TESTFN, "wb") + try: + return file.fileno() + finally: + file.close() + unlink(TESTFN) + def check_syntax_error(testcase, statement): try: compile(statement, '', 'exec') diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 69aa3fd23c0f..497914f583eb 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -6,7 +6,8 @@ import unittest from array import array from weakref import proxy -from test.support import TESTFN, findfile, check_warnings, run_unittest +from test.support import (TESTFN, findfile, check_warnings, run_unittest, + make_bad_fd) from collections import UserList import _fileio @@ -177,7 +178,7 @@ class OtherFileTests(unittest.TestCase): def testInvalidFd(self): self.assertRaises(ValueError, _fileio._FileIO, -10) - self.assertRaises(OSError, _fileio._FileIO, 10) + self.assertRaises(OSError, _fileio._FileIO, make_bad_fd()) def testBadModeArgument(self): # verify that we get a sensible error message for bad mode argument -- 2.47.3