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
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index 014f19e..d5edf74 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -24,8 +24,11 @@
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 @@
# 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 @@
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 @@
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 @@
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 @@
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 @@
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