Skip to content

Commit c6fff69

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21317)
1 parent 71d869a commit c6fff69

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

tests/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import unittest
77
import sysconfig
88
from copy import deepcopy
9-
import test.support
9+
from test.support import os_helper
1010

1111
from distutils import log
1212
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
@@ -64,7 +64,7 @@ def tearDown(self):
6464
super().tearDown()
6565
while self.tempdirs:
6666
tmpdir = self.tempdirs.pop()
67-
test.support.rmtree(tmpdir)
67+
os_helper.rmtree(tmpdir)
6868

6969
def mkdtemp(self):
7070
"""Create a temporary directory that will be cleaned up.

tests/test_build_ext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import unittest
1717
from test import support
18+
from test.support import os_helper
1819
from test.support.script_helper import assert_python_ok
1920

2021
# http://bugs.python.org/issue4373
@@ -38,7 +39,7 @@ def setUp(self):
3839
# bpo-30132: On Windows, a .pdb file may be created in the current
3940
# working directory. Create a temporary working directory to cleanup
4041
# everything at the end of the test.
41-
change_cwd = support.change_cwd(self.tmp_dir)
42+
change_cwd = os_helper.change_cwd(self.tmp_dir)
4243
change_cwd.__enter__()
4344
self.addCleanup(change_cwd.__exit__, None, None, None)
4445

tests/test_filelist.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from distutils.filelist import glob_to_re, translate_pattern, FileList
99
from distutils import filelist
1010

11-
import test.support
1211
from test.support import os_helper
1312
from test.support import captured_stdout, run_unittest
1413
from distutils.tests import support
@@ -298,7 +297,7 @@ def test_process_template(self):
298297
class FindAllTestCase(unittest.TestCase):
299298
@os_helper.skip_unless_symlink
300299
def test_missing_symlink(self):
301-
with test.support.temp_cwd():
300+
with os_helper.temp_cwd():
302301
os.symlink('foo', 'bar')
303302
self.assertEqual(filelist.findall(), [])
304303

@@ -308,13 +307,13 @@ def test_basic_discovery(self):
308307
'.' as the parameter, the dot should be omitted from
309308
the results.
310309
"""
311-
with test.support.temp_cwd():
310+
with os_helper.temp_cwd():
312311
os.mkdir('foo')
313312
file1 = os.path.join('foo', 'file1.txt')
314-
test.support.create_empty_file(file1)
313+
os_helper.create_empty_file(file1)
315314
os.mkdir('bar')
316315
file2 = os.path.join('bar', 'file2.txt')
317-
test.support.create_empty_file(file2)
316+
os_helper.create_empty_file(file2)
318317
expected = [file2, file1]
319318
self.assertEqual(sorted(filelist.findall()), expected)
320319

@@ -323,9 +322,9 @@ def test_non_local_discovery(self):
323322
When findall is called with another path, the full
324323
path name should be returned.
325324
"""
326-
with test.support.temp_dir() as temp_dir:
325+
with os_helper.temp_dir() as temp_dir:
327326
file1 = os.path.join(temp_dir, 'file1.txt')
328-
test.support.create_empty_file(file1)
327+
os_helper.create_empty_file(file1)
329328
expected = [file1]
330329
self.assertEqual(filelist.findall(temp_dir), expected)
331330

tests/test_spawn.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import unittest.mock
66
from test.support import run_unittest, unix_shell
7-
from test import support as test_support
7+
from test.support import os_helper
88

99
from distutils.spawn import find_executable
1010
from distutils.spawn import spawn
@@ -44,9 +44,9 @@ def test_spawn(self):
4444
spawn([exe]) # should work without any error
4545

4646
def test_find_executable(self):
47-
with test_support.temp_dir() as tmp_dir:
47+
with os_helper.temp_dir() as tmp_dir:
4848
# use TESTFN to get a pseudo-unique filename
49-
program_noeext = test_support.TESTFN
49+
program_noeext = os_helper.TESTFN
5050
# Give the temporary program an ".exe" suffix for all.
5151
# It's needed on Windows and not harmful on other platforms.
5252
program = program_noeext + ".exe"
@@ -66,7 +66,7 @@ def test_find_executable(self):
6666
self.assertEqual(rv, filename)
6767

6868
# test find in the current directory
69-
with test_support.change_cwd(tmp_dir):
69+
with os_helper.change_cwd(tmp_dir):
7070
rv = find_executable(program)
7171
self.assertEqual(rv, program)
7272

@@ -76,7 +76,7 @@ def test_find_executable(self):
7676
self.assertIsNone(rv)
7777

7878
# PATH='': no match, except in the current directory
79-
with test_support.EnvironmentVarGuard() as env:
79+
with os_helper.EnvironmentVarGuard() as env:
8080
env['PATH'] = ''
8181
with unittest.mock.patch('distutils.spawn.os.confstr',
8282
return_value=tmp_dir, create=True), \
@@ -86,12 +86,12 @@ def test_find_executable(self):
8686
self.assertIsNone(rv)
8787

8888
# look in current directory
89-
with test_support.change_cwd(tmp_dir):
89+
with os_helper.change_cwd(tmp_dir):
9090
rv = find_executable(program)
9191
self.assertEqual(rv, program)
9292

9393
# PATH=':': explicitly looks in the current directory
94-
with test_support.EnvironmentVarGuard() as env:
94+
with os_helper.EnvironmentVarGuard() as env:
9595
env['PATH'] = os.pathsep
9696
with unittest.mock.patch('distutils.spawn.os.confstr',
9797
return_value='', create=True), \
@@ -100,12 +100,12 @@ def test_find_executable(self):
100100
self.assertIsNone(rv)
101101

102102
# look in current directory
103-
with test_support.change_cwd(tmp_dir):
103+
with os_helper.change_cwd(tmp_dir):
104104
rv = find_executable(program)
105105
self.assertEqual(rv, program)
106106

107107
# missing PATH: test os.confstr("CS_PATH") and os.defpath
108-
with test_support.EnvironmentVarGuard() as env:
108+
with os_helper.EnvironmentVarGuard() as env:
109109
env.pop('PATH', None)
110110

111111
# without confstr

0 commit comments

Comments
 (0)