diff options
Diffstat (limited to 'Lib/test/test_file.py')
-rw-r--r-- | Lib/test/test_file.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index dffa4b56eb6..bb0da792f55 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -1,8 +1,3 @@ -# NOTE: this file tests the new `io` library backported from Python 3.x. -# Similar tests for the builtin file object can be found in test_file2k.py. - -from __future__ import print_function - import sys import os import unittest @@ -12,8 +7,8 @@ from weakref import proxy import io import _pyio as pyio -from test.test_support import TESTFN, run_unittest -from UserList import UserList +from test.support import TESTFN, run_unittest +from collections import UserList class AutoFileTests(unittest.TestCase): # file tests for which a test file is automatically set up @@ -49,7 +44,7 @@ class AutoFileTests(unittest.TestCase): a = array('b', b'x'*10) self.f = self.open(TESTFN, 'rb') n = self.f.readinto(a) - self.assertEqual(b'12', a.tostring()[:n]) + self.assertEqual(b'12', a.tobytes()[:n]) def testReadinto_text(self): # verify readinto refuses text files @@ -100,7 +95,7 @@ class AutoFileTests(unittest.TestCase): methods = [('fileno', ()), ('flush', ()), ('isatty', ()), - ('next', ()), + ('__next__', ()), ('read', ()), ('write', (b"",)), ('readline', ()), @@ -111,8 +106,7 @@ class AutoFileTests(unittest.TestCase): ('writelines', ([],)), ('__iter__', ()), ] - if not sys.platform.startswith('atheos'): - methods.append(('truncate', ())) + methods.append(('truncate', ())) # __exit__ should close the file self.f.__exit__(None, None, None) @@ -127,7 +121,7 @@ class AutoFileTests(unittest.TestCase): self.assertEqual(self.f.__exit__(None, None, None), None) # it must also return None if an exception was given try: - 1 // 0 + 1/0 except: self.assertEqual(self.f.__exit__(*sys.exc_info()), None) @@ -287,7 +281,7 @@ class OtherFileTests(unittest.TestCase): except ValueError: self.fail("readinto() after next() with supposedly empty " "iteration-buffer failed anyway") - line = buf.tostring() + line = buf.tobytes() if line != testline: self.fail("readinto() after next() with empty buffer " "failed. Got %r, expected %r" % (line, testline)) @@ -309,6 +303,8 @@ class OtherFileTests(unittest.TestCase): if lines != testlines: self.fail("readlines() after next() with empty buffer " "failed. Got %r, expected %r" % (line, testline)) + f.close() + # Reading after iteration hit EOF shouldn't hurt either f = self.open(TESTFN, 'rb') try: |