summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2020-06-25 17:17:57 (GMT)
committerGitHub <noreply@github.com>2020-06-25 17:17:57 (GMT)
commit847f94f47b104aec678d1d2a2d8fe23d817f375e (patch)
tree3b247098fefe734937e9ed4e5a7388ab4da5c284 /Lib/test
parent700cfa8c90a90016638bac13c4efd03786b2b2a0 (diff)
downloadcpython-847f94f47b104aec678d1d2a2d8fe23d817f375e.zip
cpython-847f94f47b104aec678d1d2a2d8fe23d817f375e.tar.gz
cpython-847f94f47b104aec678d1d2a2d8fe23d817f375e.tar.bz2
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
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_buffer.py3
-rw-r--r--Lib/test/test_compile.py4
-rw-r--r--Lib/test/test_filecmp.py7
-rw-r--r--Lib/test/test_fileinput.py21
-rw-r--r--Lib/test/test_readline.py4
-rw-r--r--Lib/test/test_smtpnet.py3
-rw-r--r--Lib/test/test_structmembers.py17
-rw-r--r--Lib/test/test_tools/__init__.py5
8 files changed, 38 insertions, 26 deletions
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
index d440bcf..468c6ea 100644
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -16,6 +16,7 @@
import contextlib
import unittest
from test import support
+from test.support import os_helper
from itertools import permutations, product
from random import randrange, sample, choice
import warnings
@@ -39,7 +40,7 @@ except ImportError:
ctypes = None
try:
- with support.EnvironmentVarGuard() as os.environ, \
+ with os_helper.EnvironmentVarGuard() as os.environ, \
warnings.catch_warnings():
from numpy import ndarray as numpy_array
except ImportError:
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 566ca27..3dd8c8d 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -7,7 +7,9 @@ import _ast
import tempfile
import types
from test import support
-from test.support import script_helper, FakePath
+from test.support import script_helper
+from test.support.os_helper import FakePath
+
class TestSpecifics(unittest.TestCase):
diff --git a/Lib/test/test_filecmp.py b/Lib/test/test_filecmp.py
index b5b24a2..ca9b4f3 100644
--- a/Lib/test/test_filecmp.py
+++ b/Lib/test/test_filecmp.py
@@ -5,13 +5,14 @@ import tempfile
import unittest
from test import support
+from test.support import os_helper
class FileCompareTestCase(unittest.TestCase):
def setUp(self):
- self.name = support.TESTFN
- self.name_same = support.TESTFN + '-same'
- self.name_diff = support.TESTFN + '-diff'
+ self.name = os_helper.TESTFN
+ self.name_same = os_helper.TESTFN + '-same'
+ self.name_diff = os_helper.TESTFN + '-diff'
data = 'Contents of file go here.\n'
for name in [self.name, self.name_same, self.name_diff]:
with open(name, 'w') as output:
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 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
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py
index 67ee9b7..de573be 100644
--- a/Lib/test/test_readline.py
+++ b/Lib/test/test_readline.py
@@ -10,7 +10,9 @@ import subprocess
import sys
import tempfile
import unittest
-from test.support import import_module, unlink, temp_dir, TESTFN, verbose
+from test.support import verbose
+from test.support.import_helper import import_module
+from test.support.os_helper import unlink, temp_dir, TESTFN
from test.support.script_helper import assert_python_ok
# Skip tests if there is no readline module
diff --git a/Lib/test/test_smtpnet.py b/Lib/test/test_smtpnet.py
index 74a00a9..72f51cd 100644
--- a/Lib/test/test_smtpnet.py
+++ b/Lib/test/test_smtpnet.py
@@ -1,10 +1,11 @@
import unittest
from test import support
+from test.support import import_helper
from test.support import socket_helper
import smtplib
import socket
-ssl = support.import_module("ssl")
+ssl = import_helper.import_module("ssl")
support.requires("network")
diff --git a/Lib/test/test_structmembers.py b/Lib/test/test_structmembers.py
index 57ec45f..07d2f62 100644
--- a/Lib/test/test_structmembers.py
+++ b/Lib/test/test_structmembers.py
@@ -1,8 +1,9 @@
import unittest
-from test import support
+from test.support import import_helper
+from test.support import warnings_helper
# Skip this test if the _testcapi module isn't available.
-support.import_module('_testcapi')
+import_helper.import_module('_testcapi')
from _testcapi import _test_structmembersType, \
CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
SHRT_MAX, SHRT_MIN, USHRT_MAX, \
@@ -116,27 +117,27 @@ class ReadWriteTests(unittest.TestCase):
class TestWarnings(unittest.TestCase):
def test_byte_max(self):
- with support.check_warnings(('', RuntimeWarning)):
+ with warnings_helper.check_warnings(('', RuntimeWarning)):
ts.T_BYTE = CHAR_MAX+1
def test_byte_min(self):
- with support.check_warnings(('', RuntimeWarning)):
+ with warnings_helper.check_warnings(('', RuntimeWarning)):
ts.T_BYTE = CHAR_MIN-1
def test_ubyte_max(self):
- with support.check_warnings(('', RuntimeWarning)):
+ with warnings_helper.check_warnings(('', RuntimeWarning)):
ts.T_UBYTE = UCHAR_MAX+1
def test_short_max(self):
- with support.check_warnings(('', RuntimeWarning)):
+ with warnings_helper.check_warnings(('', RuntimeWarning)):
ts.T_SHORT = SHRT_MAX+1
def test_short_min(self):
- with support.check_warnings(('', RuntimeWarning)):
+ with warnings_helper.check_warnings(('', RuntimeWarning)):
ts.T_SHORT = SHRT_MIN-1
def test_ushort_max(self):
- with support.check_warnings(('', RuntimeWarning)):
+ with warnings_helper.check_warnings(('', RuntimeWarning)):
ts.T_USHORT = USHRT_MAX+1
diff --git a/Lib/test/test_tools/__init__.py b/Lib/test/test_tools/__init__.py
index eb9acad..61af657 100644
--- a/Lib/test/test_tools/__init__.py
+++ b/Lib/test/test_tools/__init__.py
@@ -4,6 +4,7 @@ import importlib
import os.path
import unittest
from test import support
+from test.support import import_helper
basepath = os.path.normpath(
os.path.dirname( # <src/install dir>
@@ -26,11 +27,11 @@ def skip_if_missing(tool=None):
@contextlib.contextmanager
def imports_under_tool(name, *subdirs):
tooldir = os.path.join(toolsdir, name, *subdirs)
- with support.DirsOnSysPath(tooldir) as cm:
+ with import_helper.DirsOnSysPath(tooldir) as cm:
yield cm
def import_tool(toolname):
- with support.DirsOnSysPath(scriptsdir):
+ with import_helper.DirsOnSysPath(scriptsdir):
return importlib.import_module(toolname)
def load_tests(*args):