Skip to content

Commit 847f94f

Browse files
authored
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
1 parent 700cfa8 commit 847f94f

20 files changed

+69
-42
lines changed

Lib/distutils/tests/test_archive_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
ARCHIVE_FORMATS)
1414
from distutils.spawn import find_executable, spawn
1515
from distutils.tests import support
16-
from test.support import check_warnings, run_unittest, patch, change_cwd
16+
from test.support import run_unittest, patch
17+
from test.support.os_helper import change_cwd
18+
from test.support.warnings_helper import check_warnings
1719

1820
try:
1921
import grp

Lib/distutils/tests/test_bdist_msi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Tests for distutils.command.bdist_msi."""
22
import sys
33
import unittest
4-
from test.support import run_unittest, check_warnings
4+
from test.support import run_unittest
5+
from test.support.warnings_helper import check_warnings
56
from distutils.tests import support
67

78

Lib/distutils/tests/test_bdist_wininst.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import sys
33
import platform
44
import unittest
5-
from test.support import run_unittest, check_warnings
5+
from test.support import run_unittest
6+
from test.support.warnings_helper import check_warnings
67

78
from distutils.command.bdist_wininst import bdist_wininst
89
from distutils.tests import support

Lib/distutils/tests/test_core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import os
66
import shutil
77
import sys
8-
import test.support
98
from test.support import captured_stdout, run_unittest
9+
from test.support import os_helper
1010
import unittest
1111
from distutils.tests import support
1212
from distutils import log
@@ -62,13 +62,13 @@ def tearDown(self):
6262
super(CoreTestCase, self).tearDown()
6363

6464
def cleanup_testfn(self):
65-
path = test.support.TESTFN
65+
path = os_helper.TESTFN
6666
if os.path.isfile(path):
6767
os.remove(path)
6868
elif os.path.isdir(path):
6969
shutil.rmtree(path)
7070

71-
def write_setup(self, text, path=test.support.TESTFN):
71+
def write_setup(self, text, path=os_helper.TESTFN):
7272
f = open(path, "w")
7373
try:
7474
f.write(text)
@@ -105,8 +105,8 @@ def test_run_setup_uses_current_dir(self):
105105
cwd = os.getcwd()
106106

107107
# Create a directory and write the setup.py file there:
108-
os.mkdir(test.support.TESTFN)
109-
setup_py = os.path.join(test.support.TESTFN, "setup.py")
108+
os.mkdir(os_helper.TESTFN)
109+
setup_py = os.path.join(os_helper.TESTFN, "setup.py")
110110
distutils.core.run_setup(
111111
self.write_setup(setup_prints_cwd, path=setup_py))
112112

Lib/distutils/tests/test_dist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from distutils.cmd import Command
1313

1414
from test.support import (
15-
TESTFN, captured_stdout, captured_stderr, run_unittest
15+
captured_stdout, captured_stderr, run_unittest
1616
)
17+
from test.support.os_helper import TESTFN
1718
from distutils.tests import support
1819
from distutils import log
1920

Lib/distutils/tests/test_extension.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import warnings
55

6-
from test.support import check_warnings, run_unittest
6+
from test.support import run_unittest
7+
from test.support.warnings_helper import check_warnings
78
from distutils.extension import read_setup_file, Extension
89

910
class ExtensionTestCase(unittest.TestCase):

Lib/distutils/tests/test_file_util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from distutils import log
99
from distutils.tests import support
1010
from distutils.errors import DistutilsFileError
11-
from test.support import run_unittest, unlink
11+
from test.support import run_unittest
12+
from test.support.os_helper import unlink
13+
1214

1315
class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
1416

Lib/distutils/tests/test_filelist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from distutils import filelist
1010

1111
import test.support
12+
from test.support import os_helper
1213
from test.support import captured_stdout, run_unittest
1314
from distutils.tests import support
1415

@@ -295,7 +296,7 @@ def test_process_template(self):
295296

296297

297298
class FindAllTestCase(unittest.TestCase):
298-
@test.support.skip_unless_symlink
299+
@os_helper.skip_unless_symlink
299300
def test_missing_symlink(self):
300301
with test.support.temp_cwd():
301302
os.symlink('foo', 'bar')

Lib/distutils/tests/test_register.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import urllib
66
import warnings
77

8-
from test.support import check_warnings, run_unittest
8+
from test.support import run_unittest
9+
from test.support.warnings_helper import check_warnings
910

1011
from distutils.command import register as register_module
1112
from distutils.command.register import register

Lib/distutils/tests/test_sdist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import zipfile
77
from os.path import join
88
from textwrap import dedent
9-
from test.support import captured_stdout, check_warnings, run_unittest
9+
from test.support import captured_stdout, run_unittest
10+
from test.support.warnings_helper import check_warnings
1011

1112
try:
1213
import zlib

Lib/distutils/tests/test_sysconfig.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from distutils import sysconfig
1111
from distutils.ccompiler import get_default_compiler
1212
from distutils.tests import support
13-
from test.support import TESTFN, run_unittest, check_warnings, swap_item
13+
from test.support import run_unittest, swap_item
14+
from test.support.os_helper import TESTFN
15+
from test.support.warnings_helper import check_warnings
16+
1417

1518
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
1619
def setUp(self):

Lib/distutils/tests/test_unixccompiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Tests for distutils.unixccompiler."""
22
import sys
33
import unittest
4-
from test.support import EnvironmentVarGuard, run_unittest
4+
from test.support import run_unittest
5+
from test.support.os_helper import EnvironmentVarGuard
56

67
from distutils import sysconfig
78
from distutils.unixccompiler import UnixCCompiler

Lib/test/test_buffer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import contextlib
1717
import unittest
1818
from test import support
19+
from test.support import os_helper
1920
from itertools import permutations, product
2021
from random import randrange, sample, choice
2122
import warnings
@@ -39,7 +40,7 @@
3940
ctypes = None
4041

4142
try:
42-
with support.EnvironmentVarGuard() as os.environ, \
43+
with os_helper.EnvironmentVarGuard() as os.environ, \
4344
warnings.catch_warnings():
4445
from numpy import ndarray as numpy_array
4546
except ImportError:

Lib/test/test_compile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import tempfile
88
import types
99
from test import support
10-
from test.support import script_helper, FakePath
10+
from test.support import script_helper
11+
from test.support.os_helper import FakePath
12+
1113

1214
class TestSpecifics(unittest.TestCase):
1315

Lib/test/test_filecmp.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import unittest
66

77
from test import support
8+
from test.support import os_helper
89

910

1011
class FileCompareTestCase(unittest.TestCase):
1112
def setUp(self):
12-
self.name = support.TESTFN
13-
self.name_same = support.TESTFN + '-same'
14-
self.name_diff = support.TESTFN + '-diff'
13+
self.name = os_helper.TESTFN
14+
self.name_same = os_helper.TESTFN + '-same'
15+
self.name_diff = os_helper.TESTFN + '-diff'
1516
data = 'Contents of file go here.\n'
1617
for name in [self.name, self.name_same, self.name_diff]:
1718
with open(name, 'w') as output:

Lib/test/test_fileinput.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
from fileinput import FileInput, hook_encoded
2525
from pathlib import Path
2626

27-
from test.support import verbose, TESTFN, check_warnings
28-
from test.support import unlink as safe_unlink
27+
from test.support import verbose
28+
from test.support.os_helper import TESTFN
29+
from test.support.os_helper import unlink as safe_unlink
30+
from test.support import os_helper
31+
from test.support import warnings_helper
2932
from test import support
3033
from unittest import mock
3134

@@ -39,7 +42,7 @@ class BaseTests:
3942
# temp file's name.
4043
def writeTmp(self, content, *, mode='w'): # opening in text mode is the default
4144
fd, name = tempfile.mkstemp()
42-
self.addCleanup(support.unlink, name)
45+
self.addCleanup(os_helper.unlink, name)
4346
with open(fd, mode) as f:
4447
f.write(content)
4548
return name
@@ -234,9 +237,9 @@ def test_opening_mode(self):
234237
pass
235238
# try opening in universal newline mode
236239
t1 = self.writeTmp(b"A\nB\r\nC\rD", mode="wb")
237-
with check_warnings(('', DeprecationWarning)):
240+
with warnings_helper.check_warnings(('', DeprecationWarning)):
238241
fi = FileInput(files=t1, mode="U")
239-
with check_warnings(('', DeprecationWarning)):
242+
with warnings_helper.check_warnings(('', DeprecationWarning)):
240243
lines = list(fi)
241244
self.assertEqual(lines, ["A\n", "B\n", "C\n", "D"])
242245

@@ -353,7 +356,7 @@ def test_empty_files_list_specified_to_constructor(self):
353356
with FileInput(files=[]) as fi:
354357
self.assertEqual(fi._files, ('-',))
355358

356-
@support.ignore_warnings(category=DeprecationWarning)
359+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
357360
def test__getitem__(self):
358361
"""Tests invoking FileInput.__getitem__() with the current
359362
line number"""
@@ -371,7 +374,7 @@ def test__getitem___deprecation(self):
371374
with FileInput(files=[t]) as fi:
372375
self.assertEqual(fi[0], "line1\n")
373376

374-
@support.ignore_warnings(category=DeprecationWarning)
377+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
375378
def test__getitem__invalid_key(self):
376379
"""Tests invoking FileInput.__getitem__() with an index unequal to
377380
the line number"""
@@ -381,7 +384,7 @@ def test__getitem__invalid_key(self):
381384
fi[1]
382385
self.assertEqual(cm.exception.args, ("accessing lines out of order",))
383386

384-
@support.ignore_warnings(category=DeprecationWarning)
387+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
385388
def test__getitem__eof(self):
386389
"""Tests invoking FileInput.__getitem__() with the line number but at
387390
end-of-input"""
@@ -400,7 +403,7 @@ def test_nextfile_oserror_deleting_backup(self):
400403
os_unlink_replacement = UnconditionallyRaise(OSError)
401404
try:
402405
t = self.writeTmp("\n")
403-
self.addCleanup(support.unlink, t + '.bak')
406+
self.addCleanup(safe_unlink, t + '.bak')
404407
with FileInput(files=[t], inplace=True) as fi:
405408
next(fi) # make sure the file is opened
406409
os.unlink = os_unlink_replacement

Lib/test/test_readline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import sys
1111
import tempfile
1212
import unittest
13-
from test.support import import_module, unlink, temp_dir, TESTFN, verbose
13+
from test.support import verbose
14+
from test.support.import_helper import import_module
15+
from test.support.os_helper import unlink, temp_dir, TESTFN
1416
from test.support.script_helper import assert_python_ok
1517

1618
# Skip tests if there is no readline module

Lib/test/test_smtpnet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import unittest
22
from test import support
3+
from test.support import import_helper
34
from test.support import socket_helper
45
import smtplib
56
import socket
67

7-
ssl = support.import_module("ssl")
8+
ssl = import_helper.import_module("ssl")
89

910
support.requires("network")
1011

Lib/test/test_structmembers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import unittest
2-
from test import support
2+
from test.support import import_helper
3+
from test.support import warnings_helper
34

45
# Skip this test if the _testcapi module isn't available.
5-
support.import_module('_testcapi')
6+
import_helper.import_module('_testcapi')
67
from _testcapi import _test_structmembersType, \
78
CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
89
SHRT_MAX, SHRT_MIN, USHRT_MAX, \
@@ -116,27 +117,27 @@ def test_inplace_string(self):
116117
class TestWarnings(unittest.TestCase):
117118

118119
def test_byte_max(self):
119-
with support.check_warnings(('', RuntimeWarning)):
120+
with warnings_helper.check_warnings(('', RuntimeWarning)):
120121
ts.T_BYTE = CHAR_MAX+1
121122

122123
def test_byte_min(self):
123-
with support.check_warnings(('', RuntimeWarning)):
124+
with warnings_helper.check_warnings(('', RuntimeWarning)):
124125
ts.T_BYTE = CHAR_MIN-1
125126

126127
def test_ubyte_max(self):
127-
with support.check_warnings(('', RuntimeWarning)):
128+
with warnings_helper.check_warnings(('', RuntimeWarning)):
128129
ts.T_UBYTE = UCHAR_MAX+1
129130

130131
def test_short_max(self):
131-
with support.check_warnings(('', RuntimeWarning)):
132+
with warnings_helper.check_warnings(('', RuntimeWarning)):
132133
ts.T_SHORT = SHRT_MAX+1
133134

134135
def test_short_min(self):
135-
with support.check_warnings(('', RuntimeWarning)):
136+
with warnings_helper.check_warnings(('', RuntimeWarning)):
136137
ts.T_SHORT = SHRT_MIN-1
137138

138139
def test_ushort_max(self):
139-
with support.check_warnings(('', RuntimeWarning)):
140+
with warnings_helper.check_warnings(('', RuntimeWarning)):
140141
ts.T_USHORT = USHRT_MAX+1
141142

142143

Lib/test/test_tools/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os.path
55
import unittest
66
from test import support
7+
from test.support import import_helper
78

89
basepath = os.path.normpath(
910
os.path.dirname( # <src/install dir>
@@ -26,11 +27,11 @@ def skip_if_missing(tool=None):
2627
@contextlib.contextmanager
2728
def imports_under_tool(name, *subdirs):
2829
tooldir = os.path.join(toolsdir, name, *subdirs)
29-
with support.DirsOnSysPath(tooldir) as cm:
30+
with import_helper.DirsOnSysPath(tooldir) as cm:
3031
yield cm
3132

3233
def import_tool(toolname):
33-
with support.DirsOnSysPath(scriptsdir):
34+
with import_helper.DirsOnSysPath(scriptsdir):
3435
return importlib.import_module(toolname)
3536

3637
def load_tests(*args):

0 commit comments

Comments
 (0)