mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-40275: Use new test.support helper submodules in tests (GH-21151)
Use new test.support helper submodules in tests: * distutils tests * test_buffer * test_compile * test_filecmp * test_fileinput * test_readline * test_smtpnet * test_structmembers * test_tools
This commit is contained in:
parent
700cfa8c90
commit
847f94f47b
20 changed files with 69 additions and 42 deletions
|
@ -24,8 +24,11 @@ from io import BytesIO, StringIO
|
|||
from fileinput import FileInput, hook_encoded
|
||||
from pathlib import Path
|
||||
|
||||
from test.support import verbose, TESTFN, check_warnings
|
||||
from test.support import unlink as safe_unlink
|
||||
from test.support import verbose
|
||||
from test.support.os_helper import TESTFN
|
||||
from test.support.os_helper import unlink as safe_unlink
|
||||
from test.support import os_helper
|
||||
from test.support import warnings_helper
|
||||
from test import support
|
||||
from unittest import mock
|
||||
|
||||
|
@ -39,7 +42,7 @@ class BaseTests:
|
|||
# temp file's name.
|
||||
def writeTmp(self, content, *, mode='w'): # opening in text mode is the default
|
||||
fd, name = tempfile.mkstemp()
|
||||
self.addCleanup(support.unlink, name)
|
||||
self.addCleanup(os_helper.unlink, name)
|
||||
with open(fd, mode) as f:
|
||||
f.write(content)
|
||||
return name
|
||||
|
@ -234,9 +237,9 @@ class FileInputTests(BaseTests, unittest.TestCase):
|
|||
pass
|
||||
# try opening in universal newline mode
|
||||
t1 = self.writeTmp(b"A\nB\r\nC\rD", mode="wb")
|
||||
with check_warnings(('', DeprecationWarning)):
|
||||
with warnings_helper.check_warnings(('', DeprecationWarning)):
|
||||
fi = FileInput(files=t1, mode="U")
|
||||
with check_warnings(('', DeprecationWarning)):
|
||||
with warnings_helper.check_warnings(('', DeprecationWarning)):
|
||||
lines = list(fi)
|
||||
self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"])
|
||||
|
||||
|
@ -353,7 +356,7 @@ class FileInputTests(BaseTests, unittest.TestCase):
|
|||
with FileInput(files=[]) as fi:
|
||||
self.assertEqual(fi._files, ('-',))
|
||||
|
||||
@support.ignore_warnings(category=DeprecationWarning)
|
||||
@warnings_helper.ignore_warnings(category=DeprecationWarning)
|
||||
def test__getitem__(self):
|
||||
"""Tests invoking FileInput.__getitem__() with the current
|
||||
line number"""
|
||||
|
@ -371,7 +374,7 @@ class FileInputTests(BaseTests, unittest.TestCase):
|
|||
with FileInput(files=[t]) as fi:
|
||||
self.assertEqual(fi[0], "line1\n")
|
||||
|
||||
@support.ignore_warnings(category=DeprecationWarning)
|
||||
@warnings_helper.ignore_warnings(category=DeprecationWarning)
|
||||
def test__getitem__invalid_key(self):
|
||||
"""Tests invoking FileInput.__getitem__() with an index unequal to
|
||||
the line number"""
|
||||
|
@ -381,7 +384,7 @@ class FileInputTests(BaseTests, unittest.TestCase):
|
|||
fi[1]
|
||||
self.assertEqual(cm.exception.args, ("accessing lines out of order",))
|
||||
|
||||
@support.ignore_warnings(category=DeprecationWarning)
|
||||
@warnings_helper.ignore_warnings(category=DeprecationWarning)
|
||||
def test__getitem__eof(self):
|
||||
"""Tests invoking FileInput.__getitem__() with the line number but at
|
||||
end-of-input"""
|
||||
|
@ -400,7 +403,7 @@ class FileInputTests(BaseTests, unittest.TestCase):
|
|||
os_unlink_replacement = UnconditionallyRaise(OSError)
|
||||
try:
|
||||
t = self.writeTmp("\n")
|
||||
self.addCleanup(support.unlink, t + '.bak')
|
||||
self.addCleanup(safe_unlink, t + '.bak')
|
||||
with FileInput(files=[t], inplace=True) as fi:
|
||||
next(fi) # make sure the file is opened
|
||||
os.unlink = os_unlink_replacement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue