summaryrefslogtreecommitdiff
path: root/setuptools/_distutils/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-06-12 18:05:03 -0400
committerJason R. Coombs <jaraco@jaraco.com>2022-06-12 18:05:03 -0400
commit423f1829b5e8b2213492e4f023f26a7c26f0b287 (patch)
tree14a73d41f42c5d3a3effce1dd47ee3af3c07d689 /setuptools/_distutils/tests
parent48adabe567806c808fdede5afc8c57f68c4f9755 (diff)
parent75ed79d1ad1bfbb30dd684cd3cc55cb1139dc31b (diff)
downloadpython-setuptools-git-423f1829b5e8b2213492e4f023f26a7c26f0b287.tar.gz
Merge pypa/distutils@75ed79d
Diffstat (limited to 'setuptools/_distutils/tests')
-rw-r--r--setuptools/_distutils/tests/py35compat.py77
-rw-r--r--setuptools/_distutils/tests/support.py13
-rw-r--r--setuptools/_distutils/tests/test_archive_util.py134
-rw-r--r--setuptools/_distutils/tests/test_bdist.py33
-rw-r--r--setuptools/_distutils/tests/test_bdist_dumb.py28
-rw-r--r--setuptools/_distutils/tests/test_bdist_msi.py9
-rw-r--r--setuptools/_distutils/tests/test_bdist_rpm.py78
-rw-r--r--setuptools/_distutils/tests/test_bdist_wininst.py20
-rw-r--r--setuptools/_distutils/tests/test_build.py9
-rw-r--r--setuptools/_distutils/tests/test_build_clib.py44
-rw-r--r--setuptools/_distutils/tests/test_build_ext.py100
-rw-r--r--setuptools/_distutils/tests/test_build_py.py37
-rw-r--r--setuptools/_distutils/tests/test_build_scripts.py60
-rw-r--r--setuptools/_distutils/tests/test_check.py85
-rw-r--r--setuptools/_distutils/tests/test_clean.py22
-rw-r--r--setuptools/_distutils/tests/test_cmd.py30
-rw-r--r--setuptools/_distutils/tests/test_config.py45
-rw-r--r--setuptools/_distutils/tests/test_config_cmd.py18
-rw-r--r--setuptools/_distutils/tests/test_core.py22
-rw-r--r--setuptools/_distutils/tests/test_cygwinccompiler.py72
-rw-r--r--setuptools/_distutils/tests/test_dep_util.py14
-rw-r--r--setuptools/_distutils/tests/test_dir_util.py33
-rw-r--r--setuptools/_distutils/tests/test_dist.py286
-rw-r--r--setuptools/_distutils/tests/test_extension.py71
-rw-r--r--setuptools/_distutils/tests/test_file_util.py13
-rw-r--r--setuptools/_distutils/tests/test_filelist.py161
-rw-r--r--setuptools/_distutils/tests/test_install.py60
-rw-r--r--setuptools/_distutils/tests/test_install_data.py16
-rw-r--r--setuptools/_distutils/tests/test_install_headers.py12
-rw-r--r--setuptools/_distutils/tests/test_install_lib.py20
-rw-r--r--setuptools/_distutils/tests/test_install_scripts.py39
-rw-r--r--setuptools/_distutils/tests/test_log.py47
-rw-r--r--setuptools/_distutils/tests/test_msvc9compiler.py22
-rw-r--r--setuptools/_distutils/tests/test_msvccompiler.py26
-rw-r--r--setuptools/_distutils/tests/test_register.py59
-rw-r--r--setuptools/_distutils/tests/test_sdist.py140
-rw-r--r--setuptools/_distutils/tests/test_spawn.py40
-rw-r--r--setuptools/_distutils/tests/test_sysconfig.py192
-rw-r--r--setuptools/_distutils/tests/test_text_file.py61
-rw-r--r--setuptools/_distutils/tests/test_unixccompiler.py70
-rw-r--r--setuptools/_distutils/tests/test_upload.py40
-rw-r--r--setuptools/_distutils/tests/test_util.py93
-rw-r--r--setuptools/_distutils/tests/test_version.py102
-rw-r--r--setuptools/_distutils/tests/test_versionpredicate.py2
-rw-r--r--setuptools/_distutils/tests/unix_compat.py3
45 files changed, 1471 insertions, 1087 deletions
diff --git a/setuptools/_distutils/tests/py35compat.py b/setuptools/_distutils/tests/py35compat.py
deleted file mode 100644
index 0c755261..00000000
--- a/setuptools/_distutils/tests/py35compat.py
+++ /dev/null
@@ -1,77 +0,0 @@
-"""
-Backward compatibility support for Python 3.5
-"""
-
-import sys
-import test.support
-import subprocess
-
-
-# copied from Python 3.9 test.support module
-def _missing_compiler_executable(cmd_names=[]):
- """Check if the compiler components used to build the interpreter exist.
-
- Check for the existence of the compiler executables whose names are listed
- in 'cmd_names' or all the compiler executables when 'cmd_names' is empty
- and return the first missing executable or None when none is found
- missing.
-
- """
- from distutils import ccompiler, sysconfig, spawn
- compiler = ccompiler.new_compiler()
- sysconfig.customize_compiler(compiler)
- for name in compiler.executables:
- if cmd_names and name not in cmd_names:
- continue
- cmd = getattr(compiler, name)
- if cmd_names:
- assert cmd is not None, \
- "the '%s' executable is not configured" % name
- elif not cmd:
- continue
- if spawn.find_executable(cmd[0]) is None:
- return cmd[0]
-
-
-missing_compiler_executable = vars(test.support).setdefault(
- 'missing_compiler_executable',
- _missing_compiler_executable,
-)
-
-
-try:
- from test.support import unix_shell
-except ImportError:
- # Adapted from Python 3.9 test.support module
- is_android = hasattr(sys, 'getandroidapilevel')
- unix_shell = (
- None if sys.platform == 'win32' else
- '/system/bin/sh' if is_android else
- '/bin/sh'
- )
-
-
-# copied from Python 3.9 subprocess module
-def _optim_args_from_interpreter_flags():
- """Return a list of command-line arguments reproducing the current
- optimization settings in sys.flags."""
- args = []
- value = sys.flags.optimize
- if value > 0:
- args.append('-' + 'O' * value)
- return args
-
-
-vars(subprocess).setdefault(
- '_optim_args_from_interpreter_flags',
- _optim_args_from_interpreter_flags,
-)
-
-
-def adapt_glob(regex):
- """
- Supply legacy expectation on Python 3.5
- """
- if sys.version_info > (3, 6):
- return regex
- return regex.replace('(?s:', '').replace(r')\Z', r'\Z(?ms)')
diff --git a/setuptools/_distutils/tests/support.py b/setuptools/_distutils/tests/support.py
index b4410fc9..3085468a 100644
--- a/setuptools/_distutils/tests/support.py
+++ b/setuptools/_distutils/tests/support.py
@@ -15,7 +15,6 @@ from distutils.core import Distribution
class LoggingSilencer(object):
-
def setUp(self):
super().setUp()
self.threshold = log.set_threshold(log.FATAL)
@@ -35,13 +34,11 @@ class LoggingSilencer(object):
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
raise ValueError('%s wrong log level' % str(level))
if not isinstance(msg, str):
- raise TypeError("msg should be str, not '%.200s'"
- % (type(msg).__name__))
+ raise TypeError("msg should be str, not '%.200s'" % (type(msg).__name__))
self.logs.append((level, msg, args))
def get_logs(self, *levels):
- return [msg % args for level, msg, args
- in self.logs if level in levels]
+ return [msg % args for level, msg, args in self.logs if level in levels]
def clear_logs(self):
self.logs = []
@@ -120,7 +117,6 @@ class DummyCommand:
class EnvironGuard(object):
-
def setUp(self):
super(EnvironGuard, self).setUp()
self.old_environ = deepcopy(os.environ)
@@ -151,8 +147,9 @@ def copy_xxmodule_c(directory):
"""
filename = _get_xxmodule_path()
if filename is None:
- raise unittest.SkipTest('cannot find xxmodule.c (test must run in '
- 'the python build dir)')
+ raise unittest.SkipTest(
+ 'cannot find xxmodule.c (test must run in ' 'the python build dir)'
+ )
shutil.copy(filename, directory)
diff --git a/setuptools/_distutils/tests/test_archive_util.py b/setuptools/_distutils/tests/test_archive_util.py
index 800b9018..8fb95744 100644
--- a/setuptools/_distutils/tests/test_archive_util.py
+++ b/setuptools/_distutils/tests/test_archive_util.py
@@ -8,9 +8,13 @@ from os.path import splitdrive
import warnings
from distutils import archive_util
-from distutils.archive_util import (check_archive_formats, make_tarball,
- make_zipfile, make_archive,
- ARCHIVE_FORMATS)
+from distutils.archive_util import (
+ check_archive_formats,
+ make_tarball,
+ make_zipfile,
+ make_archive,
+ ARCHIVE_FORMATS,
+)
from distutils.spawn import find_executable, spawn
from distutils.tests import support
from test.support import run_unittest, patch
@@ -22,12 +26,14 @@ from .py38compat import check_warnings
try:
import zipfile
+
ZIP_SUPPORT = True
except ImportError:
ZIP_SUPPORT = find_executable('zip')
try:
import zlib
+
ZLIB_SUPPORT = True
except ImportError:
ZLIB_SUPPORT = False
@@ -42,6 +48,7 @@ try:
except ImportError:
lzma = None
+
def can_fs_encode(filename):
"""
Return True if the filename can be saved in the file system.
@@ -55,10 +62,9 @@ def can_fs_encode(filename):
return True
-class ArchiveUtilTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
+class ArchiveUtilTestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_make_tarball(self, name='archive'):
# creating something to tar
@@ -82,27 +88,31 @@ class ArchiveUtilTestCase(support.TempdirManager,
tmpdir = self._create_files()
self._make_tarball(tmpdir, 'archive', '.tar.xz', compress='xz')
- @unittest.skipUnless(can_fs_encode('årchiv'),
- 'File system cannot handle this filename')
+ @unittest.skipUnless(
+ can_fs_encode('årchiv'), 'File system cannot handle this filename'
+ )
def test_make_tarball_latin1(self):
"""
Mirror test_make_tarball, except filename contains latin characters.
"""
- self.test_make_tarball('årchiv') # note this isn't a real word
+ self.test_make_tarball('årchiv') # note this isn't a real word
- @unittest.skipUnless(can_fs_encode('のアーカイブ'),
- 'File system cannot handle this filename')
+ @unittest.skipUnless(
+ can_fs_encode('のアーカイブ'), 'File system cannot handle this filename'
+ )
def test_make_tarball_extended(self):
"""
Mirror test_make_tarball, except filename contains extended
characters outside the latin charset.
"""
- self.test_make_tarball('のアーカイブ') # japanese for archive
+ self.test_make_tarball('のアーカイブ') # japanese for archive
def _make_tarball(self, tmpdir, target_name, suffix, **kwargs):
tmpdir2 = self.mkdtemp()
- unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
- "source and target should be on same drive")
+ unittest.skipUnless(
+ splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
+ "source and target should be on same drive",
+ )
base_name = os.path.join(tmpdir2, target_name)
@@ -124,8 +134,14 @@ class ArchiveUtilTestCase(support.TempdirManager,
finally:
tar.close()
- _zip_created_files = ['dist/', 'dist/file1', 'dist/file2',
- 'dist/sub/', 'dist/sub/file3', 'dist/sub2/']
+ _zip_created_files = [
+ 'dist/',
+ 'dist/file1',
+ 'dist/file2',
+ 'dist/sub/',
+ 'dist/sub/file3',
+ 'dist/sub2/',
+ ]
_created_files = [p.rstrip('/') for p in _zip_created_files]
def _create_files(self):
@@ -140,11 +156,12 @@ class ArchiveUtilTestCase(support.TempdirManager,
os.mkdir(os.path.join(dist, 'sub2'))
return tmpdir
- @unittest.skipUnless(find_executable('tar') and find_executable('gzip')
- and ZLIB_SUPPORT,
- 'Need the tar, gzip and zlib command to run')
+ @unittest.skipUnless(
+ find_executable('tar') and find_executable('gzip') and ZLIB_SUPPORT,
+ 'Need the tar, gzip and zlib command to run',
+ )
def test_tarfile_vs_tar(self):
- tmpdir = self._create_files()
+ tmpdir = self._create_files()
tmpdir2 = self.mkdtemp()
base_name = os.path.join(tmpdir2, 'archive')
old_dir = os.getcwd()
@@ -197,10 +214,11 @@ class ArchiveUtilTestCase(support.TempdirManager,
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
- @unittest.skipUnless(find_executable('compress'),
- 'The compress program is required')
+ @unittest.skipUnless(
+ find_executable('compress'), 'The compress program is required'
+ )
def test_compress_deprecated(self):
- tmpdir = self._create_files()
+ tmpdir = self._create_files()
base_name = os.path.join(self.mkdtemp(), 'archive')
# using compress and testing the PendingDeprecationWarning
@@ -223,15 +241,15 @@ class ArchiveUtilTestCase(support.TempdirManager,
try:
with check_warnings() as w:
warnings.simplefilter("always")
- make_tarball(base_name, 'dist', compress='compress',
- dry_run=True)
+ make_tarball(base_name, 'dist', compress='compress', dry_run=True)
finally:
os.chdir(old_dir)
self.assertFalse(os.path.exists(tarball))
self.assertEqual(len(w.warnings), 1)
- @unittest.skipUnless(ZIP_SUPPORT and ZLIB_SUPPORT,
- 'Need zip and zlib support to run')
+ @unittest.skipUnless(
+ ZIP_SUPPORT and ZLIB_SUPPORT, 'Need zip and zlib support to run'
+ )
def test_make_zipfile(self):
# creating something to tar
tmpdir = self._create_files()
@@ -251,6 +269,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
called = []
zipfile_class = zipfile.ZipFile
+
def fake_zipfile(*a, **kw):
if kw.get('compression', None) == zipfile.ZIP_STORED:
called.append((a, kw))
@@ -265,17 +284,18 @@ class ArchiveUtilTestCase(support.TempdirManager,
make_zipfile(base_name, 'dist')
tarball = base_name + '.zip'
- self.assertEqual(called,
- [((tarball, "w"), {'compression': zipfile.ZIP_STORED})])
+ self.assertEqual(
+ called, [((tarball, "w"), {'compression': zipfile.ZIP_STORED})]
+ )
self.assertTrue(os.path.exists(tarball))
with zipfile.ZipFile(tarball) as zf:
self.assertEqual(sorted(zf.namelist()), self._zip_created_files)
def test_check_archive_formats(self):
- self.assertEqual(check_archive_formats(['gztar', 'xxx', 'zip']),
- 'xxx')
- self.assertIsNone(check_archive_formats(['gztar', 'bztar', 'xztar',
- 'ztar', 'tar', 'zip']))
+ self.assertEqual(check_archive_formats(['gztar', 'xxx', 'zip']), 'xxx')
+ self.assertIsNone(
+ check_archive_formats(['gztar', 'bztar', 'xztar', 'ztar', 'tar', 'zip'])
+ )
def test_make_archive(self):
tmpdir = self.mkdtemp()
@@ -284,8 +304,10 @@ class ArchiveUtilTestCase(support.TempdirManager,
def test_make_archive_cwd(self):
current_dir = os.getcwd()
+
def _breaks(*args, **kw):
raise RuntimeError()
+
ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
try:
try:
@@ -297,8 +319,8 @@ class ArchiveUtilTestCase(support.TempdirManager,
del ARCHIVE_FORMATS['xxx']
def test_make_archive_tar(self):
- base_dir = self._create_files()
- base_name = os.path.join(self.mkdtemp() , 'archive')
+ base_dir = self._create_files()
+ base_name = os.path.join(self.mkdtemp(), 'archive')
res = make_archive(base_name, 'tar', base_dir, 'dist')
self.assertTrue(os.path.exists(res))
self.assertEqual(os.path.basename(res), 'archive.tar')
@@ -306,8 +328,8 @@ class ArchiveUtilTestCase(support.TempdirManager,
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_make_archive_gztar(self):
- base_dir = self._create_files()
- base_name = os.path.join(self.mkdtemp() , 'archive')
+ base_dir = self._create_files()
+ base_name = os.path.join(self.mkdtemp(), 'archive')
res = make_archive(base_name, 'gztar', base_dir, 'dist')
self.assertTrue(os.path.exists(res))
self.assertEqual(os.path.basename(res), 'archive.tar.gz')
@@ -315,8 +337,8 @@ class ArchiveUtilTestCase(support.TempdirManager,
@unittest.skipUnless(bz2, 'Need bz2 support to run')
def test_make_archive_bztar(self):
- base_dir = self._create_files()
- base_name = os.path.join(self.mkdtemp() , 'archive')
+ base_dir = self._create_files()
+ base_name = os.path.join(self.mkdtemp(), 'archive')
res = make_archive(base_name, 'bztar', base_dir, 'dist')
self.assertTrue(os.path.exists(res))
self.assertEqual(os.path.basename(res), 'archive.tar.bz2')
@@ -324,8 +346,8 @@ class ArchiveUtilTestCase(support.TempdirManager,
@unittest.skipUnless(lzma, 'Need xz support to run')
def test_make_archive_xztar(self):
- base_dir = self._create_files()
- base_name = os.path.join(self.mkdtemp() , 'archive')
+ base_dir = self._create_files()
+ base_name = os.path.join(self.mkdtemp(), 'archive')
res = make_archive(base_name, 'xztar', base_dir, 'dist')
self.assertTrue(os.path.exists(res))
self.assertEqual(os.path.basename(res), 'archive.tar.xz')
@@ -340,37 +362,41 @@ class ArchiveUtilTestCase(support.TempdirManager,
else:
group = owner = 'root'
- base_dir = self._create_files()
+ base_dir = self._create_files()
root_dir = self.mkdtemp()
- base_name = os.path.join(self.mkdtemp() , 'archive')
- res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
- group=group)
+ base_name = os.path.join(self.mkdtemp(), 'archive')
+ res = make_archive(
+ base_name, 'zip', root_dir, base_dir, owner=owner, group=group
+ )
self.assertTrue(os.path.exists(res))
res = make_archive(base_name, 'zip', root_dir, base_dir)
self.assertTrue(os.path.exists(res))
- res = make_archive(base_name, 'tar', root_dir, base_dir,
- owner=owner, group=group)
+ res = make_archive(
+ base_name, 'tar', root_dir, base_dir, owner=owner, group=group
+ )
self.assertTrue(os.path.exists(res))
- res = make_archive(base_name, 'tar', root_dir, base_dir,
- owner='kjhkjhkjg', group='oihohoh')
+ res = make_archive(
+ base_name, 'tar', root_dir, base_dir, owner='kjhkjhkjg', group='oihohoh'
+ )
self.assertTrue(os.path.exists(res))
@unittest.skipUnless(ZLIB_SUPPORT, "Requires zlib")
@require_unix_id
@require_uid_0
def test_tarfile_root_owner(self):
- tmpdir = self._create_files()
+ tmpdir = self._create_files()
base_name = os.path.join(self.mkdtemp(), 'archive')
old_dir = os.getcwd()
os.chdir(tmpdir)
group = grp.getgrgid(0)[0]
owner = pwd.getpwuid(0)[0]
try:
- archive_name = make_tarball(base_name, 'dist', compress=None,
- owner=owner, group=group)
+ archive_name = make_tarball(
+ base_name, 'dist', compress=None, owner=owner, group=group
+ )
finally:
os.chdir(old_dir)
@@ -386,8 +412,10 @@ class ArchiveUtilTestCase(support.TempdirManager,
finally:
archive.close()
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(ArchiveUtilTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_bdist.py b/setuptools/_distutils/tests/test_bdist.py
index 8b7498e3..2d0bb95b 100644
--- a/setuptools/_distutils/tests/test_bdist.py
+++ b/setuptools/_distutils/tests/test_bdist.py
@@ -8,9 +8,7 @@ from distutils.command.bdist import bdist
from distutils.tests import support
-class BuildTestCase(support.TempdirManager,
- unittest.TestCase):
-
+class BuildTestCase(support.TempdirManager, unittest.TestCase):
def test_formats(self):
# let's create a command and make sure
# we can set the format
@@ -21,8 +19,17 @@ class BuildTestCase(support.TempdirManager,
self.assertEqual(cmd.formats, ['msi'])
# what formats does bdist offer?
- formats = ['bztar', 'gztar', 'msi', 'rpm', 'tar',
- 'wininst', 'xztar', 'zip', 'ztar']
+ formats = [
+ 'bztar',
+ 'gztar',
+ 'msi',
+ 'rpm',
+ 'tar',
+ 'wininst',
+ 'xztar',
+ 'zip',
+ 'ztar',
+ ]
found = sorted(cmd.format_command)
self.assertEqual(found, formats)
@@ -34,24 +41,30 @@ class BuildTestCase(support.TempdirManager,
cmd.ensure_finalized()
dist.command_obj['bdist'] = cmd
- names = ['bdist_dumb', 'bdist_wininst'] # bdist_rpm does not support --skip-build
+ names = [
+ 'bdist_dumb',
+ 'bdist_wininst',
+ ] # bdist_rpm does not support --skip-build
if os.name == 'nt':
names.append('bdist_msi')
for name in names:
with warnings.catch_warnings():
- warnings.filterwarnings('ignore', 'bdist_wininst command is deprecated',
- DeprecationWarning)
+ warnings.filterwarnings(
+ 'ignore', 'bdist_wininst command is deprecated', DeprecationWarning
+ )
subcmd = cmd.get_finalized_command(name)
if getattr(subcmd, '_unsupported', False):
# command is not supported on this build
continue
- self.assertTrue(subcmd.skip_build,
- '%s should take --skip-build from bdist' % name)
+ self.assertTrue(
+ subcmd.skip_build, '%s should take --skip-build from bdist' % name
+ )
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildTestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_bdist_dumb.py b/setuptools/_distutils/tests/test_bdist_dumb.py
index bb860c8a..83ab217d 100644
--- a/setuptools/_distutils/tests/test_bdist_dumb.py
+++ b/setuptools/_distutils/tests/test_bdist_dumb.py
@@ -21,16 +21,18 @@ setup(name='foo', version='0.1', py_modules=['foo'],
try:
import zlib
+
ZLIB_SUPPORT = True
except ImportError:
ZLIB_SUPPORT = False
-class BuildDumbTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
+class BuildDumbTestCase(
+ support.TempdirManager,
+ support.LoggingSilencer,
+ support.EnvironGuard,
+ unittest.TestCase,
+):
def setUp(self):
super(BuildDumbTestCase, self).setUp()
self.old_location = os.getcwd()
@@ -54,10 +56,16 @@ class BuildDumbTestCase(support.TempdirManager,
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
self.write_file((pkg_dir, 'README'), '')
- dist = Distribution({'name': 'foo', 'version': '0.1',
- 'py_modules': ['foo'],
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'})
+ dist = Distribution(
+ {
+ 'name': 'foo',
+ 'version': '0.1',
+ 'py_modules': ['foo'],
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ }
+ )
dist.script_name = 'setup.py'
os.chdir(pkg_dir)
@@ -90,8 +98,10 @@ class BuildDumbTestCase(support.TempdirManager,
wanted.append('foo.%s.pyc' % sys.implementation.cache_tag)
self.assertEqual(contents, sorted(wanted))
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildDumbTestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_bdist_msi.py b/setuptools/_distutils/tests/test_bdist_msi.py
index b1831ef2..a9f3dbb5 100644
--- a/setuptools/_distutils/tests/test_bdist_msi.py
+++ b/setuptools/_distutils/tests/test_bdist_msi.py
@@ -8,13 +8,13 @@ from .py38compat import check_warnings
@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
-class BDistMSITestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
+class BDistMSITestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
def test_minimal(self):
# minimal test XXX need more tests
from distutils.command.bdist_msi import bdist_msi
+
project_dir, dist = self.create_dist()
with check_warnings(("", DeprecationWarning)):
cmd = bdist_msi(dist)
@@ -24,5 +24,6 @@ class BDistMSITestCase(support.TempdirManager,
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BDistMSITestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_bdist_rpm.py b/setuptools/_distutils/tests/test_bdist_rpm.py
index 08a7cb46..f60a582a 100644
--- a/setuptools/_distutils/tests/test_bdist_rpm.py
+++ b/setuptools/_distutils/tests/test_bdist_rpm.py
@@ -22,11 +22,13 @@ setup(name='foo', version='0.1', py_modules=['foo'],
"""
-class BuildRpmTestCase(support.TempdirManager,
- support.EnvironGuard,
- support.LoggingSilencer,
- unittest.TestCase):
+class BuildRpmTestCase(
+ support.TempdirManager,
+ support.EnvironGuard,
+ support.LoggingSilencer,
+ unittest.TestCase,
+):
def setUp(self):
try:
sys.executable.encode("UTF-8")
@@ -45,17 +47,18 @@ class BuildRpmTestCase(support.TempdirManager,
# XXX I am unable yet to make this test work without
# spurious sdtout/stderr output under Mac OS X
- @unittest.skipUnless(sys.platform.startswith('linux'),
- 'spurious sdtout/stderr output under Mac OS X')
+ @unittest.skipUnless(
+ sys.platform.startswith('linux'), 'spurious sdtout/stderr output under Mac OS X'
+ )
@requires_zlib()
- @unittest.skipIf(find_executable('rpm') is None,
- 'the rpm command is not found')
- @unittest.skipIf(find_executable('rpmbuild') is None,
- 'the rpmbuild command is not found')
+ @unittest.skipIf(find_executable('rpm') is None, 'the rpm command is not found')
+ @unittest.skipIf(
+ find_executable('rpmbuild') is None, 'the rpmbuild command is not found'
+ )
def test_quiet(self):
# let's create a package
tmp_dir = self.mkdtemp()
- os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
+ os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
pkg_dir = os.path.join(tmp_dir, 'foo')
os.mkdir(pkg_dir)
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
@@ -63,10 +66,16 @@ class BuildRpmTestCase(support.TempdirManager,
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
self.write_file((pkg_dir, 'README'), '')
- dist = Distribution({'name': 'foo', 'version': '0.1',
- 'py_modules': ['foo'],
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'})
+ dist = Distribution(
+ {
+ 'name': 'foo',
+ 'version': '0.1',
+ 'py_modules': ['foo'],
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ }
+ )
dist.script_name = 'setup.py'
os.chdir(pkg_dir)
@@ -84,22 +93,25 @@ class BuildRpmTestCase(support.TempdirManager,
# bug #2945: upload ignores bdist_rpm files
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
- self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
+ self.assertIn(
+ ('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files
+ )
# XXX I am unable yet to make this test work without
# spurious sdtout/stderr output under Mac OS X
- @unittest.skipUnless(sys.platform.startswith('linux'),
- 'spurious sdtout/stderr output under Mac OS X')
+ @unittest.skipUnless(
+ sys.platform.startswith('linux'), 'spurious sdtout/stderr output under Mac OS X'
+ )
@requires_zlib()
# http://bugs.python.org/issue1533164
- @unittest.skipIf(find_executable('rpm') is None,
- 'the rpm command is not found')
- @unittest.skipIf(find_executable('rpmbuild') is None,
- 'the rpmbuild command is not found')
+ @unittest.skipIf(find_executable('rpm') is None, 'the rpm command is not found')
+ @unittest.skipIf(
+ find_executable('rpmbuild') is None, 'the rpmbuild command is not found'
+ )
def test_no_optimize_flag(self):
# let's create a package that breaks bdist_rpm
tmp_dir = self.mkdtemp()
- os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
+ os.environ['HOME'] = tmp_dir # to confine dir '.rpmdb' creation
pkg_dir = os.path.join(tmp_dir, 'foo')
os.mkdir(pkg_dir)
self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
@@ -107,10 +119,16 @@ class BuildRpmTestCase(support.TempdirManager,
self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
self.write_file((pkg_dir, 'README'), '')
- dist = Distribution({'name': 'foo', 'version': '0.1',
- 'py_modules': ['foo'],
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'})
+ dist = Distribution(
+ {
+ 'name': 'foo',
+ 'version': '0.1',
+ 'py_modules': ['foo'],
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ }
+ )
dist.script_name = 'setup.py'
os.chdir(pkg_dir)
@@ -127,12 +145,16 @@ class BuildRpmTestCase(support.TempdirManager,
# bug #2945: upload ignores bdist_rpm files
self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
- self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
+ self.assertIn(
+ ('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files
+ )
os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildRpmTestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_bdist_wininst.py b/setuptools/_distutils/tests/test_bdist_wininst.py
index 59f25167..c103a63b 100644
--- a/setuptools/_distutils/tests/test_bdist_wininst.py
+++ b/setuptools/_distutils/tests/test_bdist_wininst.py
@@ -9,14 +9,18 @@ from .py38compat import check_warnings
from distutils.command.bdist_wininst import bdist_wininst
from distutils.tests import support
-@unittest.skipIf(sys.platform == 'win32' and platform.machine() == 'ARM64',
- 'bdist_wininst is not supported in this install')
-@unittest.skipIf(getattr(bdist_wininst, '_unsupported', False),
- 'bdist_wininst is not supported in this install')
-class BuildWinInstTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
+@unittest.skipIf(
+ sys.platform == 'win32' and platform.machine() == 'ARM64',
+ 'bdist_wininst is not supported in this install',
+)
+@unittest.skipIf(
+ getattr(bdist_wininst, '_unsupported', False),
+ 'bdist_wininst is not supported in this install',
+)
+class BuildWinInstTestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
def test_get_exe_bytes(self):
# issue5731: command was broken on non-windows platforms
@@ -33,8 +37,10 @@ class BuildWinInstTestCase(support.TempdirManager,
exe_file = cmd.get_exe_bytes()
self.assertGreater(len(exe_file), 10)
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildWinInstTestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_build.py b/setuptools/_distutils/tests/test_build.py
index 93724419..190bbdfd 100644
--- a/setuptools/_distutils/tests/test_build.py
+++ b/setuptools/_distutils/tests/test_build.py
@@ -8,10 +8,8 @@ from distutils.command.build import build
from distutils.tests import support
from sysconfig import get_platform
-class BuildTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
+class BuildTestCase(support.TempdirManager, support.LoggingSilencer, unittest.TestCase):
def test_finalize_options(self):
pkg_dir, dist = self.create_dist()
cmd = build(dist)
@@ -42,15 +40,16 @@ class BuildTestCase(support.TempdirManager,
self.assertEqual(cmd.build_temp, wanted)
# build_scripts is build/scripts-x.x
- wanted = os.path.join(cmd.build_base,
- 'scripts-%d.%d' % sys.version_info[:2])
+ wanted = os.path.join(cmd.build_base, 'scripts-%d.%d' % sys.version_info[:2])
self.assertEqual(cmd.build_scripts, wanted)
# executable is os.path.normpath(sys.executable)
self.assertEqual(cmd.executable, os.path.normpath(sys.executable))
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_build_clib.py b/setuptools/_distutils/tests/test_build_clib.py
index d50ead7c..24c74787 100644
--- a/setuptools/_distutils/tests/test_build_clib.py
+++ b/setuptools/_distutils/tests/test_build_clib.py
@@ -3,18 +3,16 @@ import unittest
import os
import sys
-from test.support import run_unittest
-
-from .py35compat import missing_compiler_executable
+from test.support import run_unittest, missing_compiler_executable
from distutils.command.build_clib import build_clib
from distutils.errors import DistutilsSetupError
from distutils.tests import support
-class BuildCLibTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
+class BuildCLibTestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
def test_check_library_dist(self):
pkg_dir, dist = self.create_dist()
cmd = build_clib(dist)
@@ -23,23 +21,27 @@ class BuildCLibTestCase(support.TempdirManager,
self.assertRaises(DistutilsSetupError, cmd.check_library_list, 'foo')
# each element of 'libraries' must a 2-tuple
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- ['foo1', 'foo2'])
+ self.assertRaises(DistutilsSetupError, cmd.check_library_list, ['foo1', 'foo2'])
# first element of each tuple in 'libraries'
# must be a string (the library name)
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- [(1, 'foo1'), ('name', 'foo2')])
+ self.assertRaises(
+ DistutilsSetupError, cmd.check_library_list, [(1, 'foo1'), ('name', 'foo2')]
+ )
# library name may not contain directory separators
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- [('name', 'foo1'),
- ('another/name', 'foo2')])
+ self.assertRaises(
+ DistutilsSetupError,
+ cmd.check_library_list,
+ [('name', 'foo1'), ('another/name', 'foo2')],
+ )
# second element of each tuple must be a dictionary (build info)
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- [('name', {}),
- ('another', 'foo2')])
+ self.assertRaises(
+ DistutilsSetupError,
+ cmd.check_library_list,
+ [('name', {}), ('another', 'foo2')],
+ )
# those work
libs = [('name', {}), ('name', {'ok': 'good'})]
@@ -63,17 +65,21 @@ class BuildCLibTestCase(support.TempdirManager,
cmd.libraries = [('name', {'sources': ('a', 'b')})]
self.assertEqual(cmd.get_source_files(), ['a', 'b'])
- cmd.libraries = [('name', {'sources': ('a', 'b')}),
- ('name2', {'sources': ['c', 'd']})]
+ cmd.libraries = [
+ ('name', {'sources': ('a', 'b')}),
+ ('name2', {'sources': ['c', 'd']}),
+ ]
self.assertEqual(cmd.get_source_files(), ['a', 'b', 'c', 'd'])
def test_build_libraries(self):
pkg_dir, dist = self.create_dist()
cmd = build_clib(dist)
+
class FakeCompiler:
def compile(*args, **kw):
pass
+
create_static_lib = compile
cmd.compiler = FakeCompiler()
@@ -129,8 +135,10 @@ class BuildCLibTestCase(support.TempdirManager,
# let's check the result
self.assertIn('libfoo.a', os.listdir(build_temp))
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildCLibTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_build_ext.py b/setuptools/_distutils/tests/test_build_ext.py
index 920e4dc8..c42ceabd 100644
--- a/setuptools/_distutils/tests/test_build_ext.py
+++ b/setuptools/_distutils/tests/test_build_ext.py
@@ -6,12 +6,19 @@ import textwrap
from distutils.core import Distribution
from distutils.command.build_ext import build_ext
from distutils import sysconfig
-from distutils.tests.support import (TempdirManager, LoggingSilencer,
- copy_xxmodule_c, fixup_build_ext)
+from distutils.tests.support import (
+ TempdirManager,
+ LoggingSilencer,
+ copy_xxmodule_c,
+ fixup_build_ext,
+)
from distutils.extension import Extension
from distutils.errors import (
- CompileError, DistutilsPlatformError, DistutilsSetupError,
- UnknownFileError)
+ CompileError,
+ DistutilsPlatformError,
+ DistutilsSetupError,
+ UnknownFileError,
+)
import unittest
from test import support
@@ -23,17 +30,17 @@ from test.support.script_helper import assert_python_ok
ALREADY_TESTED = False
-class BuildExtTestCase(TempdirManager,
- LoggingSilencer,
- unittest.TestCase):
+class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase):
def setUp(self):
# Create a simple test environment
super(BuildExtTestCase, self).setUp()
self.tmp_dir = self.mkdtemp()
import site
+
self.old_user_base = site.USER_BASE
site.USER_BASE = self.mkdtemp()
from distutils.command import build_ext
+
build_ext.USER_BASE = site.USER_BASE
# bpo-30132: On Windows, a .pdb file may be created in the current
@@ -45,8 +52,10 @@ class BuildExtTestCase(TempdirManager,
def tearDown(self):
import site
+
site.USER_BASE = self.old_user_base
from distutils.command import build_ext
+
build_ext.USER_BASE = self.old_user_base
super(BuildExtTestCase, self).tearDown()
@@ -83,7 +92,8 @@ class BuildExtTestCase(TempdirManager,
else:
ALREADY_TESTED = type(self).__name__
- code = textwrap.dedent("""
+ code = textwrap.dedent(
+ """
tmp_dir = {self.tmp_dir!r}
import sys
@@ -109,7 +119,10 @@ class BuildExtTestCase(TempdirManager,
unittest.main()
- """.format(**locals()))
+ """.format(
+ **locals()
+ )
+ )
assert_python_ok('-c', code)
def test_solaris_enable_shared(self):
@@ -117,8 +130,9 @@ class BuildExtTestCase(TempdirManager,
cmd = self.build_ext(dist)
old = sys.platform
- sys.platform = 'sunos' # fooling finalize_options
- from distutils.sysconfig import _config_vars
+ sys.platform = 'sunos' # fooling finalize_options
+ from distutils.sysconfig import _config_vars
+
old_var = _config_vars.get('Py_ENABLE_SHARED')
_config_vars['Py_ENABLE_SHARED'] = 1
try:
@@ -135,12 +149,12 @@ class BuildExtTestCase(TempdirManager,
def test_user_site(self):
import site
+
dist = Distribution({'name': 'xx'})
cmd = self.build_ext(dist)
# making sure the user option is there
- options = [name for name, short, lable in
- cmd.user_options]
+ options = [name for name, short, lable in cmd.user_options]
self.assertIn('user', options)
# setting a value
@@ -169,8 +183,9 @@ class BuildExtTestCase(TempdirManager,
dist = Distribution({'name': 'xx', 'ext_modules': modules})
cmd = self.build_ext(dist)
cmd.ensure_finalized()
- self.assertRaises((UnknownFileError, CompileError),
- cmd.run) # should raise an error
+ self.assertRaises(
+ (UnknownFileError, CompileError), cmd.run
+ ) # should raise an error
modules = [Extension('foo', ['xxx'], optional=True)]
dist = Distribution({'name': 'xx', 'ext_modules': modules})
@@ -256,8 +271,7 @@ class BuildExtTestCase(TempdirManager,
cmd.finalize_options()
#'extensions' option must be a list of Extension instances
- self.assertRaises(DistutilsSetupError,
- cmd.check_extensions_list, 'foo')
+ self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, 'foo')
# each element of 'ext_modules' option must be an
# Extension instance or 2-tuple
@@ -276,8 +290,7 @@ class BuildExtTestCase(TempdirManager,
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
# ok this one should pass
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar'})]
+ exts = [('foo.bar', {'sources': [''], 'libraries': 'foo', 'some': 'bar'})]
cmd.check_extensions_list(exts)
ext = exts[0]
self.assertIsInstance(ext, Extension)
@@ -289,8 +302,17 @@ class BuildExtTestCase(TempdirManager,
self.assertFalse(hasattr(ext, 'some'))
# 'macros' element of build info dict must be 1- or 2-tuple
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar', 'macros': [('1', '2', '3'), 'foo']})]
+ exts = [
+ (
+ 'foo.bar',
+ {
+ 'sources': [''],
+ 'libraries': 'foo',
+ 'some': 'bar',
+ 'macros': [('1', '2', '3'), 'foo'],
+ },
+ )
+ ]
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
exts[0][1]['macros'] = [('1', '2'), ('3',)]
@@ -337,8 +359,7 @@ class BuildExtTestCase(TempdirManager,
c_file = os.path.join(tmp_dir, 'foo.c')
self.write_file(c_file, 'void PyInit_foo(void) {}\n')
ext = Extension('foo', [c_file], optional=False)
- dist = Distribution({'name': 'xx',
- 'ext_modules': [ext]})
+ dist = Distribution({'name': 'xx', 'ext_modules': [ext]})
cmd = self.build_ext(dist)
fixup_build_ext(cmd)
cmd.ensure_finalized()
@@ -398,9 +419,9 @@ class BuildExtTestCase(TempdirManager,
def test_ext_fullpath(self):
ext = sysconfig.get_config_var('EXT_SUFFIX')
# building lxml.etree inplace
- #etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
- #etree_ext = Extension('lxml.etree', [etree_c])
- #dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
+ # etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
+ # etree_ext = Extension('lxml.etree', [etree_c])
+ # dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
dist = Distribution()
cmd = self.build_ext(dist)
cmd.inplace = 1
@@ -423,8 +444,7 @@ class BuildExtTestCase(TempdirManager,
build_py.package_dir = {}
cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
path = cmd.get_ext_fullpath('twisted.runner.portmap')
- wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
- 'portmap' + ext)
+ wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner', 'portmap' + ext)
self.assertEqual(wanted, path)
# building twisted.runner.portmap inplace
@@ -433,7 +453,6 @@ class BuildExtTestCase(TempdirManager,
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
self.assertEqual(wanted, path)
-
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
def test_deployment_target_default(self):
# Issue 9516: Test that, in the absence of the environment variable,
@@ -445,8 +464,9 @@ class BuildExtTestCase(TempdirManager,
def test_deployment_target_too_low(self):
# Issue 9516: Test that an extension module is not allowed to be
# compiled with a deployment target less than that of the interpreter.
- self.assertRaises(DistutilsPlatformError,
- self._try_compile_deployment_target, '>', '10.1')
+ self.assertRaises(
+ DistutilsPlatformError, self._try_compile_deployment_target, '>', '10.1'
+ )
@unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
def test_deployment_target_higher_ok(self):
@@ -475,7 +495,9 @@ class BuildExtTestCase(TempdirManager,
deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
with open(deptarget_c, 'w') as fp:
- fp.write(textwrap.dedent('''\
+ fp.write(
+ textwrap.dedent(
+ '''\
#include <AvailabilityMacros.h>
int dummy;
@@ -485,7 +507,10 @@ class BuildExtTestCase(TempdirManager,
#error "Unexpected target"
#endif
- ''' % operator))
+ '''
+ % operator
+ )
+ )
# get the deployment target that the interpreter was built with
target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
@@ -506,12 +531,9 @@ class BuildExtTestCase(TempdirManager,
deptarget_ext = Extension(
'deptarget',
[deptarget_c],
- extra_compile_args=['-DTARGET=%s'%(target,)],
+ extra_compile_args=['-DTARGET=%s' % (target,)],
)
- dist = Distribution({
- 'name': 'deptarget',
- 'ext_modules': [deptarget_ext]
- })
+ dist = Distribution({'name': 'deptarget', 'ext_modules': [deptarget_ext]})
dist.package_dir = self.tmp_dir
cmd = self.build_ext(dist)
cmd.build_lib = self.tmp_dir
@@ -533,7 +555,6 @@ class BuildExtTestCase(TempdirManager,
class ParallelBuildExtTestCase(BuildExtTestCase):
-
def build_ext(self, *args, **kwargs):
build_ext = super().build_ext(*args, **kwargs)
build_ext.parallel = True
@@ -546,5 +567,6 @@ def test_suite():
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(ParallelBuildExtTestCase))
return suite
+
if __name__ == '__main__':
support.run_unittest(__name__)
diff --git a/setuptools/_distutils/tests/test_build_py.py b/setuptools/_distutils/tests/test_build_py.py
index a590a485..4585d799 100644
--- a/setuptools/_distutils/tests/test_build_py.py
+++ b/setuptools/_distutils/tests/test_build_py.py
@@ -12,10 +12,9 @@ from distutils.tests import support
from test.support import run_unittest
-class BuildPyTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
+class BuildPyTestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
def test_package_data(self):
sources = self.mkdtemp()
f = open(os.path.join(sources, "__init__.py"), "w")
@@ -31,13 +30,10 @@ class BuildPyTestCase(support.TempdirManager,
destination = self.mkdtemp()
- dist = Distribution({"packages": ["pkg"],
- "package_dir": {"pkg": sources}})
+ dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": sources}})
# script_name need not exist, it just need to be initialized
dist.script_name = os.path.join(sources, "setup.py")
- dist.command_obj["build"] = support.DummyCommand(
- force=0,
- build_lib=destination)
+ dist.command_obj["build"] = support.DummyCommand(force=0, build_lib=destination)
dist.packages = ["pkg"]
dist.package_data = {"pkg": ["README.txt"]}
dist.package_dir = {"pkg": sources}
@@ -62,8 +58,7 @@ class BuildPyTestCase(support.TempdirManager,
self.assertFalse(os.path.exists(pycache_dir))
else:
pyc_files = os.listdir(pycache_dir)
- self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag,
- pyc_files)
+ self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag, pyc_files)
def test_empty_package_dir(self):
# See bugs #1668596/#1720897
@@ -75,9 +70,13 @@ class BuildPyTestCase(support.TempdirManager,
open(os.path.join(testdir, "testfile"), "w").close()
os.chdir(sources)
- dist = Distribution({"packages": ["pkg"],
- "package_dir": {"pkg": ""},
- "package_data": {"pkg": ["doc/*"]}})
+ dist = Distribution(
+ {
+ "packages": ["pkg"],
+ "package_dir": {"pkg": ""},
+ "package_data": {"pkg": ["doc/*"]},
+ }
+ )
# script_name need not exist, it just need to be initialized
dist.script_name = os.path.join(sources, "setup.py")
dist.script_args = ["build"]
@@ -102,8 +101,7 @@ class BuildPyTestCase(support.TempdirManager,
found = os.listdir(cmd.build_lib)
self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
- self.assertEqual(found,
- ['boiledeggs.%s.pyc' % sys.implementation.cache_tag])
+ self.assertEqual(found, ['boiledeggs.%s.pyc' % sys.implementation.cache_tag])
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
def test_byte_compile_optimized(self):
@@ -142,8 +140,7 @@ class BuildPyTestCase(support.TempdirManager,
os.mkdir(os.path.join(docdir, 'otherdir'))
os.chdir(sources)
- dist = Distribution({"packages": ["pkg"],
- "package_data": {"pkg": ["doc/*"]}})
+ dist = Distribution({"packages": ["pkg"], "package_data": {"pkg": ["doc/*"]}})
# script_name need not exist, it just need to be initialized
dist.script_name = os.path.join(sources, "setup.py")
dist.script_args = ["build"]
@@ -168,12 +165,12 @@ class BuildPyTestCase(support.TempdirManager,
finally:
sys.dont_write_bytecode = old_dont_write_bytecode
- self.assertIn('byte-compiling is disabled',
- self.logs[0][1] % self.logs[0][2])
+ self.assertIn('byte-compiling is disabled', self.logs[0][1] % self.logs[0][2])
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildPyTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_build_scripts.py b/setuptools/_distutils/tests/test_build_scripts.py
index f299e51e..8c7061d7 100644
--- a/setuptools/_distutils/tests/test_build_scripts.py
+++ b/setuptools/_distutils/tests/test_build_scripts.py
@@ -11,10 +11,9 @@ from distutils.tests import support
from test.support import run_unittest
-class BuildScriptsTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
+class BuildScriptsTestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
def test_default_settings(self):
cmd = self.get_build_scripts_cmd("/foo/bar", [])
self.assertFalse(cmd.force)
@@ -30,9 +29,9 @@ class BuildScriptsTestCase(support.TempdirManager,
target = self.mkdtemp()
expected = self.write_sample_scripts(source)
- cmd = self.get_build_scripts_cmd(target,
- [os.path.join(source, fn)
- for fn in expected])
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, fn) for fn in expected]
+ )
cmd.finalize_options()
cmd.run()
@@ -42,32 +41,38 @@ class BuildScriptsTestCase(support.TempdirManager,
def get_build_scripts_cmd(self, target, scripts):
import sys
+
dist = Distribution()
dist.scripts = scripts
dist.command_obj["build"] = support.DummyCommand(
- build_scripts=target,
- force=1,
- executable=sys.executable
- )
+ build_scripts=target, force=1, executable=sys.executable
+ )
return build_scripts(dist)
def write_sample_scripts(self, dir):
expected = []
expected.append("script1.py")
- self.write_script(dir, "script1.py",
- ("#! /usr/bin/env python2.3\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
+ self.write_script(
+ dir,
+ "script1.py",
+ (
+ "#! /usr/bin/env python2.3\n"
+ "# bogus script w/ Python sh-bang\n"
+ "pass\n"
+ ),
+ )
expected.append("script2.py")
- self.write_script(dir, "script2.py",
- ("#!/usr/bin/python\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
+ self.write_script(
+ dir,
+ "script2.py",
+ ("#!/usr/bin/python\n" "# bogus script w/ Python sh-bang\n" "pass\n"),
+ )
expected.append("shell.sh")
- self.write_script(dir, "shell.sh",
- ("#!/bin/sh\n"
- "# bogus shell script w/ sh-bang\n"
- "exit 0\n"))
+ self.write_script(
+ dir,
+ "shell.sh",
+ ("#!/bin/sh\n" "# bogus shell script w/ sh-bang\n" "exit 0\n"),
+ )
return expected
def write_script(self, dir, name, text):
@@ -82,10 +87,9 @@ class BuildScriptsTestCase(support.TempdirManager,
target = self.mkdtemp()
expected = self.write_sample_scripts(source)
-
- cmd = self.get_build_scripts_cmd(target,
- [os.path.join(source, fn)
- for fn in expected])
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, fn) for fn in expected]
+ )
cmd.finalize_options()
# http://bugs.python.org/issue4524
@@ -105,8 +109,10 @@ class BuildScriptsTestCase(support.TempdirManager,
for name in expected:
self.assertIn(name, built)
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(BuildScriptsTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_check.py b/setuptools/_distutils/tests/test_check.py
index 2414d6eb..424c5e08 100644
--- a/setuptools/_distutils/tests/test_check.py
+++ b/setuptools/_distutils/tests/test_check.py
@@ -17,10 +17,7 @@ except ImportError:
HERE = os.path.dirname(__file__)
-class CheckTestCase(support.LoggingSilencer,
- support.TempdirManager,
- unittest.TestCase):
-
+class CheckTestCase(support.LoggingSilencer, support.TempdirManager, unittest.TestCase):
def _run(self, metadata=None, cwd=None, **options):
if metadata is None:
metadata = {}
@@ -48,9 +45,13 @@ class CheckTestCase(support.LoggingSilencer,
# now let's add the required fields
# and run it again, to make sure we don't get
# any warning anymore
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx'}
+ metadata = {
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ }
cmd = self._run(metadata)
self.assertEqual(cmd._warnings, 0)
@@ -63,11 +64,15 @@ class CheckTestCase(support.LoggingSilencer,
self.assertEqual(cmd._warnings, 0)
# now a test with non-ASCII characters
- metadata = {'url': 'xxx', 'author': '\u00c9ric',
- 'author_email': 'xxx', 'name': 'xxx',
- 'version': 'xxx',
- 'description': 'Something about esszet \u00df',
- 'long_description': 'More things about esszet \u00df'}
+ metadata = {
+ 'url': 'xxx',
+ 'author': '\u00c9ric',
+ 'author_email': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'description': 'Something about esszet \u00df',
+ 'long_description': 'More things about esszet \u00df',
+ }
cmd = self._run(metadata)
self.assertEqual(cmd._warnings, 0)
@@ -75,9 +80,12 @@ class CheckTestCase(support.LoggingSilencer,
for kind in ("author", "maintainer"):
# ensure no warning when author_email or maintainer_email is given
# (the spec allows these fields to take the form "Name <email>")
- metadata = {'url': 'xxx',
- kind + '_email': 'Name <name@email.com>',
- 'name': 'xxx', 'version': 'xxx'}
+ metadata = {
+ 'url': 'xxx',
+ kind + '_email': 'Name <name@email.com>',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ }
cmd = self._run(metadata)
self.assertEqual(cmd._warnings, 0)
@@ -117,12 +125,20 @@ class CheckTestCase(support.LoggingSilencer,
self.assertEqual(cmd._warnings, 1)
# let's see if we have an error with strict=1
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx',
- 'long_description': broken_rest}
- self.assertRaises(DistutilsSetupError, self._run, metadata,
- **{'strict': 1, 'restructuredtext': 1})
+ metadata = {
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'long_description': broken_rest,
+ }
+ self.assertRaises(
+ DistutilsSetupError,
+ self._run,
+ metadata,
+ **{'strict': 1, 'restructuredtext': 1}
+ )
# and non-broken rest, including a non-ASCII character to test #12114
metadata['long_description'] = 'title\n=====\n\ntest \u00df'
@@ -139,22 +155,30 @@ class CheckTestCase(support.LoggingSilencer,
# Don't fail if there is a `code` or `code-block` directive
example_rst_docs = []
- example_rst_docs.append(textwrap.dedent("""\
+ example_rst_docs.append(
+ textwrap.dedent(
+ """\
Here's some code:
.. code:: python
def foo():
pass
- """))
- example_rst_docs.append(textwrap.dedent("""\
+ """
+ )
+ )
+ example_rst_docs.append(
+ textwrap.dedent(
+ """\
Here's some code:
.. code-block:: python
def foo():
pass
- """))
+ """
+ )
+ )
for rest_with_code in example_rst_docs:
pkg_info, dist = self.create_dist(long_description=rest_with_code)
@@ -166,19 +190,20 @@ class CheckTestCase(support.LoggingSilencer,
else:
self.assertEqual(len(msgs), 1)
self.assertEqual(
- str(msgs[0][1]),
- 'Cannot analyze code. Pygments package not found.'
+ str(msgs[0][1]), 'Cannot analyze code. Pygments package not found.'
)
def test_check_all(self):
metadata = {'url': 'xxx', 'author': 'xxx'}
- self.assertRaises(DistutilsSetupError, self._run,
- {}, **{'strict': 1,
- 'restructuredtext': 1})
+ self.assertRaises(
+ DistutilsSetupError, self._run, {}, **{'strict': 1, 'restructuredtext': 1}
+ )
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(CheckTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_clean.py b/setuptools/_distutils/tests/test_clean.py
index 92367499..92e58f78 100644
--- a/setuptools/_distutils/tests/test_clean.py
+++ b/setuptools/_distutils/tests/test_clean.py
@@ -6,18 +6,23 @@ from distutils.command.clean import clean
from distutils.tests import support
from test.support import run_unittest
-class cleanTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
+class cleanTestCase(support.TempdirManager, support.LoggingSilencer, unittest.TestCase):
def test_simple_run(self):
pkg_dir, dist = self.create_dist()
cmd = clean(dist)
# let's add some elements clean should remove
- dirs = [(d, os.path.join(pkg_dir, d))
- for d in ('build_temp', 'build_lib', 'bdist_base',
- 'build_scripts', 'build_base')]
+ dirs = [
+ (d, os.path.join(pkg_dir, d))
+ for d in (
+ 'build_temp',
+ 'build_lib',
+ 'bdist_base',
+ 'build_scripts',
+ 'build_base',
+ )
+ ]
for name, path in dirs:
os.mkdir(path)
@@ -34,16 +39,17 @@ class cleanTestCase(support.TempdirManager,
# make sure the files where removed
for name, path in dirs:
- self.assertFalse(os.path.exists(path),
- '%s was not removed' % path)
+ self.assertFalse(os.path.exists(path), '%s was not removed' % path)
# let's run the command again (should spit warnings but succeed)
cmd.all = 1
cmd.ensure_finalized()
cmd.run()
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(cleanTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_cmd.py b/setuptools/_distutils/tests/test_cmd.py
index 2319214a..12a8a20c 100644
--- a/setuptools/_distutils/tests/test_cmd.py
+++ b/setuptools/_distutils/tests/test_cmd.py
@@ -8,12 +8,13 @@ from distutils.dist import Distribution
from distutils.errors import DistutilsOptionError
from distutils import debug
+
class MyCmd(Command):
def initialize_options(self):
pass
-class CommandTestCase(unittest.TestCase):
+class CommandTestCase(unittest.TestCase):
def setUp(self):
dist = Distribution()
self.cmd = MyCmd(dist)
@@ -28,11 +29,13 @@ class CommandTestCase(unittest.TestCase):
cmd.ensure_string_list('yes_string_list')
cmd.ensure_string_list('yes_string_list2')
- self.assertRaises(DistutilsOptionError,
- cmd.ensure_string_list, 'not_string_list')
+ self.assertRaises(
+ DistutilsOptionError, cmd.ensure_string_list, 'not_string_list'
+ )
- self.assertRaises(DistutilsOptionError,
- cmd.ensure_string_list, 'not_string_list2')
+ self.assertRaises(
+ DistutilsOptionError, cmd.ensure_string_list, 'not_string_list2'
+ )
cmd.option1 = 'ok,dok'
cmd.ensure_string_list('option1')
@@ -42,21 +45,21 @@ class CommandTestCase(unittest.TestCase):
cmd.ensure_string_list('option2')
cmd.option3 = ['ok', 2]
- self.assertRaises(DistutilsOptionError, cmd.ensure_string_list,
- 'option3')
-
+ self.assertRaises(DistutilsOptionError, cmd.ensure_string_list, 'option3')
def test_make_file(self):
cmd = self.cmd
# making sure it raises when infiles is not a string or a list/tuple
- self.assertRaises(TypeError, cmd.make_file,
- infiles=1, outfile='', func='func', args=())
+ self.assertRaises(
+ TypeError, cmd.make_file, infiles=1, outfile='', func='func', args=()
+ )
# making sure execute gets called properly
def _execute(func, args, exec_msg, level):
self.assertEqual(exec_msg, 'generating out from in')
+
cmd.force = True
cmd.execute = _execute
cmd.make_file(infiles='in', outfile='out', func='func', args=())
@@ -64,8 +67,10 @@ class CommandTestCase(unittest.TestCase):
def test_dump_options(self):
msgs = []
+
def _announce(msg, level):
msgs.append(msg)
+
cmd = self.cmd
cmd.announce = _announce
cmd.option1 = 1
@@ -73,8 +78,7 @@ class CommandTestCase(unittest.TestCase):
cmd.user_options = [('option1', '', ''), ('option2', '', '')]
cmd.dump_options()
- wanted = ["command options for 'MyCmd':", ' option1 = 1',
- ' option2 = 1']
+ wanted = ["command options for 'MyCmd':", ' option1 = 1', ' option2 = 1']
self.assertEqual(msgs, wanted)
def test_ensure_string(self):
@@ -119,8 +123,10 @@ class CommandTestCase(unittest.TestCase):
finally:
debug.DEBUG = False
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(CommandTestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_config.py b/setuptools/_distutils/tests/test_config.py
index 27bd9d44..a4b48509 100644
--- a/setuptools/_distutils/tests/test_config.py
+++ b/setuptools/_distutils/tests/test_config.py
@@ -50,11 +50,12 @@ password:xxx
"""
-class BasePyPIRCCommandTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
+class BasePyPIRCCommandTestCase(
+ support.TempdirManager,
+ support.LoggingSilencer,
+ support.EnvironGuard,
+ unittest.TestCase,
+):
def setUp(self):
"""Patches the environment."""
super(BasePyPIRCCommandTestCase, self).setUp()
@@ -67,8 +68,10 @@ class BasePyPIRCCommandTestCase(support.TempdirManager,
class command(PyPIRCCommand):
def __init__(self, dist):
super().__init__(dist)
+
def initialize_options(self):
pass
+
finalize_options = initialize_options
self._cmd = command
@@ -81,7 +84,6 @@ class BasePyPIRCCommandTestCase(support.TempdirManager,
class PyPIRCCommandTestCase(BasePyPIRCCommandTestCase):
-
def test_server_registration(self):
# This test makes sure PyPIRCCommand knows how to:
# 1. handle several sections in .pypirc
@@ -93,18 +95,26 @@ class PyPIRCCommandTestCase(BasePyPIRCCommandTestCase):
config = cmd._read_pypirc()
config = list(sorted(config.items()))
- waited = [('password', 'secret'), ('realm', 'pypi'),
- ('repository', 'https://upload.pypi.org/legacy/'),
- ('server', 'server1'), ('username', 'me')]
+ waited = [
+ ('password', 'secret'),
+ ('realm', 'pypi'),
+ ('repository', 'https://upload.pypi.org/legacy/'),
+ ('server', 'server1'),
+ ('username', 'me'),
+ ]
self.assertEqual(config, waited)
# old format
self.write_file(self.rc, PYPIRC_OLD)
config = cmd._read_pypirc()
config = list(sorted(config.items()))
- waited = [('password', 'secret'), ('realm', 'pypi'),
- ('repository', 'https://upload.pypi.org/legacy/'),
- ('server', 'server-login'), ('username', 'tarek')]
+ waited = [
+ ('password', 'secret'),
+ ('realm', 'pypi'),
+ ('repository', 'https://upload.pypi.org/legacy/'),
+ ('server', 'server-login'),
+ ('username', 'tarek'),
+ ]
self.assertEqual(config, waited)
def test_server_empty_registration(self):
@@ -128,14 +138,19 @@ class PyPIRCCommandTestCase(BasePyPIRCCommandTestCase):
config = cmd._read_pypirc()
config = list(sorted(config.items()))
- waited = [('password', 'yh^%#rest-of-my-password'), ('realm', 'pypi'),
- ('repository', 'https://upload.pypi.org/legacy/'),
- ('server', 'server3'), ('username', 'cbiggles')]
+ waited = [
+ ('password', 'yh^%#rest-of-my-password'),
+ ('realm', 'pypi'),
+ ('repository', 'https://upload.pypi.org/legacy/'),
+ ('server', 'server3'),
+ ('username', 'cbiggles'),
+ ]
self.assertEqual(config, waited)
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(PyPIRCCommandTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_config_cmd.py b/setuptools/_distutils/tests/test_config_cmd.py
index 2c84719a..0c1a9d25 100644
--- a/setuptools/_distutils/tests/test_config_cmd.py
+++ b/setuptools/_distutils/tests/test_config_cmd.py
@@ -2,18 +2,16 @@
import unittest
import os
import sys
-from test.support import run_unittest
-
-from .py35compat import missing_compiler_executable
+from test.support import run_unittest, missing_compiler_executable
from distutils.command.config import dump_file, config
from distutils.tests import support
from distutils import log
-class ConfigTestCase(support.LoggingSilencer,
- support.TempdirManager,
- unittest.TestCase):
+class ConfigTestCase(
+ support.LoggingSilencer, support.TempdirManager, unittest.TestCase
+):
def _info(self, msg, *args):
for line in msg.splitlines():
self._logs.append(line)
@@ -37,7 +35,7 @@ class ConfigTestCase(support.LoggingSilencer,
f.close()
dump_file(this_file, 'I am the header')
- self.assertEqual(len(self._logs), numlines+1)
+ self.assertEqual(len(self._logs), numlines + 1)
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
def test_search_cpp(self):
@@ -49,7 +47,9 @@ class ConfigTestCase(support.LoggingSilencer,
cmd._check_compiler()
compiler = cmd.compiler
if sys.platform[:3] == "aix" and "xlc" in compiler.preprocessor[0].lower():
- self.skipTest('xlc: The -E option overrides the -P, -o, and -qsyntaxonly options')
+ self.skipTest(
+ 'xlc: The -E option overrides the -P, -o, and -qsyntaxonly options'
+ )
# simple pattern searches
match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
@@ -91,8 +91,10 @@ class ConfigTestCase(support.LoggingSilencer,
for f in (f1, f2):
self.assertFalse(os.path.exists(f))
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(ConfigTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_core.py b/setuptools/_distutils/tests/test_core.py
index 7270d699..23402fb8 100644
--- a/setuptools/_distutils/tests/test_core.py
+++ b/setuptools/_distutils/tests/test_core.py
@@ -56,8 +56,8 @@ if __name__ == "__main__":
main()
"""
-class CoreTestCase(support.EnvironGuard, unittest.TestCase):
+class CoreTestCase(support.EnvironGuard, unittest.TestCase):
def setUp(self):
super(CoreTestCase, self).setUp()
self.old_stdout = sys.stdout
@@ -90,21 +90,18 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
def test_run_setup_provides_file(self):
# Make sure the script can use __file__; if that's missing, the test
# setup.py script will raise NameError.
- distutils.core.run_setup(
- self.write_setup(setup_using___file__))
+ distutils.core.run_setup(self.write_setup(setup_using___file__))
def test_run_setup_preserves_sys_argv(self):
# Make sure run_setup does not clobber sys.argv
argv_copy = sys.argv.copy()
- distutils.core.run_setup(
- self.write_setup(setup_does_nothing))
+ distutils.core.run_setup(self.write_setup(setup_does_nothing))
self.assertEqual(sys.argv, argv_copy)
def test_run_setup_defines_subclass(self):
# Make sure the script can use __file__; if that's missing, the test
# setup.py script will raise NameError.
- dist = distutils.core.run_setup(
- self.write_setup(setup_defines_subclass))
+ dist = distutils.core.run_setup(self.write_setup(setup_defines_subclass))
install = dist.get_command_obj('install')
self.assertIn('cmd', install.sub_commands)
@@ -118,8 +115,7 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
# Create a directory and write the setup.py file there:
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))
+ distutils.core.run_setup(self.write_setup(setup_prints_cwd, path=setup_py))
output = sys.stdout.getvalue()
if output.endswith("\n"):
@@ -128,14 +124,16 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
def test_run_setup_within_if_main(self):
dist = distutils.core.run_setup(
- self.write_setup(setup_within_if_main), stop_after="config")
+ self.write_setup(setup_within_if_main), stop_after="config"
+ )
self.assertIsInstance(dist, Distribution)
self.assertEqual(dist.get_name(), "setup_within_if_main")
def test_run_commands(self):
sys.argv = ['setup.py', 'build']
dist = distutils.core.run_setup(
- self.write_setup(setup_within_if_main), stop_after="commandline")
+ self.write_setup(setup_within_if_main), stop_after="commandline"
+ )
self.assertNotIn('build', dist.have_run)
distutils.core.run_commands(dist)
self.assertIn('build', dist.have_run)
@@ -158,8 +156,10 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
wanted = "options (after parsing config files):\n"
self.assertEqual(stdout.readlines()[0], wanted)
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(CoreTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_cygwinccompiler.py b/setuptools/_distutils/tests/test_cygwinccompiler.py
index 8715a535..b3c164ed 100644
--- a/setuptools/_distutils/tests/test_cygwinccompiler.py
+++ b/setuptools/_distutils/tests/test_cygwinccompiler.py
@@ -4,39 +4,58 @@ import sys
import os
from test.support import run_unittest
-from distutils.cygwinccompiler import (check_config_h,
- CONFIG_H_OK, CONFIG_H_NOTOK,
- CONFIG_H_UNCERTAIN,
- get_msvcr)
+from distutils.cygwinccompiler import (
+ check_config_h,
+ CONFIG_H_OK,
+ CONFIG_H_NOTOK,
+ CONFIG_H_UNCERTAIN,
+ get_msvcr,
+)
from distutils.tests import support
-class CygwinCCompilerTestCase(support.TempdirManager,
- unittest.TestCase):
-
+class CygwinCCompilerTestCase(support.TempdirManager, unittest.TestCase):
def setUp(self):
super(CygwinCCompilerTestCase, self).setUp()
self.version = sys.version
self.python_h = os.path.join(self.mkdtemp(), 'python.h')
from distutils import sysconfig
+
self.old_get_config_h_filename = sysconfig.get_config_h_filename
sysconfig.get_config_h_filename = self._get_config_h_filename
def tearDown(self):
sys.version = self.version
from distutils import sysconfig
+
sysconfig.get_config_h_filename = self.old_get_config_h_filename
super(CygwinCCompilerTestCase, self).tearDown()
def _get_config_h_filename(self):
return self.python_h
+ @unittest.skipIf(sys.platform != "cygwin", "Not running on Cygwin")
+ @unittest.skipIf(
+ not os.path.exists("/usr/lib/libbash.dll.a"), "Don't know a linkable library"
+ )
+ def test_find_library_file(self):
+ from distutils.cygwinccompiler import CygwinCCompiler
+
+ compiler = CygwinCCompiler()
+ link_name = "bash"
+ linkable_file = compiler.find_library_file(["/usr/lib"], link_name)
+ self.assertIsNotNone(linkable_file)
+ self.assertTrue(os.path.exists(linkable_file))
+ self.assertEquals(linkable_file, "/usr/lib/lib{:s}.dll.a".format(link_name))
+
def test_check_config_h(self):
# check_config_h looks for "GCC" in sys.version first
# returns CONFIG_H_OK if found
- sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) \n[GCC '
- '4.0.1 (Apple Computer, Inc. build 5370)]')
+ sys.version = (
+ '2.6.1 (r261:67515, Dec 6 2008, 16:42:21) \n[GCC '
+ '4.0.1 (Apple Computer, Inc. build 5370)]'
+ )
self.assertEqual(check_config_h()[0], CONFIG_H_OK)
@@ -57,40 +76,49 @@ class CygwinCCompilerTestCase(support.TempdirManager,
def test_get_msvcr(self):
# none
- sys.version = ('2.6.1 (r261:67515, Dec 6 2008, 16:42:21) '
- '\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]')
+ sys.version = (
+ '2.6.1 (r261:67515, Dec 6 2008, 16:42:21) '
+ '\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]'
+ )
self.assertEqual(get_msvcr(), None)
# MSVC 7.0
- sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
- '[MSC v.1300 32 bits (Intel)]')
+ sys.version = (
+ '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' '[MSC v.1300 32 bits (Intel)]'
+ )
self.assertEqual(get_msvcr(), ['msvcr70'])
# MSVC 7.1
- sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
- '[MSC v.1310 32 bits (Intel)]')
+ sys.version = (
+ '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' '[MSC v.1310 32 bits (Intel)]'
+ )
self.assertEqual(get_msvcr(), ['msvcr71'])
# VS2005 / MSVC 8.0
- sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
- '[MSC v.1400 32 bits (Intel)]')
+ sys.version = (
+ '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' '[MSC v.1400 32 bits (Intel)]'
+ )
self.assertEqual(get_msvcr(), ['msvcr80'])
# VS2008 / MSVC 9.0
- sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
- '[MSC v.1500 32 bits (Intel)]')
+ sys.version = (
+ '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' '[MSC v.1500 32 bits (Intel)]'
+ )
self.assertEqual(get_msvcr(), ['msvcr90'])
-
+
sys.version = '3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 18:46:30) [MSC v.1929 32 bit (Intel)]'
self.assertEqual(get_msvcr(), ['ucrt', 'vcruntime140'])
# unknown
- sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
- '[MSC v.2000 32 bits (Intel)]')
+ sys.version = (
+ '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) ' '[MSC v.2000 32 bits (Intel)]'
+ )
self.assertRaises(ValueError, get_msvcr)
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(CygwinCCompilerTestCase)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_dep_util.py b/setuptools/_distutils/tests/test_dep_util.py
index 0d52740a..89ae05d1 100644
--- a/setuptools/_distutils/tests/test_dep_util.py
+++ b/setuptools/_distutils/tests/test_dep_util.py
@@ -7,8 +7,8 @@ from distutils.errors import DistutilsFileError
from distutils.tests import support
from test.support import run_unittest
-class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
+class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
def test_newer(self):
tmpdir = self.mkdtemp()
@@ -36,14 +36,13 @@ class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
os.mkdir(targets)
one = os.path.join(sources, 'one')
two = os.path.join(sources, 'two')
- three = os.path.abspath(__file__) # I am the old file
+ three = os.path.abspath(__file__) # I am the old file
four = os.path.join(targets, 'four')
self.write_file(one)
self.write_file(two)
self.write_file(four)
- self.assertEqual(newer_pairwise([one, two], [three, four]),
- ([one],[three]))
+ self.assertEqual(newer_pairwise([one, two], [three, four]), ([one], [three]))
def test_newer_group(self):
tmpdir = self.mkdtemp()
@@ -66,15 +65,14 @@ class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
os.remove(one)
self.assertRaises(OSError, newer_group, [one, two, old_file], three)
- self.assertFalse(newer_group([one, two, old_file], three,
- missing='ignore'))
+ self.assertFalse(newer_group([one, two, old_file], three, missing='ignore'))
- self.assertTrue(newer_group([one, two, old_file], three,
- missing='newer'))
+ self.assertTrue(newer_group([one, two, old_file], three, missing='newer'))
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(DepUtilTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_dir_util.py b/setuptools/_distutils/tests/test_dir_util.py
index 1b1f3bbb..a1f9a240 100644
--- a/setuptools/_distutils/tests/test_dir_util.py
+++ b/setuptools/_distutils/tests/test_dir_util.py
@@ -6,8 +6,13 @@ import sys
from unittest.mock import patch
from distutils import dir_util, errors
-from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree,
- ensure_relative)
+from distutils.dir_util import (
+ mkpath,
+ remove_tree,
+ create_tree,
+ copy_tree,
+ ensure_relative,
+)
from distutils import log
from distutils.tests import support
@@ -15,7 +20,6 @@ from test.support import run_unittest
class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
-
def _log(self, msg, *args):
if len(args) > 0:
self._logs.append(msg % args)
@@ -44,8 +48,7 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
remove_tree(self.root_target, verbose=0)
mkpath(self.target, verbose=1)
- wanted = ['creating %s' % self.root_target,
- 'creating %s' % self.target]
+ wanted = ['creating %s' % self.root_target, 'creating %s' % self.target]
self.assertEqual(self._logs, wanted)
self._logs = []
@@ -53,18 +56,18 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
wanted = ["removing '%s' (and everything under it)" % self.root_target]
self.assertEqual(self._logs, wanted)
- @unittest.skipIf(sys.platform.startswith('win'),
- "This test is only appropriate for POSIX-like systems.")
+ @unittest.skipIf(
+ sys.platform.startswith('win'),
+ "This test is only appropriate for POSIX-like systems.",
+ )
def test_mkpath_with_custom_mode(self):
# Get and set the current umask value for testing mode bits.
umask = os.umask(0o002)
os.umask(umask)
mkpath(self.target, 0o700)
- self.assertEqual(
- stat.S_IMODE(os.stat(self.target).st_mode), 0o700 & ~umask)
+ self.assertEqual(stat.S_IMODE(os.stat(self.target).st_mode), 0o700 & ~umask)
mkpath(self.target2, 0o555)
- self.assertEqual(
- stat.S_IMODE(os.stat(self.target2).st_mode), 0o555 & ~umask)
+ self.assertEqual(stat.S_IMODE(os.stat(self.target2).st_mode), 0o555 & ~umask)
def test_create_tree_verbosity(self):
@@ -118,7 +121,7 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
if os.sep == '/':
self.assertEqual(ensure_relative('/home/foo'), 'home/foo')
self.assertEqual(ensure_relative('some/path'), 'some/path')
- else: # \\
+ else: # \\
self.assertEqual(ensure_relative('c:\\home\\foo'), 'c:home\\foo')
self.assertEqual(ensure_relative('home\\foo'), 'home\\foo')
@@ -126,8 +129,9 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
"""
An exception in listdir should raise a DistutilsFileError
"""
- with patch("os.listdir", side_effect=OSError()), \
- self.assertRaises(errors.DistutilsFileError):
+ with patch("os.listdir", side_effect=OSError()), self.assertRaises(
+ errors.DistutilsFileError
+ ):
src = self.tempdirs[-1]
dir_util.copy_tree(src, None)
@@ -135,5 +139,6 @@ class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(DirUtilTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_dist.py b/setuptools/_distutils/tests/test_dist.py
index 9132bc04..6520a46d 100644
--- a/setuptools/_distutils/tests/test_dist.py
+++ b/setuptools/_distutils/tests/test_dist.py
@@ -11,9 +11,7 @@ from unittest import mock
from distutils.dist import Distribution, fix_help_options
from distutils.cmd import Command
-from test.support import (
- captured_stdout, captured_stderr, run_unittest
-)
+from test.support import captured_stdout, captured_stderr, run_unittest
from .py38compat import TESTFN
from distutils.tests import support
from distutils import log
@@ -42,11 +40,12 @@ class TestDistribution(Distribution):
return self._config_files
-class DistributionTestCase(support.LoggingSilencer,
- support.TempdirManager,
- support.EnvironGuard,
- unittest.TestCase):
-
+class DistributionTestCase(
+ support.LoggingSilencer,
+ support.TempdirManager,
+ support.EnvironGuard,
+ unittest.TestCase,
+):
def setUp(self):
super(DistributionTestCase, self).setUp()
self.argv = sys.argv, sys.argv[:]
@@ -71,15 +70,21 @@ class DistributionTestCase(support.LoggingSilencer,
def test_command_packages_cmdline(self):
from distutils.tests.test_dist import test_dist
- sys.argv.extend(["--command-packages",
- "foo.bar,distutils.tests",
- "test_dist",
- "-Ssometext",
- ])
+
+ sys.argv.extend(
+ [
+ "--command-packages",
+ "foo.bar,distutils.tests",
+ "test_dist",
+ "-Ssometext",
+ ]
+ )
d = self.create_distribution()
# let's actually try to load our test command:
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "foo.bar", "distutils.tests"])
+ self.assertEqual(
+ d.get_command_packages(),
+ ["distutils.command", "foo.bar", "distutils.tests"],
+ )
cmd = d.get_command_obj("test_dist")
self.assertIsInstance(cmd, test_dist)
self.assertEqual(cmd.sample_option, "sometext")
@@ -95,20 +100,25 @@ class DistributionTestCase(support.LoggingSilencer,
fakepath = '/somedir'
with open(TESTFN, "w") as f:
- print(("[install]\n"
- "install-base = {0}\n"
- "install-platbase = {0}\n"
- "install-lib = {0}\n"
- "install-platlib = {0}\n"
- "install-purelib = {0}\n"
- "install-headers = {0}\n"
- "install-scripts = {0}\n"
- "install-data = {0}\n"
- "prefix = {0}\n"
- "exec-prefix = {0}\n"
- "home = {0}\n"
- "user = {0}\n"
- "root = {0}").format(fakepath), file=f)
+ print(
+ (
+ "[install]\n"
+ "install-base = {0}\n"
+ "install-platbase = {0}\n"
+ "install-lib = {0}\n"
+ "install-platlib = {0}\n"
+ "install-purelib = {0}\n"
+ "install-headers = {0}\n"
+ "install-scripts = {0}\n"
+ "install-data = {0}\n"
+ "prefix = {0}\n"
+ "exec-prefix = {0}\n"
+ "home = {0}\n"
+ "user = {0}\n"
+ "root = {0}"
+ ).format(fakepath),
+ file=f,
+ )
# Base case: Not in a Virtual Environment
with mock.patch.multiple(sys, prefix='/a', base_prefix='/a') as values:
@@ -133,8 +143,8 @@ class DistributionTestCase(support.LoggingSilencer,
}
self.assertEqual(
- sorted(d.command_options.get('install').keys()),
- sorted(result_dict.keys()))
+ sorted(d.command_options.get('install').keys()), sorted(result_dict.keys())
+ )
for (key, value) in d.command_options.get('install').items():
self.assertEqual(value, result_dict[key])
@@ -157,14 +167,14 @@ class DistributionTestCase(support.LoggingSilencer,
f.close()
d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "foo.bar", "splat"])
+ self.assertEqual(
+ d.get_command_packages(), ["distutils.command", "foo.bar", "splat"]
+ )
# ensure command line overrides config:
sys.argv[1:] = ["--command-packages", "spork", "build"]
d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "spork"])
+ self.assertEqual(d.get_command_packages(), ["distutils.command", "spork"])
# Setting --command-packages to '' should cause the default to
# be used even if a config file specified something else:
@@ -184,16 +194,21 @@ class DistributionTestCase(support.LoggingSilencer,
self.addCleanup(setattr, warnings, 'warn', warnings.warn)
warnings.warn = _warn
- dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx',
- 'version': 'xxx', 'url': 'xxxx',
- 'options': {}})
+ dist = Distribution(
+ attrs={
+ 'author': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'url': 'xxxx',
+ 'options': {},
+ }
+ )
self.assertEqual(len(warns), 0)
self.assertNotIn('options', dir(dist))
def test_finalize_options(self):
- attrs = {'keywords': 'one,two',
- 'platforms': 'one,two'}
+ attrs = {'keywords': 'one,two', 'platforms': 'one,two'}
dist = Distribution(attrs=attrs)
dist.finalize_options()
@@ -202,8 +217,7 @@ class DistributionTestCase(support.LoggingSilencer,
self.assertEqual(dist.metadata.platforms, ['one', 'two'])
self.assertEqual(dist.metadata.keywords, ['one', 'two'])
- attrs = {'keywords': 'foo bar',
- 'platforms': 'foo bar'}
+ attrs = {'keywords': 'foo bar', 'platforms': 'foo bar'}
dist = Distribution(attrs=attrs)
dist.finalize_options()
self.assertEqual(dist.metadata.platforms, ['foo bar'])
@@ -214,8 +228,7 @@ class DistributionTestCase(support.LoggingSilencer,
self.assertEqual(dist.command_packages, None)
cmds = dist.get_command_packages()
self.assertEqual(cmds, ['distutils.command'])
- self.assertEqual(dist.command_packages,
- ['distutils.command'])
+ self.assertEqual(dist.command_packages, ['distutils.command'])
dist.command_packages = 'one,two'
cmds = dist.get_command_packages()
@@ -228,7 +241,6 @@ class DistributionTestCase(support.LoggingSilencer,
kwargs = {'level': 'ok2'}
self.assertRaises(ValueError, dist.announce, args, kwargs)
-
def test_find_config_files_disable(self):
# Ticket #1180: Allow user to disable their home config file.
temp_home = self.mkdtemp()
@@ -255,11 +267,10 @@ class DistributionTestCase(support.LoggingSilencer,
os.path.expanduser = old_expander
# make sure --no-user-cfg disables the user cfg file
- self.assertEqual(len(all_files)-1, len(files))
+ self.assertEqual(len(all_files) - 1, len(files))
-class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
- unittest.TestCase):
+class MetadataTestCase(support.TempdirManager, support.EnvironGuard, unittest.TestCase):
def setUp(self):
super(MetadataTestCase, self).setUp()
self.argv = sys.argv, sys.argv[:]
@@ -275,8 +286,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
return sio.getvalue()
def test_simple_metadata(self):
- attrs = {"name": "package",
- "version": "1.0"}
+ attrs = {"name": "package", "version": "1.0"}
dist = Distribution(attrs)
meta = self.format_metadata(dist)
self.assertIn("Metadata-Version: 1.0", meta)
@@ -285,34 +295,35 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertNotIn("obsoletes:", meta.lower())
def test_provides(self):
- attrs = {"name": "package",
- "version": "1.0",
- "provides": ["package", "package.sub"]}
+ attrs = {
+ "name": "package",
+ "version": "1.0",
+ "provides": ["package", "package.sub"],
+ }
dist = Distribution(attrs)
- self.assertEqual(dist.metadata.get_provides(),
- ["package", "package.sub"])
- self.assertEqual(dist.get_provides(),
- ["package", "package.sub"])
+ self.assertEqual(dist.metadata.get_provides(), ["package", "package.sub"])
+ self.assertEqual(dist.get_provides(), ["package", "package.sub"])
meta = self.format_metadata(dist)
self.assertIn("Metadata-Version: 1.1", meta)
self.assertNotIn("requires:", meta.lower())
self.assertNotIn("obsoletes:", meta.lower())
def test_provides_illegal(self):
- self.assertRaises(ValueError, Distribution,
- {"name": "package",
- "version": "1.0",
- "provides": ["my.pkg (splat)"]})
+ self.assertRaises(
+ ValueError,
+ Distribution,
+ {"name": "package", "version": "1.0", "provides": ["my.pkg (splat)"]},
+ )
def test_requires(self):
- attrs = {"name": "package",
- "version": "1.0",
- "requires": ["other", "another (==1.0)"]}
+ attrs = {
+ "name": "package",
+ "version": "1.0",
+ "requires": ["other", "another (==1.0)"],
+ }
dist = Distribution(attrs)
- self.assertEqual(dist.metadata.get_requires(),
- ["other", "another (==1.0)"])
- self.assertEqual(dist.get_requires(),
- ["other", "another (==1.0)"])
+ self.assertEqual(dist.metadata.get_requires(), ["other", "another (==1.0)"])
+ self.assertEqual(dist.get_requires(), ["other", "another (==1.0)"])
meta = self.format_metadata(dist)
self.assertIn("Metadata-Version: 1.1", meta)
self.assertNotIn("provides:", meta.lower())
@@ -321,27 +332,26 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertNotIn("obsoletes:", meta.lower())
def test_requires_illegal(self):
- self.assertRaises(ValueError, Distribution,
- {"name": "package",
- "version": "1.0",
- "requires": ["my.pkg (splat)"]})
+ self.assertRaises(
+ ValueError,
+ Distribution,
+ {"name": "package", "version": "1.0", "requires": ["my.pkg (splat)"]},
+ )
def test_requires_to_list(self):
- attrs = {"name": "package",
- "requires": iter(["other"])}
+ attrs = {"name": "package", "requires": iter(["other"])}
dist = Distribution(attrs)
self.assertIsInstance(dist.metadata.requires, list)
-
def test_obsoletes(self):
- attrs = {"name": "package",
- "version": "1.0",
- "obsoletes": ["other", "another (<1.0)"]}
+ attrs = {
+ "name": "package",
+ "version": "1.0",
+ "obsoletes": ["other", "another (<1.0)"],
+ }
dist = Distribution(attrs)
- self.assertEqual(dist.metadata.get_obsoletes(),
- ["other", "another (<1.0)"])
- self.assertEqual(dist.get_obsoletes(),
- ["other", "another (<1.0)"])
+ self.assertEqual(dist.metadata.get_obsoletes(), ["other", "another (<1.0)"])
+ self.assertEqual(dist.get_obsoletes(), ["other", "another (<1.0)"])
meta = self.format_metadata(dist)
self.assertIn("Metadata-Version: 1.1", meta)
self.assertNotIn("provides:", meta.lower())
@@ -350,48 +360,59 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertIn("Obsoletes: another (<1.0)", meta)
def test_obsoletes_illegal(self):
- self.assertRaises(ValueError, Distribution,
- {"name": "package",
- "version": "1.0",
- "obsoletes": ["my.pkg (splat)"]})
+ self.assertRaises(
+ ValueError,
+ Distribution,
+ {"name": "package", "version": "1.0", "obsoletes": ["my.pkg (splat)"]},
+ )
def test_obsoletes_to_list(self):
- attrs = {"name": "package",
- "obsoletes": iter(["other"])}
+ attrs = {"name": "package", "obsoletes": iter(["other"])}
dist = Distribution(attrs)
self.assertIsInstance(dist.metadata.obsoletes, list)
def test_classifier(self):
- attrs = {'name': 'Boa', 'version': '3.0',
- 'classifiers': ['Programming Language :: Python :: 3']}
+ attrs = {
+ 'name': 'Boa',
+ 'version': '3.0',
+ 'classifiers': ['Programming Language :: Python :: 3'],
+ }
dist = Distribution(attrs)
- self.assertEqual(dist.get_classifiers(),
- ['Programming Language :: Python :: 3'])
+ self.assertEqual(
+ dist.get_classifiers(), ['Programming Language :: Python :: 3']
+ )
meta = self.format_metadata(dist)
self.assertIn('Metadata-Version: 1.1', meta)
def test_classifier_invalid_type(self):
- attrs = {'name': 'Boa', 'version': '3.0',
- 'classifiers': ('Programming Language :: Python :: 3',)}
+ attrs = {
+ 'name': 'Boa',
+ 'version': '3.0',
+ 'classifiers': ('Programming Language :: Python :: 3',),
+ }
with captured_stderr() as error:
d = Distribution(attrs)
# should have warning about passing a non-list
self.assertIn('should be a list', error.getvalue())
# should be converted to a list
self.assertIsInstance(d.metadata.classifiers, list)
- self.assertEqual(d.metadata.classifiers,
- list(attrs['classifiers']))
+ self.assertEqual(d.metadata.classifiers, list(attrs['classifiers']))
def test_keywords(self):
- attrs = {'name': 'Monty', 'version': '1.0',
- 'keywords': ['spam', 'eggs', 'life of brian']}
+ attrs = {
+ 'name': 'Monty',
+ 'version': '1.0',
+ 'keywords': ['spam', 'eggs', 'life of brian'],
+ }
dist = Distribution(attrs)
- self.assertEqual(dist.get_keywords(),
- ['spam', 'eggs', 'life of brian'])
+ self.assertEqual(dist.get_keywords(), ['spam', 'eggs', 'life of brian'])
def test_keywords_invalid_type(self):
- attrs = {'name': 'Monty', 'version': '1.0',
- 'keywords': ('spam', 'eggs', 'life of brian')}
+ attrs = {
+ 'name': 'Monty',
+ 'version': '1.0',
+ 'keywords': ('spam', 'eggs', 'life of brian'),
+ }
with captured_stderr() as error:
d = Distribution(attrs)
# should have warning about passing a non-list
@@ -401,15 +422,20 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(d.metadata.keywords, list(attrs['keywords']))
def test_platforms(self):
- attrs = {'name': 'Monty', 'version': '1.0',
- 'platforms': ['GNU/Linux', 'Some Evil Platform']}
+ attrs = {
+ 'name': 'Monty',
+ 'version': '1.0',
+ 'platforms': ['GNU/Linux', 'Some Evil Platform'],
+ }
dist = Distribution(attrs)
- self.assertEqual(dist.get_platforms(),
- ['GNU/Linux', 'Some Evil Platform'])
+ self.assertEqual(dist.get_platforms(), ['GNU/Linux', 'Some Evil Platform'])
def test_platforms_invalid_types(self):
- attrs = {'name': 'Monty', 'version': '1.0',
- 'platforms': ('GNU/Linux', 'Some Evil Platform')}
+ attrs = {
+ 'name': 'Monty',
+ 'version': '1.0',
+ 'platforms': ('GNU/Linux', 'Some Evil Platform'),
+ }
with captured_stderr() as error:
d = Distribution(attrs)
# should have warning about passing a non-list
@@ -419,21 +445,24 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(d.metadata.platforms, list(attrs['platforms']))
def test_download_url(self):
- attrs = {'name': 'Boa', 'version': '3.0',
- 'download_url': 'http://example.org/boa'}
+ attrs = {
+ 'name': 'Boa',
+ 'version': '3.0',
+ 'download_url': 'http://example.org/boa',
+ }
dist = Distribution(attrs)
meta = self.format_metadata(dist)
self.assertIn('Metadata-Version: 1.1', meta)
def test_long_description(self):
- long_desc = textwrap.dedent("""\
+ long_desc = textwrap.dedent(
+ """\
example::
We start here
and continue here
- and end here.""")
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": long_desc}
+ and end here."""
+ )
+ attrs = {"name": "package", "version": "1.0", "long_description": long_desc}
dist = Distribution(attrs)
meta = self.format_metadata(dist)
@@ -470,8 +499,9 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
# home drive should be found
os.environ['USERPROFILE'] = temp_dir
files = dist.find_config_files()
- self.assertIn(user_filename, files,
- '%r not found in %r' % (user_filename, files))
+ self.assertIn(
+ user_filename, files, '%r not found in %r' % (user_filename, files)
+ )
finally:
os.remove(user_filename)
@@ -491,19 +521,19 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
with captured_stdout() as s:
dist.parse_command_line()
- output = [line for line in s.getvalue().split('\n')
- if line.strip() != '']
+ output = [line for line in s.getvalue().split('\n') if line.strip() != '']
self.assertTrue(output)
-
def test_read_metadata(self):
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": "desc",
- "description": "xxx",
- "download_url": "http://example.com",
- "keywords": ['one', 'two'],
- "requires": ['foo']}
+ attrs = {
+ "name": "package",
+ "version": "1.0",
+ "long_description": "desc",
+ "description": "xxx",
+ "download_url": "http://example.com",
+ "keywords": ['one', 'two'],
+ "requires": ['foo'],
+ }
dist = Distribution(attrs)
metadata = dist.metadata
@@ -523,11 +553,13 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(metadata.obsoletes, None)
self.assertEqual(metadata.requires, ['foo'])
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DistributionTestCase))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(MetadataTestCase))
return suite
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_extension.py b/setuptools/_distutils/tests/test_extension.py
index 78a55daa..77fe3f82 100644
--- a/setuptools/_distutils/tests/test_extension.py
+++ b/setuptools/_distutils/tests/test_extension.py
@@ -8,8 +8,8 @@ from distutils.extension import read_setup_file, Extension
from .py38compat import check_warnings
-class ExtensionTestCase(unittest.TestCase):
+class ExtensionTestCase(unittest.TestCase):
def test_read_setup_file(self):
# trying to read a Setup file
# (sample extracted from the PyGame project)
@@ -21,14 +21,42 @@ class ExtensionTestCase(unittest.TestCase):
# here are the extensions read_setup_file should have created
# out of the file
- wanted = ['_arraysurfarray', '_camera', '_numericsndarray',
- '_numericsurfarray', 'base', 'bufferproxy', 'cdrom',
- 'color', 'constants', 'display', 'draw', 'event',
- 'fastevent', 'font', 'gfxdraw', 'image', 'imageext',
- 'joystick', 'key', 'mask', 'mixer', 'mixer_music',
- 'mouse', 'movie', 'overlay', 'pixelarray', 'pypm',
- 'rect', 'rwobject', 'scrap', 'surface', 'surflock',
- 'time', 'transform']
+ wanted = [
+ '_arraysurfarray',
+ '_camera',
+ '_numericsndarray',
+ '_numericsurfarray',
+ 'base',
+ 'bufferproxy',
+ 'cdrom',
+ 'color',
+ 'constants',
+ 'display',
+ 'draw',
+ 'event',
+ 'fastevent',
+ 'font',
+ 'gfxdraw',
+ 'image',
+ 'imageext',
+ 'joystick',
+ 'key',
+ 'mask',
+ 'mixer',
+ 'mixer_music',
+ 'mouse',
+ 'movie',
+ 'overlay',
+ 'pixelarray',
+ 'pypm',
+ 'rect',
+ 'rwobject',
+ 'scrap',
+ 'surface',
+ 'surflock',
+ 'time',
+ 'transform',
+ ]
self.assertEqual(names, wanted)
@@ -46,10 +74,20 @@ class ExtensionTestCase(unittest.TestCase):
self.assertEqual(ext.sources, ['file1', 'file2'])
# others arguments have defaults
- for attr in ('include_dirs', 'define_macros', 'undef_macros',
- 'library_dirs', 'libraries', 'runtime_library_dirs',
- 'extra_objects', 'extra_compile_args', 'extra_link_args',
- 'export_symbols', 'swig_opts', 'depends'):
+ for attr in (
+ 'include_dirs',
+ 'define_macros',
+ 'undef_macros',
+ 'library_dirs',
+ 'libraries',
+ 'runtime_library_dirs',
+ 'extra_objects',
+ 'extra_compile_args',
+ 'extra_link_args',
+ 'export_symbols',
+ 'swig_opts',
+ 'depends',
+ ):
self.assertEqual(getattr(ext, attr), [])
self.assertEqual(ext.language, None)
@@ -61,11 +99,14 @@ class ExtensionTestCase(unittest.TestCase):
ext = Extension('name', ['file1', 'file2'], chic=True)
self.assertEqual(len(w.warnings), 1)
- self.assertEqual(str(w.warnings[0].message),
- "Unknown Extension options: 'chic'")
+ self.assertEqual(
+ str(w.warnings[0].message), "Unknown Extension options: 'chic'"
+ )
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(ExtensionTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_file_util.py b/setuptools/_distutils/tests/test_file_util.py
index 81b90d6c..22898b95 100644
--- a/setuptools/_distutils/tests/test_file_util.py
+++ b/setuptools/_distutils/tests/test_file_util.py
@@ -13,7 +13,6 @@ from .py38compat import unlink
class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
-
def _log(self, msg, *args):
if len(args) > 0:
self._logs.append(msg % args)
@@ -64,17 +63,18 @@ class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
def test_move_file_exception_unpacking_rename(self):
# see issue 22182
- with patch("os.rename", side_effect=OSError("wrong", 1)), \
- self.assertRaises(DistutilsFileError):
+ with patch("os.rename", side_effect=OSError("wrong", 1)), self.assertRaises(
+ DistutilsFileError
+ ):
with open(self.source, 'w') as fobj:
fobj.write('spam eggs')
move_file(self.source, self.target, verbose=0)
def test_move_file_exception_unpacking_unlink(self):
# see issue 22182
- with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \
- patch("os.unlink", side_effect=OSError("wrong", 1)), \
- self.assertRaises(DistutilsFileError):
+ with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), patch(
+ "os.unlink", side_effect=OSError("wrong", 1)
+ ), self.assertRaises(DistutilsFileError):
with open(self.source, 'w') as fobj:
fobj.write('spam eggs')
move_file(self.source, self.target, verbose=0)
@@ -120,5 +120,6 @@ class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(FileUtilTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_filelist.py b/setuptools/_distutils/tests/test_filelist.py
index a90edcf1..71718a86 100644
--- a/setuptools/_distutils/tests/test_filelist.py
+++ b/setuptools/_distutils/tests/test_filelist.py
@@ -11,7 +11,6 @@ from distutils import filelist
from test.support import captured_stdout, run_unittest
from distutils.tests import support
-from .py35compat import adapt_glob
from . import py38compat as os_helper
@@ -36,9 +35,7 @@ def make_local_path(s):
return s.replace('/', os.sep)
-class FileListTestCase(support.LoggingSilencer,
- unittest.TestCase):
-
+class FileListTestCase(support.LoggingSilencer, unittest.TestCase):
def assertNoWarnings(self):
self.assertEqual(self.get_logs(WARN), [])
self.clear_logs()
@@ -61,47 +58,53 @@ class FileListTestCase(support.LoggingSilencer,
(r'foo\\*', r'(?s:foo\\\\[^%(sep)s]*)\Z'),
(r'foo\\\*', r'(?s:foo\\\\\\[^%(sep)s]*)\Z'),
('foo????', r'(?s:foo[^%(sep)s][^%(sep)s][^%(sep)s][^%(sep)s])\Z'),
- (r'foo\\??', r'(?s:foo\\\\[^%(sep)s][^%(sep)s])\Z')):
+ (r'foo\\??', r'(?s:foo\\\\[^%(sep)s][^%(sep)s])\Z'),
+ ):
regex = regex % {'sep': sep}
- self.assertEqual(glob_to_re(glob), adapt_glob(regex))
+ self.assertEqual(glob_to_re(glob), regex)
def test_process_template_line(self):
# testing all MANIFEST.in template patterns
file_list = FileList()
- l = make_local_path
+ mlp = make_local_path
# simulated file list
- file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
- 'buildout.cfg',
- # filelist does not filter out VCS directories,
- # it's sdist that does
- l('.hg/last-message.txt'),
- l('global/one.txt'),
- l('global/two.txt'),
- l('global/files.x'),
- l('global/here.tmp'),
- l('f/o/f.oo'),
- l('dir/graft-one'),
- l('dir/dir2/graft2'),
- l('dir3/ok'),
- l('dir3/sub/ok.txt'),
- ]
+ file_list.allfiles = [
+ 'foo.tmp',
+ 'ok',
+ 'xo',
+ 'four.txt',
+ 'buildout.cfg',
+ # filelist does not filter out VCS directories,
+ # it's sdist that does
+ mlp('.hg/last-message.txt'),
+ mlp('global/one.txt'),
+ mlp('global/two.txt'),
+ mlp('global/files.x'),
+ mlp('global/here.tmp'),
+ mlp('f/o/f.oo'),
+ mlp('dir/graft-one'),
+ mlp('dir/dir2/graft2'),
+ mlp('dir3/ok'),
+ mlp('dir3/sub/ok.txt'),
+ ]
for line in MANIFEST_IN.split('\n'):
if line.strip() == '':
continue
file_list.process_template_line(line)
- wanted = ['ok',
- 'buildout.cfg',
- 'four.txt',
- l('.hg/last-message.txt'),
- l('global/one.txt'),
- l('global/two.txt'),
- l('f/o/f.oo'),
- l('dir/graft-one'),
- l('dir/dir2/graft2'),
- ]
+ wanted = [
+ 'ok',
+ 'buildout.cfg',
+ 'four.txt',
+ mlp('.hg/last-message.txt'),
+ mlp('global/one.txt'),
+ mlp('global/two.txt'),
+ mlp('f/o/f.oo'),
+ mlp('dir/graft-one'),
+ mlp('dir/dir2/graft2'),
+ ]
self.assertEqual(file_list.files, wanted)
@@ -135,24 +138,23 @@ class FileListTestCase(support.LoggingSilencer,
def test_translate_pattern(self):
# not regex
- self.assertTrue(hasattr(
- translate_pattern('a', anchor=True, is_regex=False),
- 'search'))
+ self.assertTrue(
+ hasattr(translate_pattern('a', anchor=True, is_regex=False), 'search')
+ )
# is a regex
regex = re.compile('a')
- self.assertEqual(
- translate_pattern(regex, anchor=True, is_regex=True),
- regex)
+ self.assertEqual(translate_pattern(regex, anchor=True, is_regex=True), regex)
# plain string flagged as regex
- self.assertTrue(hasattr(
- translate_pattern('a', anchor=True, is_regex=True),
- 'search'))
+ self.assertTrue(
+ hasattr(translate_pattern('a', anchor=True, is_regex=True), 'search')
+ )
# glob support
- self.assertTrue(translate_pattern(
- '*.py', anchor=True, is_regex=False).search('filelist.py'))
+ self.assertTrue(
+ translate_pattern('*.py', anchor=True, is_regex=False).search('filelist.py')
+ )
def test_exclude_pattern(self):
# return False if no match
@@ -189,18 +191,27 @@ class FileListTestCase(support.LoggingSilencer,
self.assertEqual(file_list.allfiles, ['a.py', 'b.txt'])
def test_process_template(self):
- l = make_local_path
+ mlp = make_local_path
# invalid lines
file_list = FileList()
- for action in ('include', 'exclude', 'global-include',
- 'global-exclude', 'recursive-include',
- 'recursive-exclude', 'graft', 'prune', 'blarg'):
- self.assertRaises(DistutilsTemplateError,
- file_list.process_template_line, action)
+ for action in (
+ 'include',
+ 'exclude',
+ 'global-include',
+ 'global-exclude',
+ 'recursive-include',
+ 'recursive-exclude',
+ 'graft',
+ 'prune',
+ 'blarg',
+ ):
+ self.assertRaises(
+ DistutilsTemplateError, file_list.process_template_line, action
+ )
# include
file_list = FileList()
- file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])
+ file_list.set_allfiles(['a.py', 'b.txt', mlp('d/c.py')])
file_list.process_template_line('include *.py')
self.assertEqual(file_list.files, ['a.py'])
@@ -212,31 +223,31 @@ class FileListTestCase(support.LoggingSilencer,
# exclude
file_list = FileList()
- file_list.files = ['a.py', 'b.txt', l('d/c.py')]
+ file_list.files = ['a.py', 'b.txt', mlp('d/c.py')]
file_list.process_template_line('exclude *.py')
- self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
+ self.assertEqual(file_list.files, ['b.txt', mlp('d/c.py')])
self.assertNoWarnings()
file_list.process_template_line('exclude *.rb')
- self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
+ self.assertEqual(file_list.files, ['b.txt', mlp('d/c.py')])
self.assertWarnings()
# global-include
file_list = FileList()
- file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])
+ file_list.set_allfiles(['a.py', 'b.txt', mlp('d/c.py')])
file_list.process_template_line('global-include *.py')
- self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
+ self.assertEqual(file_list.files, ['a.py', mlp('d/c.py')])
self.assertNoWarnings()
file_list.process_template_line('global-include *.rb')
- self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
+ self.assertEqual(file_list.files, ['a.py', mlp('d/c.py')])
self.assertWarnings()
# global-exclude
file_list = FileList()
- file_list.files = ['a.py', 'b.txt', l('d/c.py')]
+ file_list.files = ['a.py', 'b.txt', mlp('d/c.py')]
file_list.process_template_line('global-exclude *.py')
self.assertEqual(file_list.files, ['b.txt'])
@@ -248,52 +259,50 @@ class FileListTestCase(support.LoggingSilencer,
# recursive-include
file_list = FileList()
- file_list.set_allfiles(['a.py', l('d/b.py'), l('d/c.txt'),
- l('d/d/e.py')])
+ file_list.set_allfiles(['a.py', mlp('d/b.py'), mlp('d/c.txt'), mlp('d/d/e.py')])
file_list.process_template_line('recursive-include d *.py')
- self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
+ self.assertEqual(file_list.files, [mlp('d/b.py'), mlp('d/d/e.py')])
self.assertNoWarnings()
file_list.process_template_line('recursive-include e *.py')
- self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
+ self.assertEqual(file_list.files, [mlp('d/b.py'), mlp('d/d/e.py')])
self.assertWarnings()
# recursive-exclude
file_list = FileList()
- file_list.files = ['a.py', l('d/b.py'), l('d/c.txt'), l('d/d/e.py')]
+ file_list.files = ['a.py', mlp('d/b.py'), mlp('d/c.txt'), mlp('d/d/e.py')]
file_list.process_template_line('recursive-exclude d *.py')
- self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
+ self.assertEqual(file_list.files, ['a.py', mlp('d/c.txt')])
self.assertNoWarnings()
file_list.process_template_line('recursive-exclude e *.py')
- self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
+ self.assertEqual(file_list.files, ['a.py', mlp('d/c.txt')])
self.assertWarnings()
# graft
file_list = FileList()
- file_list.set_allfiles(['a.py', l('d/b.py'), l('d/d/e.py'),
- l('f/f.py')])
+ file_list.set_allfiles(['a.py', mlp('d/b.py'), mlp('d/d/e.py'), mlp('f/f.py')])
file_list.process_template_line('graft d')
- self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
+ self.assertEqual(file_list.files, [mlp('d/b.py'), mlp('d/d/e.py')])
self.assertNoWarnings()
file_list.process_template_line('graft e')
- self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
+ self.assertEqual(file_list.files, [mlp('d/b.py'), mlp('d/d/e.py')])
self.assertWarnings()
# prune
file_list = FileList()
- file_list.files = ['a.py', l('d/b.py'), l('d/d/e.py'), l('f/f.py')]
+ file_list.files = ['a.py', mlp('d/b.py'), mlp('d/d/e.py'), mlp('f/f.py')]
file_list.process_template_line('prune d')
- self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
+ self.assertEqual(file_list.files, ['a.py', mlp('f/f.py')])
self.assertNoWarnings()
file_list.process_template_line('prune e')
- self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
+ self.assertEqual(file_list.files, ['a.py', mlp('f/f.py')])
self.assertWarnings()
@@ -343,10 +352,12 @@ class FindAllTestCase(unittest.TestCase):
def test_suite():
- return unittest.TestSuite([
- unittest.TestLoader().loadTestsFromTestCase(FileListTestCase),
- unittest.TestLoader().loadTestsFromTestCase(FindAllTestCase),
- ])
+ return unittest.TestSuite(
+ [
+ unittest.TestLoader().loadTestsFromTestCase(FileListTestCase),
+ unittest.TestLoader().loadTestsFromTestCase(FindAllTestCase),
+ ]
+ )
if __name__ == "__main__":
diff --git a/setuptools/_distutils/tests/test_install.py b/setuptools/_distutils/tests/test_install.py
index 3aef9e43..5f0a64db 100644
--- a/setuptools/_distutils/tests/test_install.py
+++ b/setuptools/_distutils/tests/test_install.py
@@ -19,16 +19,23 @@ from distutils.extension import Extension
from distutils.tests import support
from test import support as test_support
+import pytest
+
def _make_ext_name(modname):
return modname + sysconfig.get_config_var('EXT_SUFFIX')
-class InstallTestCase(support.TempdirManager,
- support.EnvironGuard,
- support.LoggingSilencer,
- unittest.TestCase):
-
+class InstallTestCase(
+ support.TempdirManager,
+ support.EnvironGuard,
+ support.LoggingSilencer,
+ unittest.TestCase,
+):
+ @pytest.mark.xfail(
+ 'platform.system() == "Windows" and sys.version_info > (3, 11)',
+ reason="pypa/distutils#148",
+ )
def test_home_installation_scheme(self):
# This ensure two things:
# - that --home generates the desired set of directory names
@@ -42,7 +49,7 @@ class InstallTestCase(support.TempdirManager,
dist.command_obj["build"] = support.DummyCommand(
build_base=builddir,
build_lib=os.path.join(builddir, "lib"),
- )
+ )
cmd = install(dist)
cmd.home = destination
@@ -63,8 +70,10 @@ class InstallTestCase(support.TempdirManager,
platlibdir = os.path.join(destination, _platlibdir, impl_name)
check_path(cmd.install_platlib, platlibdir)
check_path(cmd.install_purelib, libdir)
- check_path(cmd.install_headers,
- os.path.join(destination, "include", impl_name, "foopkg"))
+ check_path(
+ cmd.install_headers,
+ os.path.join(destination, "include", impl_name, "foopkg"),
+ )
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
check_path(cmd.install_data, destination)
@@ -85,6 +94,7 @@ class InstallTestCase(support.TempdirManager,
if path.startswith('~'):
return os.path.normpath(self.tmpdir + path[1:])
return path
+
self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser
@@ -104,8 +114,7 @@ class InstallTestCase(support.TempdirManager,
cmd = install(dist)
# making sure the user option is there
- options = [name for name, short, lable in
- cmd.user_options]
+ options = [name for name, short, lable in cmd.user_options]
self.assertIn('user', options)
# setting a value
@@ -128,13 +137,16 @@ class InstallTestCase(support.TempdirManager,
actual_headers = os.path.relpath(cmd.install_headers, self.user_base)
if os.name == 'nt':
site_path = os.path.relpath(
- os.path.dirname(self.old_user_site), self.old_user_base)
+ os.path.dirname(self.old_user_site), self.old_user_base
+ )
include = os.path.join(site_path, 'Include')
else:
include = sysconfig.get_python_inc(0, '')
expect_headers = os.path.join(include, 'xx')
- self.assertEqual(os.path.normcase(actual_headers), os.path.normcase(expect_headers))
+ self.assertEqual(
+ os.path.normcase(actual_headers), os.path.normcase(expect_headers)
+ )
def test_handle_extra_path(self):
dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
@@ -187,8 +199,7 @@ class InstallTestCase(support.TempdirManager,
def test_record(self):
install_dir = self.mkdtemp()
- project_dir, dist = self.create_dist(py_modules=['hello'],
- scripts=['sayhi'])
+ project_dir, dist = self.create_dist(py_modules=['hello'], scripts=['sayhi'])
os.chdir(project_dir)
self.write_file('hello.py', "def main(): print('o hai')")
self.write_file('sayhi', 'from hello import main; main()')
@@ -207,9 +218,12 @@ class InstallTestCase(support.TempdirManager,
f.close()
found = [os.path.basename(line) for line in content.splitlines()]
- expected = ['hello.py', 'hello.%s.pyc' % sys.implementation.cache_tag,
- 'sayhi',
- 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
+ expected = [
+ 'hello.py',
+ 'hello.%s.pyc' % sys.implementation.cache_tag,
+ 'sayhi',
+ 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2],
+ ]
self.assertEqual(found, expected)
def test_record_extensions(self):
@@ -217,8 +231,9 @@ class InstallTestCase(support.TempdirManager,
if cmd is not None:
self.skipTest('The %r command is not found' % cmd)
install_dir = self.mkdtemp()
- project_dir, dist = self.create_dist(ext_modules=[
- Extension('xx', ['xxmodule.c'])])
+ project_dir, dist = self.create_dist(
+ ext_modules=[Extension('xx', ['xxmodule.c'])]
+ )
os.chdir(project_dir)
support.copy_xxmodule_c(project_dir)
@@ -241,8 +256,10 @@ class InstallTestCase(support.TempdirManager,
f.close()
found = [os.path.basename(line) for line in content.splitlines()]
- expected = [_make_ext_name('xx'),
- 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
+ expected = [
+ _make_ext_name('xx'),
+ 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2],
+ ]
self.assertEqual(found, expected)
def test_debug_mode(self):
@@ -260,5 +277,6 @@ class InstallTestCase(support.TempdirManager,
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(InstallTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_install_data.py b/setuptools/_distutils/tests/test_install_data.py
index 6191d2fa..a08168b2 100644
--- a/setuptools/_distutils/tests/test_install_data.py
+++ b/setuptools/_distutils/tests/test_install_data.py
@@ -6,11 +6,13 @@ from distutils.command.install_data import install_data
from distutils.tests import support
from test.support import run_unittest
-class InstallDataTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
+class InstallDataTestCase(
+ support.TempdirManager,
+ support.LoggingSilencer,
+ support.EnvironGuard,
+ unittest.TestCase,
+):
def test_simple_run(self):
pkg_dir, dist = self.create_dist()
cmd = install_data(dist)
@@ -57,9 +59,7 @@ class InstallDataTestCase(support.TempdirManager,
inst4 = os.path.join(pkg_dir, 'inst4')
three = os.path.join(cmd.install_dir, 'three')
self.write_file(three, 'xx')
- cmd.data_files = [one, (inst2, [two]),
- ('inst3', [three]),
- (inst4, [])]
+ cmd.data_files = [one, (inst2, [two]), ('inst3', [three]), (inst4, [])]
cmd.ensure_finalized()
cmd.run()
@@ -68,8 +68,10 @@ class InstallDataTestCase(support.TempdirManager,
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(InstallDataTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_install_headers.py b/setuptools/_distutils/tests/test_install_headers.py
index 1aa4d09c..db4f4dbb 100644
--- a/setuptools/_distutils/tests/test_install_headers.py
+++ b/setuptools/_distutils/tests/test_install_headers.py
@@ -6,11 +6,13 @@ from distutils.command.install_headers import install_headers
from distutils.tests import support
from test.support import run_unittest
-class InstallHeadersTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
+class InstallHeadersTestCase(
+ support.TempdirManager,
+ support.LoggingSilencer,
+ support.EnvironGuard,
+ unittest.TestCase,
+):
def test_simple_run(self):
# we have two headers
header_list = self.mkdtemp()
@@ -32,8 +34,10 @@ class InstallHeadersTestCase(support.TempdirManager,
# let's check the results
self.assertEqual(len(cmd.get_outputs()), 2)
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(InstallHeadersTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_install_lib.py b/setuptools/_distutils/tests/test_install_lib.py
index 652653f2..1ef233a7 100644
--- a/setuptools/_distutils/tests/test_install_lib.py
+++ b/setuptools/_distutils/tests/test_install_lib.py
@@ -11,11 +11,12 @@ from distutils.errors import DistutilsOptionError
from test.support import run_unittest
-class InstallLibTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
+class InstallLibTestCase(
+ support.TempdirManager,
+ support.LoggingSilencer,
+ support.EnvironGuard,
+ unittest.TestCase,
+):
def test_finalize_options(self):
dist = self.create_dist()[1]
cmd = install_lib(dist)
@@ -45,8 +46,9 @@ class InstallLibTestCase(support.TempdirManager,
self.write_file(f, '# python file')
cmd.byte_compile([f])
pyc_file = importlib.util.cache_from_source('foo.py', optimization='')
- pyc_opt_file = importlib.util.cache_from_source('foo.py',
- optimization=cmd.optimize)
+ pyc_opt_file = importlib.util.cache_from_source(
+ 'foo.py', optimization=cmd.optimize
+ )
self.assertTrue(os.path.exists(pyc_file))
self.assertTrue(os.path.exists(pyc_opt_file))
@@ -104,12 +106,12 @@ class InstallLibTestCase(support.TempdirManager,
finally:
sys.dont_write_bytecode = old_dont_write_bytecode
- self.assertIn('byte-compiling is disabled',
- self.logs[0][1] % self.logs[0][2])
+ self.assertIn('byte-compiling is disabled', self.logs[0][1] % self.logs[0][2])
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(InstallLibTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_install_scripts.py b/setuptools/_distutils/tests/test_install_scripts.py
index 648db3b1..bac78801 100644
--- a/setuptools/_distutils/tests/test_install_scripts.py
+++ b/setuptools/_distutils/tests/test_install_scripts.py
@@ -10,19 +10,17 @@ from distutils.tests import support
from test.support import run_unittest
-class InstallScriptsTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
+class InstallScriptsTestCase(
+ support.TempdirManager, support.LoggingSilencer, unittest.TestCase
+):
def test_default_settings(self):
dist = Distribution()
- dist.command_obj["build"] = support.DummyCommand(
- build_scripts="/foo/bar")
+ dist.command_obj["build"] = support.DummyCommand(build_scripts="/foo/bar")
dist.command_obj["install"] = support.DummyCommand(
install_scripts="/splat/funk",
force=1,
skip_build=1,
- )
+ )
cmd = install_scripts(dist)
self.assertFalse(cmd.force)
self.assertFalse(cmd.skip_build)
@@ -48,15 +46,21 @@ class InstallScriptsTestCase(support.TempdirManager,
finally:
f.close()
- write_script("script1.py", ("#! /usr/bin/env python2.3\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
- write_script("script2.py", ("#!/usr/bin/python\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
- write_script("shell.sh", ("#!/bin/sh\n"
- "# bogus shell script w/ sh-bang\n"
- "exit 0\n"))
+ write_script(
+ "script1.py",
+ (
+ "#! /usr/bin/env python2.3\n"
+ "# bogus script w/ Python sh-bang\n"
+ "pass\n"
+ ),
+ )
+ write_script(
+ "script2.py",
+ ("#!/usr/bin/python\n" "# bogus script w/ Python sh-bang\n" "pass\n"),
+ )
+ write_script(
+ "shell.sh", ("#!/bin/sh\n" "# bogus shell script w/ sh-bang\n" "exit 0\n")
+ )
target = self.mkdtemp()
dist = Distribution()
@@ -65,7 +69,7 @@ class InstallScriptsTestCase(support.TempdirManager,
install_scripts=target,
force=1,
skip_build=1,
- )
+ )
cmd = install_scripts(dist)
cmd.finalize_options()
cmd.run()
@@ -78,5 +82,6 @@ class InstallScriptsTestCase(support.TempdirManager,
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(InstallScriptsTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_log.py b/setuptools/_distutils/tests/test_log.py
index ec2ae028..33f7f96c 100644
--- a/setuptools/_distutils/tests/test_log.py
+++ b/setuptools/_distutils/tests/test_log.py
@@ -7,40 +7,55 @@ from test.support import swap_attr, run_unittest
from distutils import log
+
class TestLog(unittest.TestCase):
def test_non_ascii(self):
# Issues #8663, #34421: test that non-encodable text is escaped with
# backslashreplace error handler and encodable non-ASCII text is
# output as is.
- for errors in ('strict', 'backslashreplace', 'surrogateescape',
- 'replace', 'ignore'):
+ for errors in (
+ 'strict',
+ 'backslashreplace',
+ 'surrogateescape',
+ 'replace',
+ 'ignore',
+ ):
with self.subTest(errors=errors):
- stdout = io.TextIOWrapper(io.BytesIO(),
- encoding='cp437', errors=errors)
- stderr = io.TextIOWrapper(io.BytesIO(),
- encoding='cp437', errors=errors)
+ stdout = io.TextIOWrapper(io.BytesIO(), encoding='cp437', errors=errors)
+ stderr = io.TextIOWrapper(io.BytesIO(), encoding='cp437', errors=errors)
old_threshold = log.set_threshold(log.DEBUG)
try:
- with swap_attr(sys, 'stdout', stdout), \
- swap_attr(sys, 'stderr', stderr):
+ with swap_attr(sys, 'stdout', stdout), swap_attr(
+ sys, 'stderr', stderr
+ ):
log.debug('Dεbug\tMėssãge')
log.fatal('Fαtal\tÈrrōr')
finally:
log.set_threshold(old_threshold)
stdout.seek(0)
- self.assertEqual(stdout.read().rstrip(),
- 'Dεbug\tM?ss?ge' if errors == 'replace' else
- 'Dεbug\tMssge' if errors == 'ignore' else
- 'Dεbug\tM\\u0117ss\\xe3ge')
+ self.assertEqual(
+ stdout.read().rstrip(),
+ 'Dεbug\tM?ss?ge'
+ if errors == 'replace'
+ else 'Dεbug\tMssge'
+ if errors == 'ignore'
+ else 'Dεbug\tM\\u0117ss\\xe3ge',
+ )
stderr.seek(0)
- self.assertEqual(stderr.read().rstrip(),
- 'Fαtal\t?rr?r' if errors == 'replace' else
- 'Fαtal\trrr' if errors == 'ignore' else
- 'Fαtal\t\\xc8rr\\u014dr')
+ self.assertEqual(
+ stderr.read().rstrip(),
+ 'Fαtal\t?rr?r'
+ if errors == 'replace'
+ else 'Fαtal\trrr'
+ if errors == 'ignore'
+ else 'Fαtal\t\\xc8rr\\u014dr',
+ )
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TestLog)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_msvc9compiler.py b/setuptools/_distutils/tests/test_msvc9compiler.py
index 6235405e..ec4781af 100644
--- a/setuptools/_distutils/tests/test_msvc9compiler.py
+++ b/setuptools/_distutils/tests/test_msvc9compiler.py
@@ -90,38 +90,42 @@ _CLEANED_MANIFEST = """\
</dependency>
</assembly>"""
-if sys.platform=="win32":
+if sys.platform == "win32":
from distutils.msvccompiler import get_build_version
- if get_build_version()>=8.0:
+
+ if get_build_version() >= 8.0:
SKIP_MESSAGE = None
else:
SKIP_MESSAGE = "These tests are only for MSVC8.0 or above"
else:
SKIP_MESSAGE = "These tests are only for win32"
-@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
-class msvc9compilerTestCase(support.TempdirManager,
- unittest.TestCase):
+@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
+class msvc9compilerTestCase(support.TempdirManager, unittest.TestCase):
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a DistutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
+
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
+
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
- self.assertRaises(DistutilsPlatformError, query_vcvarsall,
- 'wont find this version')
+ self.assertRaises(
+ DistutilsPlatformError, query_vcvarsall, 'wont find this version'
+ )
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_reg_class(self):
from distutils.msvc9compiler import Reg
+
self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
# looking for values that should exist on all
@@ -131,6 +135,7 @@ class msvc9compilerTestCase(support.TempdirManager,
self.assertIn(v, ('0', '1', '2'))
import winreg
+
HKCU = winreg.HKEY_CURRENT_USER
keys = Reg.read_keys(HKCU, 'xxxx')
self.assertEqual(keys, None)
@@ -140,6 +145,7 @@ class msvc9compilerTestCase(support.TempdirManager,
def test_remove_visual_c_ref(self):
from distutils.msvc9compiler import MSVCCompiler
+
tempdir = self.mkdtemp()
manifest = os.path.join(tempdir, 'manifest')
f = open(manifest, 'w')
@@ -164,6 +170,7 @@ class msvc9compilerTestCase(support.TempdirManager,
def test_remove_entire_manifest(self):
from distutils.msvc9compiler import MSVCCompiler
+
tempdir = self.mkdtemp()
manifest = os.path.join(tempdir, 'manifest')
f = open(manifest, 'w')
@@ -180,5 +187,6 @@ class msvc9compilerTestCase(support.TempdirManager,
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(msvc9compilerTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_msvccompiler.py b/setuptools/_distutils/tests/test_msvccompiler.py
index 846e5bb8..21fe57f8 100644
--- a/setuptools/_distutils/tests/test_msvccompiler.py
+++ b/setuptools/_distutils/tests/test_msvccompiler.py
@@ -9,15 +9,14 @@ from distutils.tests import support
from test.support import run_unittest
-SKIP_MESSAGE = (None if sys.platform == "win32" else
- "These tests are only for win32")
+SKIP_MESSAGE = None if sys.platform == "win32" else "These tests are only for win32"
-@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
-class msvccompilerTestCase(support.TempdirManager,
- unittest.TestCase):
+@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
+class msvccompilerTestCase(support.TempdirManager, unittest.TestCase):
def test_no_compiler(self):
import distutils._msvccompiler as _msvccompiler
+
# makes sure query_vcvarsall raises
# a DistutilsPlatformError if the compiler
# is not found
@@ -27,9 +26,11 @@ class msvccompilerTestCase(support.TempdirManager,
old_find_vcvarsall = _msvccompiler._find_vcvarsall
_msvccompiler._find_vcvarsall = _find_vcvarsall
try:
- self.assertRaises(DistutilsPlatformError,
- _msvccompiler._get_vc_env,
- 'wont find this version')
+ self.assertRaises(
+ DistutilsPlatformError,
+ _msvccompiler._get_vc_env,
+ 'wont find this version',
+ )
finally:
_msvccompiler._find_vcvarsall = old_find_vcvarsall
@@ -95,14 +96,14 @@ class TestSpawn(unittest.TestCase):
Concurrent calls to spawn should have consistent results.
"""
import distutils._msvccompiler as _msvccompiler
+
compiler = _msvccompiler.MSVCCompiler()
compiler._paths = "expected"
inner_cmd = 'import os; assert os.environ["PATH"] == "expected"'
command = [sys.executable, '-c', inner_cmd]
threads = [
- CheckThread(target=compiler.spawn, args=[command])
- for n in range(100)
+ CheckThread(target=compiler.spawn, args=[command]) for n in range(100)
]
for thread in threads:
thread.start()
@@ -117,6 +118,7 @@ class TestSpawn(unittest.TestCase):
"""
import distutils._msvccompiler as _msvccompiler
from distutils import ccompiler
+
compiler = _msvccompiler.MSVCCompiler()
compiler._paths = "expected"
@@ -124,8 +126,7 @@ class TestSpawn(unittest.TestCase):
"A spawn without an env argument."
assert os.environ["PATH"] == "expected"
- with unittest.mock.patch.object(
- ccompiler.CCompiler, 'spawn', CCompiler_spawn):
+ with unittest.mock.patch.object(ccompiler.CCompiler, 'spawn', CCompiler_spawn):
compiler.spawn(["n/a"])
assert os.environ.get("PATH") != "expected"
@@ -134,5 +135,6 @@ class TestSpawn(unittest.TestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(msvccompilerTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_register.py b/setuptools/_distutils/tests/test_register.py
index 45567686..0f91ad36 100644
--- a/setuptools/_distutils/tests/test_register.py
+++ b/setuptools/_distutils/tests/test_register.py
@@ -41,8 +41,10 @@ username:tarek
password:password
"""
+
class Inputs(object):
"""Fakes user inputs."""
+
def __init__(self, *answers):
self.answers = answers
self.index = 0
@@ -53,8 +55,10 @@ class Inputs(object):
finally:
self.index += 1
+
class FakeOpener(object):
"""Fakes a PyPI server"""
+
def __init__(self):
self.reqs = []
@@ -71,17 +75,18 @@ class FakeOpener(object):
def getheader(self, name, default=None):
return {
'content-type': 'text/plain; charset=utf-8',
- }.get(name.lower(), default)
+ }.get(name.lower(), default)
class RegisterTestCase(BasePyPIRCCommandTestCase):
-
def setUp(self):
super(RegisterTestCase, self).setUp()
# patching the password prompt
self._old_getpass = getpass.getpass
+
def _getpass(prompt):
return 'password'
+
getpass.getpass = _getpass
urllib.request._opener = None
self.old_opener = urllib.request.build_opener
@@ -95,9 +100,13 @@ class RegisterTestCase(BasePyPIRCCommandTestCase):
def _get_cmd(self, metadata=None):
if metadata is None:
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx'}
+ metadata = {
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ }
pkg_info, dist = self.create_dist(**metadata)
return register(dist)
@@ -143,6 +152,7 @@ class RegisterTestCase(BasePyPIRCCommandTestCase):
# if we run the command again
def _no_way(prompt=''):
raise AssertionError(prompt)
+
register_module.input = _no_way
cmd.show_response = 1
@@ -220,10 +230,14 @@ class RegisterTestCase(BasePyPIRCCommandTestCase):
self.assertRaises(DistutilsSetupError, cmd.run)
# metadata are OK but long_description is broken
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'éxéxé',
- 'name': 'xxx', 'version': 'xxx',
- 'long_description': 'title\n==\n\ntext'}
+ metadata = {
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'éxéxé',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'long_description': 'title\n==\n\ntext',
+ }
cmd = self._get_cmd(metadata)
cmd.ensure_finalized()
@@ -255,11 +269,15 @@ class RegisterTestCase(BasePyPIRCCommandTestCase):
del register_module.input
# and finally a Unicode test (bug #12114)
- metadata = {'url': 'xxx', 'author': '\u00c9ric',
- 'author_email': 'xxx', 'name': 'xxx',
- 'version': 'xxx',
- 'description': 'Something about esszet \u00df',
- 'long_description': 'More things about esszet \u00df'}
+ metadata = {
+ 'url': 'xxx',
+ 'author': '\u00c9ric',
+ 'author_email': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'description': 'Something about esszet \u00df',
+ 'long_description': 'More things about esszet \u00df',
+ }
cmd = self._get_cmd(metadata)
cmd.ensure_finalized()
@@ -275,10 +293,14 @@ class RegisterTestCase(BasePyPIRCCommandTestCase):
@unittest.skipUnless(docutils is not None, 'needs docutils')
def test_register_invalid_long_description(self):
description = ':funkie:`str`' # mimic Sphinx-specific markup
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx',
- 'long_description': description}
+ metadata = {
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'long_description': description,
+ }
cmd = self._get_cmd(metadata)
cmd.ensure_finalized()
cmd.strict = True
@@ -321,5 +343,6 @@ class RegisterTestCase(BasePyPIRCCommandTestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(RegisterTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_sdist.py b/setuptools/_distutils/tests/test_sdist.py
index aa04dd05..3a6aea23 100644
--- a/setuptools/_distutils/tests/test_sdist.py
+++ b/setuptools/_distutils/tests/test_sdist.py
@@ -13,6 +13,7 @@ from .py38compat import check_warnings
try:
import zlib
+
ZLIB_SUPPORT = True
except ImportError:
ZLIB_SUPPORT = False
@@ -48,8 +49,8 @@ somecode%(sep)sdoc.dat
somecode%(sep)sdoc.txt
"""
-class SDistTestCase(BasePyPIRCCommandTestCase):
+class SDistTestCase(BasePyPIRCCommandTestCase):
def setUp(self):
# PyPIRCCommandTestCase creates a temp dir already
# and put it in self.tmp_dir
@@ -72,9 +73,13 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
def get_cmd(self, metadata=None):
"""Returns a cmd"""
if metadata is None:
- metadata = {'name': 'fake', 'version': '1.0',
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'}
+ metadata = {
+ 'name': 'fake',
+ 'version': '1.0',
+ 'url': 'xxx',
+ 'author': 'xxx',
+ 'author_email': 'xxx',
+ }
dist = Distribution(metadata)
dist.script_name = 'setup.py'
dist.packages = ['somecode']
@@ -93,12 +98,10 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
- self.write_file((self.tmp_dir, 'somecode', '.hg',
- 'ok'), 'xxx')
+ self.write_file((self.tmp_dir, 'somecode', '.hg', 'ok'), 'xxx')
os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
- self.write_file((self.tmp_dir, 'somecode', '.git',
- 'ok'), 'xxx')
+ self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx')
self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx')
@@ -124,15 +127,19 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
zip_file.close()
# making sure everything has been pruned correctly
- expected = ['', 'PKG-INFO', 'README', 'setup.py',
- 'somecode/', 'somecode/__init__.py']
+ expected = [
+ '',
+ 'PKG-INFO',
+ 'README',
+ 'setup.py',
+ 'somecode/',
+ 'somecode/__init__.py',
+ ]
self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- @unittest.skipIf(find_executable('tar') is None,
- "The tar command is not found")
- @unittest.skipIf(find_executable('gzip') is None,
- "The gzip command is not found")
+ @unittest.skipIf(find_executable('tar') is None, "The tar command is not found")
+ @unittest.skipIf(find_executable('gzip') is None, "The gzip command is not found")
def test_make_distribution(self):
# now building a sdist
dist, cmd = self.get_cmd()
@@ -172,8 +179,7 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
# filling data_files by pointing files
# in package_data
- dist.package_data = {'': ['*.cfg', '*.dat'],
- 'somecode': ['*.txt']}
+ dist.package_data = {'': ['*.cfg', '*.dat'], 'somecode': ['*.txt']}
self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#')
@@ -193,12 +199,11 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
self.write_file((some_dir, 'file.txt'), '#')
self.write_file((some_dir, 'other_file.txt'), '#')
- dist.data_files = [('data', ['data/data.dt',
- 'buildout.cfg',
- 'inroot.txt',
- 'notexisting']),
- 'some/file.txt',
- 'some/other_file.txt']
+ dist.data_files = [
+ ('data', ['data/data.dt', 'buildout.cfg', 'inroot.txt', 'notexisting']),
+ 'some/file.txt',
+ 'some/other_file.txt',
+ ]
# adding a script
script_dir = join(self.tmp_dir, 'scripts')
@@ -224,12 +229,25 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
zip_file.close()
# making sure everything was added
- expected = ['', 'PKG-INFO', 'README', 'buildout.cfg',
- 'data/', 'data/data.dt', 'inroot.txt',
- 'scripts/', 'scripts/script.py', 'setup.py',
- 'some/', 'some/file.txt', 'some/other_file.txt',
- 'somecode/', 'somecode/__init__.py', 'somecode/doc.dat',
- 'somecode/doc.txt']
+ expected = [
+ '',
+ 'PKG-INFO',
+ 'README',
+ 'buildout.cfg',
+ 'data/',
+ 'data/data.dt',
+ 'inroot.txt',
+ 'scripts/',
+ 'scripts/script.py',
+ 'setup.py',
+ 'some/',
+ 'some/file.txt',
+ 'some/other_file.txt',
+ 'somecode/',
+ 'somecode/__init__.py',
+ 'somecode/doc.dat',
+ 'somecode/doc.txt',
+ ]
self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
# checking the MANIFEST
@@ -249,8 +267,9 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
# with the `check` subcommand
cmd.ensure_finalized()
cmd.run()
- warnings = [msg for msg in self.get_logs(WARN) if
- msg.startswith('warning: check:')]
+ warnings = [
+ msg for msg in self.get_logs(WARN) if msg.startswith('warning: check:')
+ ]
self.assertEqual(len(warnings), 1)
# trying with a complete set of metadata
@@ -259,8 +278,9 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
cmd.ensure_finalized()
cmd.metadata_check = 0
cmd.run()
- warnings = [msg for msg in self.get_logs(WARN) if
- msg.startswith('warning: check:')]
+ warnings = [
+ msg for msg in self.get_logs(WARN) if msg.startswith('warning: check:')
+ ]
self.assertEqual(len(warnings), 0)
def test_check_metadata_deprecated(self):
@@ -277,8 +297,11 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
# the output should be a header line + one line per format
num_formats = len(ARCHIVE_FORMATS.keys())
- output = [line for line in stdout.getvalue().split('\n')
- if line.strip().startswith('--formats=')]
+ output = [
+ line
+ for line in stdout.getvalue().split('\n')
+ if line.strip().startswith('--formats=')
+ ]
self.assertEqual(len(output), num_formats)
def test_finalize_options(self):
@@ -341,8 +364,9 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
f = open(cmd.manifest)
try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
+ manifest = [
+ line.strip() for line in f.read().split('\n') if line.strip() != ''
+ ]
finally:
f.close()
@@ -360,8 +384,9 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
f = open(cmd.manifest)
try:
- manifest2 = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
+ manifest2 = [
+ line.strip() for line in f.read().split('\n') if line.strip() != ''
+ ]
finally:
f.close()
@@ -378,22 +403,24 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
f = open(cmd.manifest)
try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
+ manifest = [
+ line.strip() for line in f.read().split('\n') if line.strip() != ''
+ ]
finally:
f.close()
- self.assertEqual(manifest[0],
- '# file GENERATED by distutils, do NOT edit')
+ self.assertEqual(manifest[0], '# file GENERATED by distutils, do NOT edit')
@unittest.skipUnless(ZLIB_SUPPORT, "Need zlib support to run")
def test_manifest_comments(self):
# make sure comments don't cause exceptions or wrong includes
- contents = dedent("""\
+ contents = dedent(
+ """\
# bad.py
#bad.py
good.py
- """)
+ """
+ )
dist, cmd = self.get_cmd()
cmd.ensure_finalized()
self.write_file((self.tmp_dir, cmd.manifest), contents)
@@ -410,15 +437,18 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
cmd.formats = ['gztar']
cmd.ensure_finalized()
self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
- self.write_file((self.tmp_dir, 'README.manual'),
- 'This project maintains its MANIFEST file itself.')
+ self.write_file(
+ (self.tmp_dir, 'README.manual'),
+ 'This project maintains its MANIFEST file itself.',
+ )
cmd.run()
self.assertEqual(cmd.filelist.files, ['README.manual'])
f = open(cmd.manifest)
try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
+ manifest = [
+ line.strip() for line in f.read().split('\n') if line.strip() != ''
+ ]
finally:
f.close()
@@ -430,16 +460,16 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
filenames = [tarinfo.name for tarinfo in archive]
finally:
archive.close()
- self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO',
- 'fake-1.0/README.manual'])
+ self.assertEqual(
+ sorted(filenames),
+ ['fake-1.0', 'fake-1.0/PKG-INFO', 'fake-1.0/README.manual'],
+ )
@unittest.skipUnless(ZLIB_SUPPORT, "requires zlib")
@require_unix_id
@require_uid_0
- @unittest.skipIf(find_executable('tar') is None,
- "The tar command is not found")
- @unittest.skipIf(find_executable('gzip') is None,
- "The gzip command is not found")
+ @unittest.skipIf(find_executable('tar') is None, "The tar command is not found")
+ @unittest.skipIf(find_executable('gzip') is None, "The gzip command is not found")
def test_make_distribution_owner_group(self):
# now building a sdist
dist, cmd = self.get_cmd()
@@ -482,8 +512,10 @@ class SDistTestCase(BasePyPIRCCommandTestCase):
finally:
archive.close()
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(SDistTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_spawn.py b/setuptools/_distutils/tests/test_spawn.py
index c5ed8e2b..a7732562 100644
--- a/setuptools/_distutils/tests/test_spawn.py
+++ b/setuptools/_distutils/tests/test_spawn.py
@@ -3,9 +3,8 @@ import os
import stat
import sys
import unittest.mock
-from test.support import run_unittest
+from test.support import run_unittest, unix_shell
-from .py35compat import unix_shell
from . import py38compat as os_helper
from distutils.spawn import find_executable
@@ -13,12 +12,9 @@ from distutils.spawn import spawn
from distutils.errors import DistutilsExecError
from distutils.tests import support
-class SpawnTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
- @unittest.skipUnless(os.name in ('nt', 'posix'),
- 'Runs only under posix or nt')
+class SpawnTestCase(support.TempdirManager, support.LoggingSilencer, unittest.TestCase):
+ @unittest.skipUnless(os.name in ('nt', 'posix'), 'Runs only under posix or nt')
def test_spawn(self):
tmpdir = self.mkdtemp()
@@ -74,16 +70,15 @@ class SpawnTestCase(support.TempdirManager,
# test non-existent program
dont_exist_program = "dontexist_" + program
- rv = find_executable(dont_exist_program , path=tmp_dir)
+ rv = find_executable(dont_exist_program, path=tmp_dir)
self.assertIsNone(rv)
# PATH='': no match, except in the current directory
with os_helper.EnvironmentVarGuard() as env:
env['PATH'] = ''
- with unittest.mock.patch('distutils.spawn.os.confstr',
- return_value=tmp_dir, create=True), \
- unittest.mock.patch('distutils.spawn.os.defpath',
- tmp_dir):
+ with unittest.mock.patch(
+ 'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
+ ), unittest.mock.patch('distutils.spawn.os.defpath', tmp_dir):
rv = find_executable(program)
self.assertIsNone(rv)
@@ -95,9 +90,9 @@ class SpawnTestCase(support.TempdirManager,
# PATH=':': explicitly looks in the current directory
with os_helper.EnvironmentVarGuard() as env:
env['PATH'] = os.pathsep
- with unittest.mock.patch('distutils.spawn.os.confstr',
- return_value='', create=True), \
- unittest.mock.patch('distutils.spawn.os.defpath', ''):
+ with unittest.mock.patch(
+ 'distutils.spawn.os.confstr', return_value='', create=True
+ ), unittest.mock.patch('distutils.spawn.os.defpath', ''):
rv = find_executable(program)
self.assertIsNone(rv)
@@ -111,18 +106,16 @@ class SpawnTestCase(support.TempdirManager,
env.pop('PATH', None)
# without confstr
- with unittest.mock.patch('distutils.spawn.os.confstr',
- side_effect=ValueError,
- create=True), \
- unittest.mock.patch('distutils.spawn.os.defpath',
- tmp_dir):
+ with unittest.mock.patch(
+ 'distutils.spawn.os.confstr', side_effect=ValueError, create=True
+ ), unittest.mock.patch('distutils.spawn.os.defpath', tmp_dir):
rv = find_executable(program)
self.assertEqual(rv, filename)
# with confstr
- with unittest.mock.patch('distutils.spawn.os.confstr',
- return_value=tmp_dir, create=True), \
- unittest.mock.patch('distutils.spawn.os.defpath', ''):
+ with unittest.mock.patch(
+ 'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
+ ), unittest.mock.patch('distutils.spawn.os.defpath', ''):
rv = find_executable(program)
self.assertEqual(rv, filename)
@@ -135,5 +128,6 @@ class SpawnTestCase(support.TempdirManager,
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(SpawnTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_sysconfig.py b/setuptools/_distutils/tests/test_sysconfig.py
index 1c88cc85..a033e075 100644
--- a/setuptools/_distutils/tests/test_sysconfig.py
+++ b/setuptools/_distutils/tests/test_sysconfig.py
@@ -17,7 +17,6 @@ from distutils.tests import support
from test.support import run_unittest, swap_item
from .py38compat import TESTFN
-from .py38compat import check_warnings
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
@@ -41,20 +40,23 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
config_h = sysconfig.get_config_h_filename()
self.assertTrue(os.path.isfile(config_h), config_h)
- @unittest.skipIf(sys.platform == 'win32',
- 'Makefile only exists on Unix like systems')
- @unittest.skipIf(sys.implementation.name != 'cpython',
- 'Makefile only exists in CPython')
+ @unittest.skipIf(
+ sys.platform == 'win32', 'Makefile only exists on Unix like systems'
+ )
+ @unittest.skipIf(
+ sys.implementation.name != 'cpython', 'Makefile only exists in CPython'
+ )
def test_get_makefile_filename(self):
makefile = sysconfig.get_makefile_filename()
self.assertTrue(os.path.isfile(makefile), makefile)
def test_get_python_lib(self):
# XXX doesn't work on Linux when Python was never installed before
- #self.assertTrue(os.path.isdir(lib_dir), lib_dir)
+ # self.assertTrue(os.path.isdir(lib_dir), lib_dir)
# test for pythonxx.lib?
- self.assertNotEqual(sysconfig.get_python_lib(),
- sysconfig.get_python_lib(prefix=TESTFN))
+ self.assertNotEqual(
+ sysconfig.get_python_lib(), sysconfig.get_python_lib(prefix=TESTFN)
+ )
def test_get_config_vars(self):
cvars = sysconfig.get_config_vars()
@@ -76,9 +78,7 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
self.assertTrue(os.path.exists(Python_h), Python_h)
self.assertTrue(sysconfig._is_python_source_dir(srcdir))
elif os.name == 'posix':
- self.assertEqual(
- os.path.dirname(sysconfig.get_makefile_filename()),
- srcdir)
+ self.assertEqual(os.path.dirname(sysconfig.get_makefile_filename()), srcdir)
def test_srcdir_independent_of_cwd(self):
# srcdir should be independent of the current working directory
@@ -114,7 +114,6 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
'CCSHARED': '--sc-ccshared',
'LDSHARED': 'sc_ldshared',
'SHLIB_SUFFIX': 'sc_shutil_suffix',
-
# On macOS, disable _osx_support.customize_compiler()
'CUSTOMIZED_OSX_COMPILER': 'True',
}
@@ -127,8 +126,9 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
return comp
- @unittest.skipUnless(get_default_compiler() == 'unix',
- 'not testing if default compiler is not unix')
+ @unittest.skipUnless(
+ get_default_compiler() == 'unix', 'not testing if default compiler is not unix'
+ )
def test_customize_compiler(self):
# Make sure that sysconfig._config_vars is initialized
sysconfig.get_config_vars()
@@ -145,27 +145,25 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
os.environ['RANLIB'] = 'env_ranlib'
comp = self.customize_compiler()
- self.assertEqual(comp.exes['archiver'],
- 'env_ar --env-arflags')
- self.assertEqual(comp.exes['preprocessor'],
- 'env_cpp --env-cppflags')
- self.assertEqual(comp.exes['compiler'],
- 'env_cc --sc-cflags --env-cflags --env-cppflags')
- self.assertEqual(comp.exes['compiler_so'],
- ('env_cc --sc-cflags '
- '--env-cflags ''--env-cppflags --sc-ccshared'))
- self.assertEqual(comp.exes['compiler_cxx'],
- 'env_cxx --env-cxx-flags')
- self.assertEqual(comp.exes['linker_exe'],
- 'env_cc')
- self.assertEqual(comp.exes['linker_so'],
- ('env_ldshared --env-ldflags --env-cflags'
- ' --env-cppflags'))
+ self.assertEqual(comp.exes['archiver'], 'env_ar --env-arflags')
+ self.assertEqual(comp.exes['preprocessor'], 'env_cpp --env-cppflags')
+ self.assertEqual(
+ comp.exes['compiler'], 'env_cc --sc-cflags --env-cflags --env-cppflags'
+ )
+ self.assertEqual(
+ comp.exes['compiler_so'],
+ ('env_cc --sc-cflags ' '--env-cflags ' '--env-cppflags --sc-ccshared'),
+ )
+ self.assertEqual(comp.exes['compiler_cxx'], 'env_cxx --env-cxx-flags')
+ self.assertEqual(comp.exes['linker_exe'], 'env_cc')
+ self.assertEqual(
+ comp.exes['linker_so'],
+ ('env_ldshared --env-ldflags --env-cflags' ' --env-cppflags'),
+ )
self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')
if sys.platform == "darwin":
- self.assertEqual(comp.exes['ranlib'],
- 'env_ranlib')
+ self.assertEqual(comp.exes['ranlib'], 'env_ranlib')
else:
self.assertTrue('ranlib' not in comp.exes)
@@ -181,20 +179,13 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
del os.environ['RANLIB']
comp = self.customize_compiler()
- self.assertEqual(comp.exes['archiver'],
- 'sc_ar --sc-arflags')
- self.assertEqual(comp.exes['preprocessor'],
- 'sc_cc -E')
- self.assertEqual(comp.exes['compiler'],
- 'sc_cc --sc-cflags')
- self.assertEqual(comp.exes['compiler_so'],
- 'sc_cc --sc-cflags --sc-ccshared')
- self.assertEqual(comp.exes['compiler_cxx'],
- 'sc_cxx')
- self.assertEqual(comp.exes['linker_exe'],
- 'sc_cc')
- self.assertEqual(comp.exes['linker_so'],
- 'sc_ldshared')
+ self.assertEqual(comp.exes['archiver'], 'sc_ar --sc-arflags')
+ self.assertEqual(comp.exes['preprocessor'], 'sc_cc -E')
+ self.assertEqual(comp.exes['compiler'], 'sc_cc --sc-cflags')
+ self.assertEqual(comp.exes['compiler_so'], 'sc_cc --sc-cflags --sc-ccshared')
+ self.assertEqual(comp.exes['compiler_cxx'], 'sc_cxx')
+ self.assertEqual(comp.exes['linker_exe'], 'sc_cc')
+ self.assertEqual(comp.exes['linker_so'], 'sc_ldshared')
self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')
self.assertTrue('ranlib' not in comp.exes)
@@ -207,8 +198,9 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
finally:
fd.close()
d = sysconfig.parse_makefile(self.makefile)
- self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
- 'OTHER': 'foo'})
+ self.assertEqual(
+ d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'", 'OTHER': 'foo'}
+ )
def test_parse_makefile_literal_dollar(self):
self.makefile = TESTFN
@@ -219,19 +211,25 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
finally:
fd.close()
d = sysconfig.parse_makefile(self.makefile)
- self.assertEqual(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
- 'OTHER': 'foo'})
-
+ self.assertEqual(
+ d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'", 'OTHER': 'foo'}
+ )
def test_sysconfig_module(self):
import sysconfig as global_sysconfig
- self.assertEqual(global_sysconfig.get_config_var('CFLAGS'),
- sysconfig.get_config_var('CFLAGS'))
- self.assertEqual(global_sysconfig.get_config_var('LDFLAGS'),
- sysconfig.get_config_var('LDFLAGS'))
- @unittest.skipIf(sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'),
- 'compiler flags customized')
+ self.assertEqual(
+ global_sysconfig.get_config_var('CFLAGS'),
+ sysconfig.get_config_var('CFLAGS'),
+ )
+ self.assertEqual(
+ global_sysconfig.get_config_var('LDFLAGS'),
+ sysconfig.get_config_var('LDFLAGS'),
+ )
+
+ @unittest.skipIf(
+ sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'), 'compiler flags customized'
+ )
def test_sysconfig_compiler_vars(self):
# On OS X, binary installers support extension module building on
# various levels of the operating system with differing Xcode
@@ -248,49 +246,46 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
# The longer-term solution is to only have one version of sysconfig.
import sysconfig as global_sysconfig
+
if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
self.skipTest('compiler flags customized')
- self.assertEqual(global_sysconfig.get_config_var('LDSHARED'),
- sysconfig.get_config_var('LDSHARED'))
- self.assertEqual(global_sysconfig.get_config_var('CC'),
- sysconfig.get_config_var('CC'))
-
- @unittest.skipIf(sysconfig.get_config_var('EXT_SUFFIX') is None,
- 'EXT_SUFFIX required for this test')
+ self.assertEqual(
+ global_sysconfig.get_config_var('LDSHARED'),
+ sysconfig.get_config_var('LDSHARED'),
+ )
+ self.assertEqual(
+ global_sysconfig.get_config_var('CC'), sysconfig.get_config_var('CC')
+ )
+
+ @unittest.skipIf(
+ sysconfig.get_config_var('EXT_SUFFIX') is None,
+ 'EXT_SUFFIX required for this test',
+ )
def test_SO_deprecation(self):
- self.assertWarns(DeprecationWarning,
- sysconfig.get_config_var, 'SO')
-
- @unittest.skipIf(sysconfig.get_config_var('EXT_SUFFIX') is None,
- 'EXT_SUFFIX required for this test')
- def test_SO_value(self):
- with check_warnings(('', DeprecationWarning)):
- self.assertEqual(sysconfig.get_config_var('SO'),
- sysconfig.get_config_var('EXT_SUFFIX'))
-
- @unittest.skipIf(sysconfig.get_config_var('EXT_SUFFIX') is None,
- 'EXT_SUFFIX required for this test')
- def test_SO_in_vars(self):
- vars = sysconfig.get_config_vars()
- self.assertIsNotNone(vars['SO'])
- self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
+ self.assertWarns(DeprecationWarning, sysconfig.get_config_var, 'SO')
def test_customize_compiler_before_get_config_vars(self):
# Issue #21923: test that a Distribution compiler
# instance can be called without an explicit call to
# get_config_vars().
with open(TESTFN, 'w') as f:
- f.writelines(textwrap.dedent('''\
+ f.writelines(
+ textwrap.dedent(
+ '''\
from distutils.core import Distribution
config = Distribution().get_command_obj('config')
# try_compile may pass or it may fail if no compiler
# is found but it should not raise an exception.
rc = config.try_compile('int x;')
- '''))
- p = subprocess.Popen([str(sys.executable), TESTFN],
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- universal_newlines=True)
+ '''
+ )
+ )
+ p = subprocess.Popen(
+ [str(sys.executable), TESTFN],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ universal_newlines=True,
+ )
outs, errs = p.communicate()
self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)
@@ -304,23 +299,22 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
result = sysconfig.parse_config_h(f)
self.assertTrue(isinstance(result, dict))
- @unittest.skipUnless(sys.platform == 'win32',
- 'Testing windows pyd suffix')
- @unittest.skipUnless(sys.implementation.name == 'cpython',
- 'Need cpython for this test')
+ @unittest.skipUnless(sys.platform == 'win32', 'Testing windows pyd suffix')
+ @unittest.skipUnless(
+ sys.implementation.name == 'cpython', 'Need cpython for this test'
+ )
def test_win_ext_suffix(self):
self.assertTrue(sysconfig.get_config_var("EXT_SUFFIX").endswith(".pyd"))
self.assertNotEqual(sysconfig.get_config_var("EXT_SUFFIX"), ".pyd")
+ @unittest.skipUnless(sys.platform == 'win32', 'Testing Windows build layout')
@unittest.skipUnless(
- sys.platform == 'win32',
- 'Testing Windows build layout')
- @unittest.skipUnless(
- sys.implementation.name == 'cpython',
- 'Need cpython for this test')
+ sys.implementation.name == 'cpython', 'Need cpython for this test'
+ )
@unittest.skipUnless(
'\\PCbuild\\'.casefold() in sys.executable.casefold(),
- 'Need sys.executable to be in a source tree')
+ 'Need sys.executable to be in a source tree',
+ )
def test_win_build_venv_from_source_tree(self):
"""Ensure distutils.sysconfig detects venvs from source tree builds."""
env = jaraco.envs.VEnv()
@@ -330,10 +324,12 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
cmd = [
env.exe(),
"-c",
- "import distutils.sysconfig; print(distutils.sysconfig.python_build)"
+ "import distutils.sysconfig; print(distutils.sysconfig.python_build)",
]
distutils_path = os.path.dirname(os.path.dirname(distutils.__file__))
- out = subprocess.check_output(cmd, env={**os.environ, "PYTHONPATH": distutils_path})
+ out = subprocess.check_output(
+ cmd, env={**os.environ, "PYTHONPATH": distutils_path}
+ )
assert out == "True"
diff --git a/setuptools/_distutils/tests/test_text_file.py b/setuptools/_distutils/tests/test_text_file.py
index ebac3d52..16de9caa 100644
--- a/setuptools/_distutils/tests/test_text_file.py
+++ b/setuptools/_distutils/tests/test_text_file.py
@@ -12,32 +12,35 @@ line 3 \\
continues on next line
"""
-class TextFileTestCase(support.TempdirManager, unittest.TestCase):
+class TextFileTestCase(support.TempdirManager, unittest.TestCase):
def test_class(self):
# old tests moved from text_file.__main__
# so they are really called by the buildbots
# result 1: no fancy options
- result1 = ['# test file\n', '\n', 'line 3 \\\n',
- '# intervening comment\n',
- ' continues on next line\n']
+ result1 = [
+ '# test file\n',
+ '\n',
+ 'line 3 \\\n',
+ '# intervening comment\n',
+ ' continues on next line\n',
+ ]
# result 2: just strip comments
- result2 = ["\n",
- "line 3 \\\n",
- " continues on next line\n"]
+ result2 = ["\n", "line 3 \\\n", " continues on next line\n"]
# result 3: just strip blank lines
- result3 = ["# test file\n",
- "line 3 \\\n",
- "# intervening comment\n",
- " continues on next line\n"]
+ result3 = [
+ "# test file\n",
+ "line 3 \\\n",
+ "# intervening comment\n",
+ " continues on next line\n",
+ ]
# result 4: default, strip comments, blank lines,
# and trailing whitespace
- result4 = ["line 3 \\",
- " continues on next line"]
+ result4 = ["line 3 \\", " continues on next line"]
# result 5: strip comments and blanks, plus join lines (but don't
# "collapse" joined lines
@@ -59,22 +62,25 @@ class TextFileTestCase(support.TempdirManager, unittest.TestCase):
finally:
out_file.close()
- in_file = TextFile(filename, strip_comments=0, skip_blanks=0,
- lstrip_ws=0, rstrip_ws=0)
+ in_file = TextFile(
+ filename, strip_comments=0, skip_blanks=0, lstrip_ws=0, rstrip_ws=0
+ )
try:
test_input(1, "no processing", in_file, result1)
finally:
in_file.close()
- in_file = TextFile(filename, strip_comments=1, skip_blanks=0,
- lstrip_ws=0, rstrip_ws=0)
+ in_file = TextFile(
+ filename, strip_comments=1, skip_blanks=0, lstrip_ws=0, rstrip_ws=0
+ )
try:
test_input(2, "strip comments", in_file, result2)
finally:
in_file.close()
- in_file = TextFile(filename, strip_comments=0, skip_blanks=1,
- lstrip_ws=0, rstrip_ws=0)
+ in_file = TextFile(
+ filename, strip_comments=0, skip_blanks=1, lstrip_ws=0, rstrip_ws=0
+ )
try:
test_input(3, "strip blanks", in_file, result3)
finally:
@@ -86,22 +92,31 @@ class TextFileTestCase(support.TempdirManager, unittest.TestCase):
finally:
in_file.close()
- in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
- join_lines=1, rstrip_ws=1)
+ in_file = TextFile(
+ filename, strip_comments=1, skip_blanks=1, join_lines=1, rstrip_ws=1
+ )
try:
test_input(5, "join lines without collapsing", in_file, result5)
finally:
in_file.close()
- in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
- join_lines=1, rstrip_ws=1, collapse_join=1)
+ in_file = TextFile(
+ filename,
+ strip_comments=1,
+ skip_blanks=1,
+ join_lines=1,
+ rstrip_ws=1,
+ collapse_join=1,
+ )
try:
test_input(6, "join lines with collapsing", in_file, result6)
finally:
in_file.close()
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TextFileTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_unixccompiler.py b/setuptools/_distutils/tests/test_unixccompiler.py
index c8b4c149..879769fc 100644
--- a/setuptools/_distutils/tests/test_unixccompiler.py
+++ b/setuptools/_distutils/tests/test_unixccompiler.py
@@ -14,16 +14,18 @@ from distutils.util import _clear_cached_macosx_ver
from . import support
-class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
+class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
def setUp(self):
super().setUp()
self._backup_platform = sys.platform
self._backup_get_config_var = sysconfig.get_config_var
self._backup_get_config_vars = sysconfig.get_config_vars
+
class CompilerWrapper(UnixCCompiler):
def rpath_foo(self):
return self.runtime_library_dir_option('/foo')
+
self.cc = CompilerWrapper()
def tearDown(self):
@@ -49,18 +51,18 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
# Version value of None generates two tests: as None and as empty string
# Expected flag value of None means an mismatch exception is expected
darwin_test_cases = [
- ((None , None ), darwin_lib_flag),
- ((None , '11' ), darwin_rpath_flag),
- (('10' , None ), darwin_lib_flag),
- (('10.3' , None ), darwin_lib_flag),
- (('10.3.1', None ), darwin_lib_flag),
- (('10.5' , None ), darwin_rpath_flag),
- (('10.5.1', None ), darwin_rpath_flag),
- (('10.3' , '10.3' ), darwin_lib_flag),
- (('10.3' , '10.5' ), darwin_rpath_flag),
- (('10.5' , '10.3' ), darwin_lib_flag),
- (('10.5' , '11' ), darwin_rpath_flag),
- (('10.4' , '10' ), None),
+ ((None, None), darwin_lib_flag),
+ ((None, '11'), darwin_rpath_flag),
+ (('10', None), darwin_lib_flag),
+ (('10.3', None), darwin_lib_flag),
+ (('10.3.1', None), darwin_lib_flag),
+ (('10.5', None), darwin_rpath_flag),
+ (('10.5.1', None), darwin_rpath_flag),
+ (('10.3', '10.3'), darwin_lib_flag),
+ (('10.3', '10.5'), darwin_rpath_flag),
+ (('10.5', '10.3'), darwin_lib_flag),
+ (('10.5', '11'), darwin_rpath_flag),
+ (('10.4', '10'), None),
]
def make_darwin_gcv(syscfg_macosx_ver):
@@ -68,12 +70,15 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
if var == darwin_ver_var:
return syscfg_macosx_ver
return "xxx"
+
return gcv
def do_darwin_test(syscfg_macosx_ver, env_macosx_ver, expected_flag):
env = os.environ
- msg = "macOS version = (sysconfig=%r, env=%r)" % \
- (syscfg_macosx_ver, env_macosx_ver)
+ msg = "macOS version = (sysconfig=%r, env=%r)" % (
+ syscfg_macosx_ver,
+ env_macosx_ver,
+ )
# Save
old_gcv = sysconfig.get_config_var
@@ -91,8 +96,9 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
if expected_flag is not None:
self.assertEqual(self.cc.rpath_foo(), expected_flag, msg=msg)
else:
- with self.assertRaisesRegex(DistutilsPlatformError,
- darwin_ver_var + r' mismatch', msg=msg):
+ with self.assertRaisesRegex(
+ DistutilsPlatformError, darwin_ver_var + r' mismatch', msg=msg
+ ):
self.cc.rpath_foo()
# Restore
@@ -118,18 +124,22 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
# hp-ux
sys.platform = 'hp-ux'
+
def gcv(v):
return 'xxx'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), ['+s', '-L/foo'])
def gcv(v):
return 'gcc'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
def gcv(v):
return 'g++'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
@@ -137,11 +147,13 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
# GCC GNULD
sys.platform = 'bar'
+
def gcv(v):
if v == 'CC':
return 'gcc'
elif v == 'GNULD':
return 'yes'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
@@ -150,47 +162,56 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
return 'gcc -pthread -B /bar'
elif v == 'GNULD':
return 'yes'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
# GCC non-GNULD
sys.platform = 'bar'
+
def gcv(v):
if v == 'CC':
return 'gcc'
elif v == 'GNULD':
return 'no'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
# GCC GNULD with fully qualified configuration prefix
# see #7617
sys.platform = 'bar'
+
def gcv(v):
if v == 'CC':
return 'x86_64-pc-linux-gnu-gcc-4.4.2'
elif v == 'GNULD':
return 'yes'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
# non-GCC GNULD
sys.platform = 'bar'
+
def gcv(v):
if v == 'CC':
return 'cc'
elif v == 'GNULD':
return 'yes'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,--enable-new-dtags,-R/foo')
# non-GCC non-GNULD
sys.platform = 'bar'
+
def gcv(v):
if v == 'CC':
return 'cc'
elif v == 'GNULD':
return 'no'
+
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
@@ -207,6 +228,7 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
if args:
return list(map(sysconfig.get_config_var, args))
return _orig()
+
sysconfig.get_config_var = gcv
sysconfig.get_config_vars = gcvs
with EnvironmentVarGuard() as env:
@@ -223,6 +245,7 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
pypa/distutils#126
"""
+
def gcv(v):
if v == 'LDSHARED':
return 'gcc-4.2 -bundle -undefined dynamic_lookup '
@@ -237,10 +260,13 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
sysconfig.get_config_var = gcv
sysconfig.get_config_vars = gcvs
- with patch.object(self.cc, 'spawn', return_value=None) as mock_spawn, \
- patch.object(self.cc, '_need_link', return_value=True), \
- patch.object(self.cc, 'mkpath', return_value=None), \
- EnvironmentVarGuard() as env:
+ with patch.object(
+ self.cc, 'spawn', return_value=None
+ ) as mock_spawn, patch.object(
+ self.cc, '_need_link', return_value=True
+ ), patch.object(
+ self.cc, 'mkpath', return_value=None
+ ), EnvironmentVarGuard() as env:
env['CC'] = 'ccache my_cc'
env['CXX'] = 'my_cxx'
del env['LDSHARED']
@@ -265,6 +291,7 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
if args:
return list(map(sysconfig.get_config_var, args))
return _orig()
+
sysconfig.get_config_var = gcv
sysconfig.get_config_vars = gcvs
with EnvironmentVarGuard() as env:
@@ -285,5 +312,6 @@ class UnixCCompilerTestCase(support.TempdirManager, unittest.TestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(UnixCCompilerTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_upload.py b/setuptools/_distutils/tests/test_upload.py
index ce3e84a2..afba2fae 100644
--- a/setuptools/_distutils/tests/test_upload.py
+++ b/setuptools/_distutils/tests/test_upload.py
@@ -43,8 +43,8 @@ index-servers =
username:me
"""
-class FakeOpen(object):
+class FakeOpen(object):
def __init__(self, url, msg=None, code=None):
self.url = url
if not isinstance(url, str):
@@ -57,7 +57,7 @@ class FakeOpen(object):
def getheader(self, name, default=None):
return {
'content-type': 'text/plain; charset=utf-8',
- }.get(name.lower(), default)
+ }.get(name.lower(), default)
def read(self):
return b'xyzzy'
@@ -67,7 +67,6 @@ class FakeOpen(object):
class uploadTestCase(BasePyPIRCCommandTestCase):
-
def setUp(self):
super(uploadTestCase, self).setUp()
self.old_open = upload_mod.urlopen
@@ -91,9 +90,12 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
dist = Distribution()
cmd = upload(dist)
cmd.finalize_options()
- for attr, waited in (('username', 'me'), ('password', 'secret'),
- ('realm', 'pypi'),
- ('repository', 'https://upload.pypi.org/legacy/')):
+ for attr, waited in (
+ ('username', 'me'),
+ ('password', 'secret'),
+ ('realm', 'pypi'),
+ ('repository', 'https://upload.pypi.org/legacy/'),
+ ):
self.assertEqual(getattr(cmd, attr), waited)
def test_saved_password(self):
@@ -137,13 +139,12 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
expected_url = 'https://upload.pypi.org/legacy/'
self.assertEqual(self.last_open.req.get_full_url(), expected_url)
data = self.last_open.req.data
- self.assertIn(b'xxx',data)
+ self.assertIn(b'xxx', data)
self.assertIn(b'protocol_version', data)
self.assertIn(b'sha256_digest', data)
self.assertIn(
- b'cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf'
- b'6860',
- data
+ b'cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf' b'6860',
+ data,
)
if b'md5_digest' in data:
self.assertIn(b'f561aaf6ef0bf14d4208bb46a4ccb3ad', data)
@@ -152,7 +153,7 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
b'b6f289a27d4fe90da63c503bfe0a9b761a8f76bb86148565065f040be'
b'6d1c3044cf7ded78ef800509bccb4b648e507d88dc6383d67642aadcc'
b'ce443f1534330a',
- data
+ data,
)
# The PyPI response body was echoed
@@ -173,8 +174,7 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
# other fields that ended with \r used to be modified, now are
# preserved.
pkg_dir, dist = self.create_dist(
- dist_files=dist_files,
- description='long description\r'
+ dist_files=dist_files, description='long description\r'
)
cmd = upload(dist)
cmd.show_response = 1
@@ -200,13 +200,18 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
pkg_dir, dist = self.create_dist(dist_files=dist_files)
tests = [
(OSError('oserror'), 'oserror', OSError),
- (HTTPError('url', 400, 'httperror', {}, None),
- 'Upload failed (400): httperror', DistutilsError),
+ (
+ HTTPError('url', 400, 'httperror', {}, None),
+ 'Upload failed (400): httperror',
+ DistutilsError,
+ ),
]
for exception, expected, raised_exception in tests:
with self.subTest(exception=type(exception).__name__):
- with mock.patch('distutils.command.upload.urlopen',
- new=mock.Mock(side_effect=exception)):
+ with mock.patch(
+ 'distutils.command.upload.urlopen',
+ new=mock.Mock(side_effect=exception),
+ ):
with self.assertRaises(raised_exception):
cmd = upload(dist)
cmd.ensure_finalized()
@@ -219,5 +224,6 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(uploadTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_util.py b/setuptools/_distutils/tests/test_util.py
index 2738388e..cebd61cc 100644
--- a/setuptools/_distutils/tests/test_util.py
+++ b/setuptools/_distutils/tests/test_util.py
@@ -8,16 +8,24 @@ from test.support import run_unittest
from unittest import mock
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
-from distutils.util import (get_platform, convert_path, change_root,
- check_environ, split_quoted, strtobool,
- rfc822_escape, byte_compile,
- grok_environment_error, get_host_platform)
-from distutils import util # used to patch _environ_checked
+from distutils.util import (
+ get_platform,
+ convert_path,
+ change_root,
+ check_environ,
+ split_quoted,
+ strtobool,
+ rfc822_escape,
+ byte_compile,
+ grok_environment_error,
+ get_host_platform,
+)
+from distutils import util # used to patch _environ_checked
from distutils import sysconfig
from distutils.tests import support
-class UtilTestCase(support.EnvironGuard, unittest.TestCase):
+class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def setUp(self):
super(UtilTestCase, self).setUp()
# saving the environment
@@ -64,9 +72,9 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def test_get_host_platform(self):
with unittest.mock.patch('os.name', 'nt'):
- with unittest.mock.patch('sys.version', '... [... (ARM64)]'):
+ with unittest.mock.patch('sys.version', '... [... (ARM64)]'):
self.assertEqual(get_host_platform(), 'win-arm64')
- with unittest.mock.patch('sys.version', '... [... (ARM)]'):
+ with unittest.mock.patch('sys.version', '... [... (ARM)]'):
self.assertEqual(get_host_platform(), 'win-arm32')
with unittest.mock.patch('sys.version_info', (3, 9, 0, 'final', 0)):
@@ -75,76 +83,86 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def test_get_platform(self):
with unittest.mock.patch('os.name', 'nt'):
with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x86'}):
- self.assertEqual(get_platform(), 'win32')
+ self.assertEqual(get_platform(), 'win32')
with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x64'}):
- self.assertEqual(get_platform(), 'win-amd64')
+ self.assertEqual(get_platform(), 'win-amd64')
with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm'}):
- self.assertEqual(get_platform(), 'win-arm32')
- with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm64'}):
- self.assertEqual(get_platform(), 'win-arm64')
+ self.assertEqual(get_platform(), 'win-arm32')
+ with unittest.mock.patch.dict(
+ 'os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm64'}
+ ):
+ self.assertEqual(get_platform(), 'win-arm64')
def test_convert_path(self):
# linux/mac
os.sep = '/'
+
def _join(path):
return '/'.join(path)
+
os.path.join = _join
- self.assertEqual(convert_path('/home/to/my/stuff'),
- '/home/to/my/stuff')
+ self.assertEqual(convert_path('/home/to/my/stuff'), '/home/to/my/stuff')
# win
os.sep = '\\'
+
def _join(*path):
return '\\'.join(path)
+
os.path.join = _join
self.assertRaises(ValueError, convert_path, '/home/to/my/stuff')
self.assertRaises(ValueError, convert_path, 'home/to/my/stuff/')
- self.assertEqual(convert_path('home/to/my/stuff'),
- 'home\\to\\my\\stuff')
- self.assertEqual(convert_path('.'),
- os.curdir)
+ self.assertEqual(convert_path('home/to/my/stuff'), 'home\\to\\my\\stuff')
+ self.assertEqual(convert_path('.'), os.curdir)
def test_change_root(self):
# linux/mac
os.name = 'posix'
+
def _isabs(path):
return path[0] == '/'
+
os.path.isabs = _isabs
+
def _join(*path):
return '/'.join(path)
+
os.path.join = _join
- self.assertEqual(change_root('/root', '/old/its/here'),
- '/root/old/its/here')
- self.assertEqual(change_root('/root', 'its/here'),
- '/root/its/here')
+ self.assertEqual(change_root('/root', '/old/its/here'), '/root/old/its/here')
+ self.assertEqual(change_root('/root', 'its/here'), '/root/its/here')
# windows
os.name = 'nt'
+
def _isabs(path):
return path.startswith('c:\\')
+
os.path.isabs = _isabs
+
def _splitdrive(path):
if path.startswith('c:'):
return ('', path.replace('c:', ''))
return ('', path)
+
os.path.splitdrive = _splitdrive
+
def _join(*path):
return '\\'.join(path)
+
os.path.join = _join
- self.assertEqual(change_root('c:\\root', 'c:\\old\\its\\here'),
- 'c:\\root\\old\\its\\here')
- self.assertEqual(change_root('c:\\root', 'its\\here'),
- 'c:\\root\\its\\here')
+ self.assertEqual(
+ change_root('c:\\root', 'c:\\old\\its\\here'), 'c:\\root\\old\\its\\here'
+ )
+ self.assertEqual(change_root('c:\\root', 'its\\here'), 'c:\\root\\its\\here')
# BugsBunny os (it's a great os)
os.name = 'BugsBunny'
- self.assertRaises(DistutilsPlatformError,
- change_root, 'c:\\root', 'its\\here')
+ self.assertRaises(DistutilsPlatformError, change_root, 'c:\\root', 'its\\here')
# XXX platforms to be covered: mac
@@ -165,8 +183,9 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
import pwd
# only set pw_dir field, other fields are not used
- result = pwd.struct_passwd((None, None, None, None, None,
- '/home/distutils', None))
+ result = pwd.struct_passwd(
+ (None, None, None, None, None, '/home/distutils', None)
+ )
with mock.patch.object(pwd, 'getpwuid', return_value=result):
check_environ()
self.assertEqual(os.environ['HOME'], '/home/distutils')
@@ -180,8 +199,10 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self.assertNotIn('HOME', os.environ)
def test_split_quoted(self):
- self.assertEqual(split_quoted('""one"" "two" \'three\' \\four'),
- ['one', 'two', 'three', 'four'])
+ self.assertEqual(
+ split_quoted('""one"" "two" \'three\' \\four'),
+ ['one', 'two', 'three', 'four'],
+ )
def test_strtobool(self):
yes = ('y', 'Y', 'yes', 'True', 't', 'true', 'True', 'On', 'on', '1')
@@ -196,8 +217,9 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def test_rfc822_escape(self):
header = 'I am a\npoor\nlonesome\nheader\n'
res = rfc822_escape(header)
- wanted = ('I am a%(8s)spoor%(8s)slonesome%(8s)s'
- 'header%(8s)s') % {'8s': '\n'+8*' '}
+ wanted = ('I am a%(8s)spoor%(8s)slonesome%(8s)s' 'header%(8s)s') % {
+ '8s': '\n' + 8 * ' '
+ }
self.assertEqual(res, wanted)
def test_dont_write_bytecode(self):
@@ -220,5 +242,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(UtilTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_version.py b/setuptools/_distutils/tests/test_version.py
index 8405aa3a..cecb279f 100644
--- a/setuptools/_distutils/tests/test_version.py
+++ b/setuptools/_distutils/tests/test_version.py
@@ -5,8 +5,8 @@ from distutils.version import LooseVersion
from distutils.version import StrictVersion
from test.support import run_unittest
-class VersionTestCase(unittest.TestCase):
+class VersionTestCase(unittest.TestCase):
def setUp(self):
self.ctx = distutils.version.suppress_known_deprecation()
self.ctx.__enter__()
@@ -24,21 +24,23 @@ class VersionTestCase(unittest.TestCase):
self.assertEqual(str(version), '1.2')
def test_cmp_strict(self):
- versions = (('1.5.1', '1.5.2b2', -1),
- ('161', '3.10a', ValueError),
- ('8.02', '8.02', 0),
- ('3.4j', '1996.07.12', ValueError),
- ('3.2.pl0', '3.1.1.6', ValueError),
- ('2g6', '11g', ValueError),
- ('0.9', '2.2', -1),
- ('1.2.1', '1.2', 1),
- ('1.1', '1.2.2', -1),
- ('1.2', '1.1', 1),
- ('1.2.1', '1.2.2', -1),
- ('1.2.2', '1.2', 1),
- ('1.2', '1.2.2', -1),
- ('0.4.0', '0.4', 0),
- ('1.13++', '5.5.kw', ValueError))
+ versions = (
+ ('1.5.1', '1.5.2b2', -1),
+ ('161', '3.10a', ValueError),
+ ('8.02', '8.02', 0),
+ ('3.4j', '1996.07.12', ValueError),
+ ('3.2.pl0', '3.1.1.6', ValueError),
+ ('2g6', '11g', ValueError),
+ ('0.9', '2.2', -1),
+ ('1.2.1', '1.2', 1),
+ ('1.1', '1.2.2', -1),
+ ('1.2', '1.1', 1),
+ ('1.2.1', '1.2.2', -1),
+ ('1.2.2', '1.2', 1),
+ ('1.2', '1.2.2', -1),
+ ('0.4.0', '0.4', 0),
+ ('1.13++', '5.5.kw', ValueError),
+ )
for v1, v2, wanted in versions:
try:
@@ -47,49 +49,55 @@ class VersionTestCase(unittest.TestCase):
if wanted is ValueError:
continue
else:
- raise AssertionError(("cmp(%s, %s) "
- "shouldn't raise ValueError")
- % (v1, v2))
- self.assertEqual(res, wanted,
- 'cmp(%s, %s) should be %s, got %s' %
- (v1, v2, wanted, res))
+ raise AssertionError(
+ ("cmp(%s, %s) " "shouldn't raise ValueError") % (v1, v2)
+ )
+ self.assertEqual(
+ res, wanted, 'cmp(%s, %s) should be %s, got %s' % (v1, v2, wanted, res)
+ )
res = StrictVersion(v1)._cmp(v2)
- self.assertEqual(res, wanted,
- 'cmp(%s, %s) should be %s, got %s' %
- (v1, v2, wanted, res))
+ self.assertEqual(
+ res, wanted, 'cmp(%s, %s) should be %s, got %s' % (v1, v2, wanted, res)
+ )
res = StrictVersion(v1)._cmp(object())
- self.assertIs(res, NotImplemented,
- 'cmp(%s, %s) should be NotImplemented, got %s' %
- (v1, v2, res))
-
+ self.assertIs(
+ res,
+ NotImplemented,
+ 'cmp(%s, %s) should be NotImplemented, got %s' % (v1, v2, res),
+ )
def test_cmp(self):
- versions = (('1.5.1', '1.5.2b2', -1),
- ('161', '3.10a', 1),
- ('8.02', '8.02', 0),
- ('3.4j', '1996.07.12', -1),
- ('3.2.pl0', '3.1.1.6', 1),
- ('2g6', '11g', -1),
- ('0.960923', '2.2beta29', -1),
- ('1.13++', '5.5.kw', -1))
-
+ versions = (
+ ('1.5.1', '1.5.2b2', -1),
+ ('161', '3.10a', 1),
+ ('8.02', '8.02', 0),
+ ('3.4j', '1996.07.12', -1),
+ ('3.2.pl0', '3.1.1.6', 1),
+ ('2g6', '11g', -1),
+ ('0.960923', '2.2beta29', -1),
+ ('1.13++', '5.5.kw', -1),
+ )
for v1, v2, wanted in versions:
res = LooseVersion(v1)._cmp(LooseVersion(v2))
- self.assertEqual(res, wanted,
- 'cmp(%s, %s) should be %s, got %s' %
- (v1, v2, wanted, res))
+ self.assertEqual(
+ res, wanted, 'cmp(%s, %s) should be %s, got %s' % (v1, v2, wanted, res)
+ )
res = LooseVersion(v1)._cmp(v2)
- self.assertEqual(res, wanted,
- 'cmp(%s, %s) should be %s, got %s' %
- (v1, v2, wanted, res))
+ self.assertEqual(
+ res, wanted, 'cmp(%s, %s) should be %s, got %s' % (v1, v2, wanted, res)
+ )
res = LooseVersion(v1)._cmp(object())
- self.assertIs(res, NotImplemented,
- 'cmp(%s, %s) should be NotImplemented, got %s' %
- (v1, v2, res))
+ self.assertIs(
+ res,
+ NotImplemented,
+ 'cmp(%s, %s) should be NotImplemented, got %s' % (v1, v2, res),
+ )
+
def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(VersionTestCase)
+
if __name__ == "__main__":
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/test_versionpredicate.py b/setuptools/_distutils/tests/test_versionpredicate.py
index 28ae09dc..ce3d0f46 100644
--- a/setuptools/_distutils/tests/test_versionpredicate.py
+++ b/setuptools/_distutils/tests/test_versionpredicate.py
@@ -6,8 +6,10 @@ import distutils.versionpredicate
import doctest
from test.support import run_unittest
+
def test_suite():
return doctest.DocTestSuite(distutils.versionpredicate)
+
if __name__ == '__main__':
run_unittest(test_suite())
diff --git a/setuptools/_distutils/tests/unix_compat.py b/setuptools/_distutils/tests/unix_compat.py
index b7718c26..8250b363 100644
--- a/setuptools/_distutils/tests/unix_compat.py
+++ b/setuptools/_distutils/tests/unix_compat.py
@@ -11,6 +11,5 @@ except ImportError:
UNIX_ID_SUPPORT = grp and pwd
UID_0_SUPPORT = UNIX_ID_SUPPORT and sys.platform != "cygwin"
-require_unix_id = unittest.skipUnless(
- UNIX_ID_SUPPORT, "Requires grp and pwd support")
+require_unix_id = unittest.skipUnless(UNIX_ID_SUPPORT, "Requires grp and pwd support")
require_uid_0 = unittest.skipUnless(UID_0_SUPPORT, "Requires UID 0 support")