diff options
Diffstat (limited to 'Lib/test/test_fileio.py')
| -rw-r--r-- | Lib/test/test_fileio.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 444be91..a4fd20d 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -113,22 +113,22 @@ class AutoFileTests(unittest.TestCase): def testErrors(self): f = self.f - self.assertTrue(not f.isatty()) - self.assertTrue(not f.closed) + self.assertFalse(f.isatty()) + self.assertFalse(f.closed) #self.assertEqual(f.name, TESTFN) self.assertRaises(ValueError, f.read, 10) # Open for reading f.close() self.assertTrue(f.closed) f = _FileIO(TESTFN, 'r') self.assertRaises(TypeError, f.readinto, "") - self.assertTrue(not f.closed) + self.assertFalse(f.closed) f.close() self.assertTrue(f.closed) def testMethods(self): - methods = ['fileno', 'isatty', 'read', 'readinto', - 'seek', 'tell', 'truncate', 'write', 'seekable', - 'readable', 'writable'] + methods = ['fileno', 'isatty', 'seekable', 'readable', 'writable', + 'read', 'readall', 'readline', 'readlines', + 'tell', 'truncate', 'flush'] self.f.close() self.assertTrue(self.f.closed) @@ -138,22 +138,31 @@ class AutoFileTests(unittest.TestCase): # should raise on closed file self.assertRaises(ValueError, method) + self.assertRaises(ValueError, self.f.readinto) # XXX should be TypeError? + self.assertRaises(ValueError, self.f.readinto, bytearray(1)) + self.assertRaises(ValueError, self.f.seek) + self.assertRaises(ValueError, self.f.seek, 0) + self.assertRaises(ValueError, self.f.write) + self.assertRaises(ValueError, self.f.write, b'') + self.assertRaises(TypeError, self.f.writelines) + self.assertRaises(ValueError, self.f.writelines, b'') + def testOpendir(self): # Issue 3703: opening a directory should fill the errno # Windows always returns "[Errno 13]: Permission denied # Unix calls dircheck() and returns "[Errno 21]: Is a directory" try: _FileIO('.', 'r') - except IOError as e: + except OSError as e: self.assertNotEqual(e.errno, 0) self.assertEqual(e.filename, ".") else: - self.fail("Should have raised IOError") + self.fail("Should have raised OSError") @unittest.skipIf(os.name == 'nt', "test only works on a POSIX-like system") def testOpenDirFD(self): fd = os.open('.', os.O_RDONLY) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: _FileIO(fd, 'r') os.close(fd) self.assertEqual(cm.exception.errno, errno.EISDIR) @@ -171,7 +180,7 @@ class AutoFileTests(unittest.TestCase): finally: try: self.f.close() - except IOError: + except OSError: pass return wrapper @@ -183,14 +192,14 @@ class AutoFileTests(unittest.TestCase): os.close(f.fileno()) try: func(self, f) - except IOError as e: + except OSError as e: self.assertEqual(e.errno, errno.EBADF) else: - self.fail("Should have raised IOError") + self.fail("Should have raised OSError") finally: try: self.f.close() - except IOError: + except OSError: pass return wrapper @@ -237,7 +246,7 @@ class AutoFileTests(unittest.TestCase): def ReopenForRead(self): try: self.f.close() - except IOError: + except OSError: pass self.f = _FileIO(TESTFN, 'r') os.close(self.f.fileno()) @@ -285,7 +294,7 @@ class OtherFileTests(unittest.TestCase): if sys.platform != "win32": try: f = _FileIO("/dev/tty", "a") - except EnvironmentError: + except OSError: # When run in a cron job there just aren't any # ttys, so skip the test. This also handles other # OS'es that don't support /dev/tty. @@ -360,7 +369,7 @@ class OtherFileTests(unittest.TestCase): self.assertRaises(OSError, _FileIO, make_bad_fd()) if sys.platform == 'win32': import msvcrt - self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd()) + self.assertRaises(OSError, msvcrt.get_osfhandle, make_bad_fd()) @cpython_only def testInvalidFd_overflow(self): |
