Update test_file from CPython 3.10.6

This commit is contained in:
CPython Developers authored and Jeong YunWon committed 2022-08-15 04:54:01 +09:00
1 parent 0181e2b380
commit 01dc2b4f6f
2 files changed
+30 -14

No files matched your search

+22 -3
View File
@@ -7,8 +7,10 @@ from weakref import proxy
import io
import _pyio as pyio
from test.support import os_helper, warnings_helper
from test.support import gc_collect
from test.support.os_helper import TESTFN
from test.support import os_helper
from test.support import warnings_helper
from collections import UserList
class AutoFileTests:
@@ -29,6 +31,7 @@ class AutoFileTests:
self.assertEqual(self.f.tell(), p.tell())
self.f.close()
self.f = None
gc_collect() # For PyPy or other GCs.
self.assertRaises(ReferenceError, getattr, p, 'tell')
def testAttributes(self):
@@ -51,7 +54,7 @@ class AutoFileTests:
# verify readinto refuses text files
a = array('b', b'x'*10)
self.f.close()
self.f = self.open(TESTFN, 'r')
self.f = self.open(TESTFN, encoding="utf-8")
if hasattr(self.f, "readinto"):
self.assertRaises(TypeError, self.f.readinto, a)
@@ -132,7 +135,6 @@ class AutoFileTests:
class CAutoFileTests(AutoFileTests, unittest.TestCase):
open = io.open
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, test setUp errors on Windows")
class PyAutoFileTests(AutoFileTests, unittest.TestCase):
open = staticmethod(pyio.open)
@@ -154,6 +156,22 @@ class OtherFileTests:
f.close()
self.fail('%r is an invalid file mode' % mode)
def testStdin(self):
if sys.platform == 'osf1V5':
# This causes the interpreter to exit on OSF1 v5.1.
self.skipTest(
' sys.stdin.seek(-1) may crash the interpreter on OSF1.'
' Test manually.')
if not sys.stdin.isatty():
# Issue 14853: stdin becomes seekable when redirected to a file
self.skipTest('stdin must be a TTY in this test')
with self.assertRaises((IOError, ValueError)):
sys.stdin.seek(-1)
with self.assertRaises((IOError, ValueError)):
sys.stdin.truncate()
def testBadModeArgument(self):
# verify that we get a sensible error message for bad mode argument
bad_mode = "qwerty"
@@ -334,5 +352,6 @@ class COtherFileTests(OtherFileTests, unittest.TestCase):
class PyOtherFileTests(OtherFileTests, unittest.TestCase):
open = staticmethod(pyio.open)
if __name__ == '__main__':
unittest.main()
+8 -11
View File
@@ -9,8 +9,8 @@ from array import array
from weakref import proxy
from functools import wraps
from test.support import run_unittest, cpython_only, swap_attr
from test.support.os_helper import TESTFN, TESTFN_UNICODE, make_bad_fd
from test.support import cpython_only, swap_attr, gc_collect
from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd)
from test.support.warnings_helper import check_warnings
from collections import UserList
@@ -36,6 +36,7 @@ class AutoFileTests:
self.assertEqual(self.f.tell(), p.tell())
self.f.close()
self.f = None
gc_collect() # For PyPy or other GCs.
self.assertRaises(ReferenceError, getattr, p, 'tell')
def testSeekTell(self):
@@ -177,7 +178,6 @@ class AutoFileTests:
finally:
os.close(fd)
@unittest.skipIf(getattr(sys, '_rustpython_debugbuild', False), "TODO: RUSTPYTHON, stack overflow on debug build")
def testRecursiveRepr(self):
# Issue #25455
with swap_attr(self.f, 'name', self.f):
@@ -664,15 +664,12 @@ class PyOtherFileTests(OtherFileTests, unittest.TestCase):
self.assertNotEqual(w.warnings, [])
def test_main():
def tearDownModule():
# Historically, these tests have been sloppy about removing TESTFN.
# So get rid of it no matter what.
try:
run_unittest(CAutoFileTests, PyAutoFileTests,
COtherFileTests, PyOtherFileTests)
finally:
if os.path.exists(TESTFN):
os.unlink(TESTFN)
if os.path.exists(TESTFN):
os.unlink(TESTFN)
if __name__ == '__main__':
test_main()
unittest.main()