Skip to content

Commit

Permalink
bpo-40275: Use new test.support helper submodules in tests (GH-21317)
Browse files Browse the repository at this point in the history
  • Loading branch information
shihai1991 authored Jul 6, 2020
1 parent 71d869a commit c6fff69
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand Down Expand Up @@ -64,7 +64,7 @@ def tearDown(self):
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.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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
Expand All @@ -38,7 +39,7 @@ def setUp(self):
# 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)

Expand Down
13 changes: 6 additions & 7 deletions tests/test_filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
Expand Down Expand Up @@ -298,7 +297,7 @@ def test_process_template(self):
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(), [])

Expand All @@ -308,13 +307,13 @@ def test_basic_discovery(self):
'.' 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)

Expand All @@ -323,9 +322,9 @@ def test_non_local_discovery(self):
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)

Expand Down
18 changes: 9 additions & 9 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -44,9 +44,9 @@ def test_spawn(self):
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"
Expand All @@ -66,7 +66,7 @@ def test_find_executable(self):
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)

Expand All @@ -76,7 +76,7 @@ def test_find_executable(self):
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), \
Expand All @@ -86,12 +86,12 @@ def test_find_executable(self):
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), \
Expand All @@ -100,12 +100,12 @@ def test_find_executable(self):
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
Expand Down

0 comments on commit c6fff69

Please sign in to comment.