Skip to content

Commit

Permalink
Merge branch 'cpython'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 8, 2020
2 parents a21ea47 + e34d6d8 commit bbe8e80
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 45 deletions.
6 changes: 3 additions & 3 deletions distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import importlib.util
import sys
from glob import glob
import glob

from distutils.core import Command
from distutils.errors import *
Expand Down Expand Up @@ -125,7 +125,7 @@ def find_data_files(self, package, src_dir):
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)])
Expand Down Expand Up @@ -216,7 +216,7 @@ def check_module(self, module, module_file):

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)

Expand Down
14 changes: 7 additions & 7 deletions distutils/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
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


Expand Down
50 changes: 50 additions & 0 deletions distutils/tests/py38compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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
5 changes: 3 additions & 2 deletions distutils/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
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
Expand Down Expand Up @@ -64,7 +65,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
5 changes: 4 additions & 1 deletion distutils/tests/test_archive_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
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
Expand Down
4 changes: 3 additions & 1 deletion distutils/tests/test_bdist_msi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""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,
Expand Down
4 changes: 3 additions & 1 deletion distutils/tests/test_bdist_wininst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion distutils/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 . import py38compat as 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
10 changes: 5 additions & 5 deletions distutils/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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
Expand Down Expand Up @@ -62,13 +62,13 @@ def tearDown(self):
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)
Expand Down Expand Up @@ -105,8 +105,8 @@ def test_run_setup_uses_current_dir(self):
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))

Expand Down
3 changes: 2 additions & 1 deletion distutils/tests/test_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
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

Expand Down
4 changes: 3 additions & 1 deletion distutils/tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
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):
Expand Down
4 changes: 3 additions & 1 deletion distutils/tests/test_file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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):

Expand Down
16 changes: 8 additions & 8 deletions distutils/tests/test_filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
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 = """\
Expand Down Expand Up @@ -298,9 +298,9 @@ def test_process_template(self):


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(), [])

Expand All @@ -310,13 +310,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 @@ -325,9 +325,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
4 changes: 3 additions & 1 deletion distutils/tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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
Expand Down
4 changes: 3 additions & 1 deletion distutils/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
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
Expand Down
Loading

0 comments on commit bbe8e80

Please sign in to comment.