mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-40275: Use new test.support helper submodules in tests (GH-21317)
This commit is contained in:
parent
b4a9263708
commit
deb016224c
18 changed files with 128 additions and 110 deletions
|
@ -6,7 +6,7 @@ import tempfile
|
|||
import unittest
|
||||
import sysconfig
|
||||
from copy import deepcopy
|
||||
import test.support
|
||||
from test.support import os_helper
|
||||
|
||||
from distutils import log
|
||||
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
|
||||
|
@ -64,7 +64,7 @@ class TempdirManager(object):
|
|||
super().tearDown()
|
||||
while self.tempdirs:
|
||||
tmpdir = self.tempdirs.pop()
|
||||
test.support.rmtree(tmpdir)
|
||||
os_helper.rmtree(tmpdir)
|
||||
|
||||
def mkdtemp(self):
|
||||
"""Create a temporary directory that will be cleaned up.
|
||||
|
|
|
@ -15,6 +15,7 @@ from distutils.errors import (
|
|||
|
||||
import unittest
|
||||
from test import support
|
||||
from test.support import os_helper
|
||||
from test.support.script_helper import assert_python_ok
|
||||
|
||||
# http://bugs.python.org/issue4373
|
||||
|
@ -38,7 +39,7 @@ class BuildExtTestCase(TempdirManager,
|
|||
# bpo-30132: On Windows, a .pdb file may be created in the current
|
||||
# working directory. Create a temporary working directory to cleanup
|
||||
# everything at the end of the test.
|
||||
change_cwd = support.change_cwd(self.tmp_dir)
|
||||
change_cwd = os_helper.change_cwd(self.tmp_dir)
|
||||
change_cwd.__enter__()
|
||||
self.addCleanup(change_cwd.__exit__, None, None, None)
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ from distutils.errors import DistutilsTemplateError
|
|||
from distutils.filelist import glob_to_re, translate_pattern, FileList
|
||||
from distutils import filelist
|
||||
|
||||
import test.support
|
||||
from test.support import os_helper
|
||||
from test.support import captured_stdout, run_unittest
|
||||
from distutils.tests import support
|
||||
|
@ -298,7 +297,7 @@ class FileListTestCase(support.LoggingSilencer,
|
|||
class FindAllTestCase(unittest.TestCase):
|
||||
@os_helper.skip_unless_symlink
|
||||
def test_missing_symlink(self):
|
||||
with test.support.temp_cwd():
|
||||
with os_helper.temp_cwd():
|
||||
os.symlink('foo', 'bar')
|
||||
self.assertEqual(filelist.findall(), [])
|
||||
|
||||
|
@ -308,13 +307,13 @@ class FindAllTestCase(unittest.TestCase):
|
|||
'.' as the parameter, the dot should be omitted from
|
||||
the results.
|
||||
"""
|
||||
with test.support.temp_cwd():
|
||||
with os_helper.temp_cwd():
|
||||
os.mkdir('foo')
|
||||
file1 = os.path.join('foo', 'file1.txt')
|
||||
test.support.create_empty_file(file1)
|
||||
os_helper.create_empty_file(file1)
|
||||
os.mkdir('bar')
|
||||
file2 = os.path.join('bar', 'file2.txt')
|
||||
test.support.create_empty_file(file2)
|
||||
os_helper.create_empty_file(file2)
|
||||
expected = [file2, file1]
|
||||
self.assertEqual(sorted(filelist.findall()), expected)
|
||||
|
||||
|
@ -323,9 +322,9 @@ class FindAllTestCase(unittest.TestCase):
|
|||
When findall is called with another path, the full
|
||||
path name should be returned.
|
||||
"""
|
||||
with test.support.temp_dir() as temp_dir:
|
||||
with os_helper.temp_dir() as temp_dir:
|
||||
file1 = os.path.join(temp_dir, 'file1.txt')
|
||||
test.support.create_empty_file(file1)
|
||||
os_helper.create_empty_file(file1)
|
||||
expected = [file1]
|
||||
self.assertEqual(filelist.findall(temp_dir), expected)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import stat
|
|||
import sys
|
||||
import unittest.mock
|
||||
from test.support import run_unittest, unix_shell
|
||||
from test import support as test_support
|
||||
from test.support import os_helper
|
||||
|
||||
from distutils.spawn import find_executable
|
||||
from distutils.spawn import spawn
|
||||
|
@ -44,9 +44,9 @@ class SpawnTestCase(support.TempdirManager,
|
|||
spawn([exe]) # should work without any error
|
||||
|
||||
def test_find_executable(self):
|
||||
with test_support.temp_dir() as tmp_dir:
|
||||
with os_helper.temp_dir() as tmp_dir:
|
||||
# use TESTFN to get a pseudo-unique filename
|
||||
program_noeext = test_support.TESTFN
|
||||
program_noeext = os_helper.TESTFN
|
||||
# Give the temporary program an ".exe" suffix for all.
|
||||
# It's needed on Windows and not harmful on other platforms.
|
||||
program = program_noeext + ".exe"
|
||||
|
@ -66,7 +66,7 @@ class SpawnTestCase(support.TempdirManager,
|
|||
self.assertEqual(rv, filename)
|
||||
|
||||
# test find in the current directory
|
||||
with test_support.change_cwd(tmp_dir):
|
||||
with os_helper.change_cwd(tmp_dir):
|
||||
rv = find_executable(program)
|
||||
self.assertEqual(rv, program)
|
||||
|
||||
|
@ -76,7 +76,7 @@ class SpawnTestCase(support.TempdirManager,
|
|||
self.assertIsNone(rv)
|
||||
|
||||
# PATH='': no match, except in the current directory
|
||||
with test_support.EnvironmentVarGuard() as env:
|
||||
with os_helper.EnvironmentVarGuard() as env:
|
||||
env['PATH'] = ''
|
||||
with unittest.mock.patch('distutils.spawn.os.confstr',
|
||||
return_value=tmp_dir, create=True), \
|
||||
|
@ -86,12 +86,12 @@ class SpawnTestCase(support.TempdirManager,
|
|||
self.assertIsNone(rv)
|
||||
|
||||
# look in current directory
|
||||
with test_support.change_cwd(tmp_dir):
|
||||
with os_helper.change_cwd(tmp_dir):
|
||||
rv = find_executable(program)
|
||||
self.assertEqual(rv, program)
|
||||
|
||||
# PATH=':': explicitly looks in the current directory
|
||||
with test_support.EnvironmentVarGuard() as env:
|
||||
with os_helper.EnvironmentVarGuard() as env:
|
||||
env['PATH'] = os.pathsep
|
||||
with unittest.mock.patch('distutils.spawn.os.confstr',
|
||||
return_value='', create=True), \
|
||||
|
@ -100,12 +100,12 @@ class SpawnTestCase(support.TempdirManager,
|
|||
self.assertIsNone(rv)
|
||||
|
||||
# look in current directory
|
||||
with test_support.change_cwd(tmp_dir):
|
||||
with os_helper.change_cwd(tmp_dir):
|
||||
rv = find_executable(program)
|
||||
self.assertEqual(rv, program)
|
||||
|
||||
# missing PATH: test os.confstr("CS_PATH") and os.defpath
|
||||
with test_support.EnvironmentVarGuard() as env:
|
||||
with os_helper.EnvironmentVarGuard() as env:
|
||||
env.pop('PATH', None)
|
||||
|
||||
# without confstr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue