Commit 461c8f48 authored by Jason R. Coombs's avatar Jason R. Coombs

Merge commit 'bbe8e80b' of...

Merge commit 'bbe8e80b' of https://github.com/pypa/distutils into refresh-distutils
parents aff64ae8 bbe8e80b
......@@ -5,7 +5,7 @@ Implements the Distutils 'build_py' command."""
import os
import importlib.util
import sys
from glob import glob
import glob
from distutils.core import Command
from distutils.errors import *
......@@ -125,7 +125,7 @@ class build_py (Command):
files = []
for pattern in globs:
# Each pattern has to be converted to a platform-specific path
filelist = glob(os.path.join(src_dir, convert_path(pattern)))
filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
# Files that match more than one pattern are only added once
files.extend([fn for fn in filelist if fn not in files
and os.path.isfile(fn)])
......@@ -216,7 +216,7 @@ class build_py (Command):
def find_package_modules(self, package, package_dir):
self.check_package(package, package_dir)
module_files = glob(os.path.join(package_dir, "*.py"))
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
modules = []
setup_script = os.path.abspath(self.distribution.script_name)
......
......@@ -15,26 +15,26 @@ by import rather than matching pre-defined names.
import os
import sys
import unittest
import warnings
from test.support import run_unittest
from .py38compat import save_restore_warnings_filters
here = os.path.dirname(__file__) or os.curdir
def test_suite():
old_filters = warnings.filters[:]
suite = unittest.TestSuite()
for fn in os.listdir(here):
if fn.startswith("test") and fn.endswith(".py"):
modname = "distutils.tests." + fn[:-3]
__import__(modname)
# bpo-40055: Save/restore warnings filters to leave them unchanged.
# Importing tests imports docutils which imports pkg_resources
# which adds a warnings filter.
with save_restore_warnings_filters():
__import__(modname)
module = sys.modules[modname]
suite.addTest(module.test_suite())
# bpo-40055: Save/restore warnings filters to leave them unchanged.
# Importing tests imports docutils which imports pkg_resources which adds a
# warnings filter.
warnings.filters[:] = old_filters
return suite
......
# flake8: noqa
import contextlib
try:
from test.support.warnings_helper import check_warnings
except (ModuleNotFoundError, ImportError):
from test.support import check_warnings
try:
from test.support.os_helper import (
change_cwd,
rmtree,
EnvironmentVarGuard,
TESTFN,
unlink,
skip_unless_symlink,
temp_dir,
create_empty_file,
temp_cwd,
)
except (ModuleNotFoundError, ImportError):
from test.support import (
change_cwd,
rmtree,
EnvironmentVarGuard,
TESTFN,
unlink,
skip_unless_symlink,
temp_dir,
create_empty_file,
temp_cwd,
)
# From Python 3.9
@contextlib.contextmanager
def _save_restore_warnings_filters():
old_filters = warnings.filters[:]
try:
yield
finally:
warnings.filters[:] = old_filters
try:
from test.support.warnings_helper import save_restore_warnings_filters
except (ModuleNotFoundError, ImportError):
save_restore_warnings_filters = _save_restore_warnings_filters
......@@ -6,7 +6,8 @@ import tempfile
import unittest
import sysconfig
from copy import deepcopy
import test.support
from . import py38compat as os_helper
from distutils import log
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
......@@ -64,7 +65,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.
......
......@@ -13,7 +13,10 @@ from distutils.archive_util import (check_archive_formats, make_tarball,
ARCHIVE_FORMATS)
from distutils.spawn import find_executable, spawn
from distutils.tests import support
from test.support import check_warnings, run_unittest, patch, change_cwd
from test.support import run_unittest, patch
from .py38compat import change_cwd
from .py38compat import check_warnings
try:
import grp
......
"""Tests for distutils.command.bdist_msi."""
import sys
import unittest
from test.support import run_unittest, check_warnings
from test.support import run_unittest
from distutils.tests import support
from .py38compat import check_warnings
@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
class BDistMSITestCase(support.TempdirManager,
......
......@@ -2,7 +2,9 @@
import sys
import platform
import unittest
from test.support import run_unittest, check_warnings
from test.support import run_unittest
from .py38compat import check_warnings
from distutils.command.bdist_wininst import bdist_wininst
from distutils.tests import support
......
......@@ -15,6 +15,7 @@ from distutils.errors import (
import unittest
from test import support
from . import py38compat as 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)
......
......@@ -5,8 +5,8 @@ import distutils.core
import os
import shutil
import sys
import test.support
from test.support import captured_stdout, run_unittest
from . import py38compat as os_helper
import unittest
from distutils.tests import support
from distutils import log
......@@ -62,13 +62,13 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
super(CoreTestCase, self).tearDown()
def cleanup_testfn(self):
path = test.support.TESTFN
path = os_helper.TESTFN
if os.path.isfile(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)
def write_setup(self, text, path=test.support.TESTFN):
def write_setup(self, text, path=os_helper.TESTFN):
f = open(path, "w")
try:
f.write(text)
......@@ -105,8 +105,8 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
cwd = os.getcwd()
# Create a directory and write the setup.py file there:
os.mkdir(test.support.TESTFN)
setup_py = os.path.join(test.support.TESTFN, "setup.py")
os.mkdir(os_helper.TESTFN)
setup_py = os.path.join(os_helper.TESTFN, "setup.py")
distutils.core.run_setup(
self.write_setup(setup_prints_cwd, path=setup_py))
......
......@@ -12,8 +12,9 @@ from distutils.dist import Distribution, fix_help_options
from distutils.cmd import Command
from test.support import (
TESTFN, captured_stdout, captured_stderr, run_unittest
captured_stdout, captured_stderr, run_unittest
)
from .py38compat import TESTFN
from distutils.tests import support
from distutils import log
......
......@@ -3,9 +3,11 @@ import unittest
import os
import warnings
from test.support import check_warnings, run_unittest
from test.support import run_unittest
from distutils.extension import read_setup_file, Extension
from .py38compat import check_warnings
class ExtensionTestCase(unittest.TestCase):
def test_read_setup_file(self):
......
......@@ -8,7 +8,9 @@ from distutils.file_util import move_file, copy_file
from distutils import log
from distutils.tests import support
from distutils.errors import DistutilsFileError
from test.support import run_unittest, unlink
from test.support import run_unittest
from .py38compat import unlink
class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
......
......@@ -8,11 +8,11 @@ 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 captured_stdout, run_unittest
from distutils.tests import support
from .py35compat import adapt_glob
from . import py38compat as os_helper
MANIFEST_IN = """\
......@@ -298,9 +298,9 @@ class FileListTestCase(support.LoggingSilencer,
class FindAllTestCase(unittest.TestCase):
@test.support.skip_unless_symlink
@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(), [])
......@@ -310,13 +310,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)
......@@ -325,9 +325,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)
......
......@@ -5,7 +5,9 @@ import getpass
import urllib
import warnings
from test.support import check_warnings, run_unittest
from test.support import run_unittest
from .py38compat import check_warnings
from distutils.command import register as register_module
from distutils.command.register import register
......
......@@ -6,7 +6,9 @@ import warnings
import zipfile
from os.path import join
from textwrap import dedent
from test.support import captured_stdout, check_warnings, run_unittest
from test.support import captured_stdout, run_unittest
from .py38compat import check_warnings
try:
import zlib
......
......@@ -4,9 +4,9 @@ import stat
import sys
import unittest.mock
from test.support import run_unittest
from test import support as test_support
from .py35compat import unix_shell
from . import py38compat as os_helper
from distutils.spawn import find_executable
from distutils.spawn import spawn
......@@ -46,9 +46,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"
......@@ -68,7 +68,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)
......@@ -78,7 +78,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), \
......@@ -88,12 +88,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), \
......@@ -102,12 +102,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
......@@ -129,7 +129,7 @@ class SpawnTestCase(support.TempdirManager,
def test_spawn_missing_exe(self):
with self.assertRaises(DistutilsExecError) as ctx:
spawn(['does-not-exist'])
assert 'command does-no-exist failed' in str(ctx)
self.assertIn("command 'does-not-exist' failed", str(ctx.exception))
def test_suite():
......
......@@ -10,7 +10,11 @@ import unittest
from distutils import sysconfig
from distutils.ccompiler import get_default_compiler
from distutils.tests import support
from test.support import TESTFN, run_unittest, check_warnings, swap_item
from test.support import run_unittest, swap_item
from .py38compat import TESTFN
from .py38compat import check_warnings
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
def setUp(self):
......
"""Tests for distutils.unixccompiler."""
import sys
import unittest
from test.support import EnvironmentVarGuard, run_unittest
from test.support import run_unittest
from .py38compat import EnvironmentVarGuard
from distutils import sysconfig
from distutils.unixccompiler import UnixCCompiler
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment