summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxoviat <xoviat@users.noreply.github.com>2017-11-08 16:41:32 -0600
committerJason R. Coombs <jaraco@jaraco.com>2020-05-25 15:57:07 -0400
commitcd7d6d56a1cf84cafea44f7cf7e357a926821f03 (patch)
tree751497929ea17cfab861942590197d2b574d7dfd /tests
parent5210488f65e41038e5721d31792fae784c39d649 (diff)
downloadpython-setuptools-git-cd7d6d56a1cf84cafea44f7cf7e357a926821f03.tar.gz
[maint] move all files into subfolder
Diffstat (limited to 'tests')
-rw-r--r--tests/Setup.sample67
-rw-r--r--tests/__init__.py42
-rw-r--r--tests/includetest.rst1
-rw-r--r--tests/support.py209
-rw-r--r--tests/test_archive_util.py394
-rw-r--r--tests/test_bdist.py57
-rw-r--r--tests/test_bdist_dumb.py97
-rw-r--r--tests/test_bdist_msi.py26
-rw-r--r--tests/test_bdist_rpm.py135
-rw-r--r--tests/test_bdist_wininst.py38
-rw-r--r--tests/test_build.py56
-rw-r--r--tests/test_build_clib.py134
-rw-r--r--tests/test_build_ext.py545
-rw-r--r--tests/test_build_py.py179
-rw-r--r--tests/test_build_scripts.py112
-rw-r--r--tests/test_check.py163
-rw-r--r--tests/test_clean.py49
-rw-r--r--tests/test_cmd.py126
-rw-r--r--tests/test_config.py141
-rw-r--r--tests/test_config_cmd.py96
-rw-r--r--tests/test_core.py140
-rw-r--r--tests/test_cygwinccompiler.py154
-rw-r--r--tests/test_dep_util.py80
-rw-r--r--tests/test_dir_util.py139
-rw-r--r--tests/test_dist.py528
-rw-r--r--tests/test_extension.py69
-rw-r--r--tests/test_file_util.py122
-rw-r--r--tests/test_filelist.py340
-rw-r--r--tests/test_install.py249
-rw-r--r--tests/test_install_data.py75
-rw-r--r--tests/test_install_headers.py39
-rw-r--r--tests/test_install_lib.py115
-rw-r--r--tests/test_install_scripts.py82
-rw-r--r--tests/test_log.py46
-rw-r--r--tests/test_msvc9compiler.py184
-rw-r--r--tests/test_msvccompiler.py81
-rw-r--r--tests/test_register.py323
-rw-r--r--tests/test_sdist.py492
-rw-r--r--tests/test_spawn.py132
-rw-r--r--tests/test_sysconfig.py274
-rw-r--r--tests/test_text_file.py107
-rw-r--r--tests/test_unixccompiler.py141
-rw-r--r--tests/test_upload.py223
-rw-r--r--tests/test_util.py309
-rw-r--r--tests/test_version.py87
-rw-r--r--tests/test_versionpredicate.py13
46 files changed, 0 insertions, 7211 deletions
diff --git a/tests/Setup.sample b/tests/Setup.sample
deleted file mode 100644
index 36c4290d..00000000
--- a/tests/Setup.sample
+++ /dev/null
@@ -1,67 +0,0 @@
-# Setup file from the pygame project
-
-#--StartConfig
-SDL = -I/usr/include/SDL -D_REENTRANT -lSDL
-FONT = -lSDL_ttf
-IMAGE = -lSDL_image
-MIXER = -lSDL_mixer
-SMPEG = -lsmpeg
-PNG = -lpng
-JPEG = -ljpeg
-SCRAP = -lX11
-PORTMIDI = -lportmidi
-PORTTIME = -lporttime
-#--EndConfig
-
-#DEBUG = -C-W -C-Wall
-DEBUG =
-
-#the following modules are optional. you will want to compile
-#everything you can, but you can ignore ones you don't have
-#dependencies for, just comment them out
-
-imageext src/imageext.c $(SDL) $(IMAGE) $(PNG) $(JPEG) $(DEBUG)
-font src/font.c $(SDL) $(FONT) $(DEBUG)
-mixer src/mixer.c $(SDL) $(MIXER) $(DEBUG)
-mixer_music src/music.c $(SDL) $(MIXER) $(DEBUG)
-_numericsurfarray src/_numericsurfarray.c $(SDL) $(DEBUG)
-_numericsndarray src/_numericsndarray.c $(SDL) $(MIXER) $(DEBUG)
-movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
-scrap src/scrap.c $(SDL) $(SCRAP) $(DEBUG)
-_camera src/_camera.c src/camera_v4l2.c src/camera_v4l.c $(SDL) $(DEBUG)
-pypm src/pypm.c $(SDL) $(PORTMIDI) $(PORTTIME) $(DEBUG)
-
-GFX = src/SDL_gfx/SDL_gfxPrimitives.c
-#GFX = src/SDL_gfx/SDL_gfxBlitFunc.c src/SDL_gfx/SDL_gfxPrimitives.c
-gfxdraw src/gfxdraw.c $(SDL) $(GFX) $(DEBUG)
-
-
-
-#these modules are required for pygame to run. they only require
-#SDL as a dependency. these should not be altered
-
-base src/base.c $(SDL) $(DEBUG)
-cdrom src/cdrom.c $(SDL) $(DEBUG)
-color src/color.c $(SDL) $(DEBUG)
-constants src/constants.c $(SDL) $(DEBUG)
-display src/display.c $(SDL) $(DEBUG)
-event src/event.c $(SDL) $(DEBUG)
-fastevent src/fastevent.c src/fastevents.c $(SDL) $(DEBUG)
-key src/key.c $(SDL) $(DEBUG)
-mouse src/mouse.c $(SDL) $(DEBUG)
-rect src/rect.c $(SDL) $(DEBUG)
-rwobject src/rwobject.c $(SDL) $(DEBUG)
-surface src/surface.c src/alphablit.c src/surface_fill.c $(SDL) $(DEBUG)
-surflock src/surflock.c $(SDL) $(DEBUG)
-time src/time.c $(SDL) $(DEBUG)
-joystick src/joystick.c $(SDL) $(DEBUG)
-draw src/draw.c $(SDL) $(DEBUG)
-image src/image.c $(SDL) $(DEBUG)
-overlay src/overlay.c $(SDL) $(DEBUG)
-transform src/transform.c src/rotozoom.c src/scale2x.c src/scale_mmx.c $(SDL) $(DEBUG)
-mask src/mask.c src/bitmask.c $(SDL) $(DEBUG)
-bufferproxy src/bufferproxy.c $(SDL) $(DEBUG)
-pixelarray src/pixelarray.c $(SDL) $(DEBUG)
-_arraysurfarray src/_arraysurfarray.c $(SDL) $(DEBUG)
-
-
diff --git a/tests/__init__.py b/tests/__init__.py
deleted file mode 100644
index 5d2e69e3..00000000
--- a/tests/__init__.py
+++ /dev/null
@@ -1,42 +0,0 @@
-"""Test suite for distutils.
-
-This test suite consists of a collection of test modules in the
-distutils.tests package. Each test module has a name starting with
-'test' and contains a function test_suite(). The function is expected
-to return an initialized unittest.TestSuite instance.
-
-Tests for the command classes in the distutils.command package are
-included in distutils.tests as well, instead of using a separate
-distutils.command.tests package, since command identification is done
-by import rather than matching pre-defined names.
-
-"""
-
-import os
-import sys
-import unittest
-import warnings
-from test.support import run_unittest
-
-
-here = os.path.dirname(__file__) or os.curdir
-
-
-def test_suite():
- old_filters = warnings.filters[:]
- suite = unittest.TestSuite()
- for fn in os.listdir(here):
- if fn.startswith("test") and fn.endswith(".py"):
- modname = "distutils.tests." + fn[:-3]
- __import__(modname)
- module = sys.modules[modname]
- suite.addTest(module.test_suite())
- # bpo-40055: Save/restore warnings filters to leave them unchanged.
- # Importing tests imports docutils which imports pkg_resources which adds a
- # warnings filter.
- warnings.filters[:] = old_filters
- return suite
-
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/includetest.rst b/tests/includetest.rst
deleted file mode 100644
index d7b4ae38..00000000
--- a/tests/includetest.rst
+++ /dev/null
@@ -1 +0,0 @@
-This should be included.
diff --git a/tests/support.py b/tests/support.py
deleted file mode 100644
index 259af882..00000000
--- a/tests/support.py
+++ /dev/null
@@ -1,209 +0,0 @@
-"""Support code for distutils test cases."""
-import os
-import sys
-import shutil
-import tempfile
-import unittest
-import sysconfig
-from copy import deepcopy
-import test.support
-
-from distutils import log
-from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
-from distutils.core import Distribution
-
-
-class LoggingSilencer(object):
-
- def setUp(self):
- super().setUp()
- self.threshold = log.set_threshold(log.FATAL)
- # catching warnings
- # when log will be replaced by logging
- # we won't need such monkey-patch anymore
- self._old_log = log.Log._log
- log.Log._log = self._log
- self.logs = []
-
- def tearDown(self):
- log.set_threshold(self.threshold)
- log.Log._log = self._old_log
- super().tearDown()
-
- def _log(self, level, msg, args):
- 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__))
- 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]
-
- def clear_logs(self):
- self.logs = []
-
-
-class TempdirManager(object):
- """Mix-in class that handles temporary directories for test cases.
-
- This is intended to be used with unittest.TestCase.
- """
-
- def setUp(self):
- super().setUp()
- self.old_cwd = os.getcwd()
- self.tempdirs = []
-
- def tearDown(self):
- # Restore working dir, for Solaris and derivatives, where rmdir()
- # on the current directory fails.
- os.chdir(self.old_cwd)
- super().tearDown()
- while self.tempdirs:
- tmpdir = self.tempdirs.pop()
- test.support.rmtree(tmpdir)
-
- def mkdtemp(self):
- """Create a temporary directory that will be cleaned up.
-
- Returns the path of the directory.
- """
- d = tempfile.mkdtemp()
- self.tempdirs.append(d)
- return d
-
- def write_file(self, path, content='xxx'):
- """Writes a file in the given path.
-
-
- path can be a string or a sequence.
- """
- if isinstance(path, (list, tuple)):
- path = os.path.join(*path)
- f = open(path, 'w')
- try:
- f.write(content)
- finally:
- f.close()
-
- def create_dist(self, pkg_name='foo', **kw):
- """Will generate a test environment.
-
- This function creates:
- - a Distribution instance using keywords
- - a temporary directory with a package structure
-
- It returns the package directory and the distribution
- instance.
- """
- tmp_dir = self.mkdtemp()
- pkg_dir = os.path.join(tmp_dir, pkg_name)
- os.mkdir(pkg_dir)
- dist = Distribution(attrs=kw)
-
- return pkg_dir, dist
-
-
-class DummyCommand:
- """Class to store options for retrieval via set_undefined_options()."""
-
- def __init__(self, **kwargs):
- for kw, val in kwargs.items():
- setattr(self, kw, val)
-
- def ensure_finalized(self):
- pass
-
-
-class EnvironGuard(object):
-
- def setUp(self):
- super(EnvironGuard, self).setUp()
- self.old_environ = deepcopy(os.environ)
-
- def tearDown(self):
- for key, value in self.old_environ.items():
- if os.environ.get(key) != value:
- os.environ[key] = value
-
- for key in tuple(os.environ.keys()):
- if key not in self.old_environ:
- del os.environ[key]
-
- super(EnvironGuard, self).tearDown()
-
-
-def copy_xxmodule_c(directory):
- """Helper for tests that need the xxmodule.c source file.
-
- Example use:
-
- def test_compile(self):
- copy_xxmodule_c(self.tmpdir)
- self.assertIn('xxmodule.c', os.listdir(self.tmpdir))
-
- If the source file can be found, it will be copied to *directory*. If not,
- the test will be skipped. Errors during copy are not caught.
- """
- filename = _get_xxmodule_path()
- if filename is None:
- raise unittest.SkipTest('cannot find xxmodule.c (test must run in '
- 'the python build dir)')
- shutil.copy(filename, directory)
-
-
-def _get_xxmodule_path():
- srcdir = sysconfig.get_config_var('srcdir')
- candidates = [
- # use installed copy if available
- os.path.join(os.path.dirname(__file__), 'xxmodule.c'),
- # otherwise try using copy from build directory
- os.path.join(srcdir, 'Modules', 'xxmodule.c'),
- # srcdir mysteriously can be $srcdir/Lib/distutils/tests when
- # this file is run from its parent directory, so walk up the
- # tree to find the real srcdir
- os.path.join(srcdir, '..', '..', '..', 'Modules', 'xxmodule.c'),
- ]
- for path in candidates:
- if os.path.exists(path):
- return path
-
-
-def fixup_build_ext(cmd):
- """Function needed to make build_ext tests pass.
-
- When Python was built with --enable-shared on Unix, -L. is not enough to
- find libpython<blah>.so, because regrtest runs in a tempdir, not in the
- source directory where the .so lives.
-
- When Python was built with in debug mode on Windows, build_ext commands
- need their debug attribute set, and it is not done automatically for
- some reason.
-
- This function handles both of these things. Example use:
-
- cmd = build_ext(dist)
- support.fixup_build_ext(cmd)
- cmd.ensure_finalized()
-
- Unlike most other Unix platforms, Mac OS X embeds absolute paths
- to shared libraries into executables, so the fixup is not needed there.
- """
- if os.name == 'nt':
- cmd.debug = sys.executable.endswith('_d.exe')
- elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
- # To further add to the shared builds fun on Unix, we can't just add
- # library_dirs to the Extension() instance because that doesn't get
- # plumbed through to the final compiler command.
- runshared = sysconfig.get_config_var('RUNSHARED')
- if runshared is None:
- cmd.library_dirs = ['.']
- else:
- if sys.platform == 'darwin':
- cmd.library_dirs = []
- else:
- name, equals, value = runshared.partition('=')
- cmd.library_dirs = [d for d in value.split(os.pathsep) if d]
diff --git a/tests/test_archive_util.py b/tests/test_archive_util.py
deleted file mode 100644
index e9aad0e4..00000000
--- a/tests/test_archive_util.py
+++ /dev/null
@@ -1,394 +0,0 @@
-# -*- coding: utf-8 -*-
-"""Tests for distutils.archive_util."""
-import unittest
-import os
-import sys
-import tarfile
-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.spawn import find_executable, spawn
-from distutils.tests import support
-from test.support import check_warnings, run_unittest, patch, change_cwd
-
-try:
- import grp
- import pwd
- UID_GID_SUPPORT = True
-except ImportError:
- UID_GID_SUPPORT = False
-
-try:
- import zipfile
- ZIP_SUPPORT = True
-except ImportError:
- ZIP_SUPPORT = find_executable('zip')
-
-try:
- import zlib
- ZLIB_SUPPORT = True
-except ImportError:
- ZLIB_SUPPORT = False
-
-try:
- import bz2
-except ImportError:
- bz2 = None
-
-try:
- import lzma
-except ImportError:
- lzma = None
-
-def can_fs_encode(filename):
- """
- Return True if the filename can be saved in the file system.
- """
- if os.path.supports_unicode_filenames:
- return True
- try:
- filename.encode(sys.getfilesystemencoding())
- except UnicodeEncodeError:
- return False
- return True
-
-
-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
- tmpdir = self._create_files()
- self._make_tarball(tmpdir, name, '.tar.gz')
- # trying an uncompressed one
- self._make_tarball(tmpdir, name, '.tar', compress=None)
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_make_tarball_gzip(self):
- tmpdir = self._create_files()
- self._make_tarball(tmpdir, 'archive', '.tar.gz', compress='gzip')
-
- @unittest.skipUnless(bz2, 'Need bz2 support to run')
- def test_make_tarball_bzip2(self):
- tmpdir = self._create_files()
- self._make_tarball(tmpdir, 'archive', '.tar.bz2', compress='bzip2')
-
- @unittest.skipUnless(lzma, 'Need lzma support to run')
- def test_make_tarball_xz(self):
- 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')
- 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
-
- @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
-
- 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")
-
- base_name = os.path.join(tmpdir2, target_name)
-
- # working with relative paths to avoid tar warnings
- with change_cwd(tmpdir):
- make_tarball(splitdrive(base_name)[1], 'dist', **kwargs)
-
- # check if the compressed tarball was created
- tarball = base_name + suffix
- self.assertTrue(os.path.exists(tarball))
- self.assertEqual(self._tarinfo(tarball), self._created_files)
-
- def _tarinfo(self, path):
- tar = tarfile.open(path)
- try:
- names = tar.getnames()
- names.sort()
- return names
- finally:
- tar.close()
-
- _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):
- # creating something to tar
- tmpdir = self.mkdtemp()
- dist = os.path.join(tmpdir, 'dist')
- os.mkdir(dist)
- self.write_file([dist, 'file1'], 'xxx')
- self.write_file([dist, 'file2'], 'xxx')
- os.mkdir(os.path.join(dist, 'sub'))
- self.write_file([dist, 'sub', 'file3'], 'xxx')
- 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')
- def test_tarfile_vs_tar(self):
- tmpdir = self._create_files()
- tmpdir2 = self.mkdtemp()
- base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(base_name, 'dist')
- finally:
- os.chdir(old_dir)
-
- # check if the compressed tarball was created
- tarball = base_name + '.tar.gz'
- self.assertTrue(os.path.exists(tarball))
-
- # now create another tarball using `tar`
- tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
- tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
- gzip_cmd = ['gzip', '-f', '-9', 'archive2.tar']
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- spawn(tar_cmd)
- spawn(gzip_cmd)
- finally:
- os.chdir(old_dir)
-
- self.assertTrue(os.path.exists(tarball2))
- # let's compare both tarballs
- self.assertEqual(self._tarinfo(tarball), self._created_files)
- self.assertEqual(self._tarinfo(tarball2), self._created_files)
-
- # trying an uncompressed one
- base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(base_name, 'dist', compress=None)
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar'
- self.assertTrue(os.path.exists(tarball))
-
- # now for a dry_run
- base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(base_name, 'dist', compress=None, dry_run=True)
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar'
- self.assertTrue(os.path.exists(tarball))
-
- @unittest.skipUnless(find_executable('compress'),
- 'The compress program is required')
- def test_compress_deprecated(self):
- tmpdir = self._create_files()
- base_name = os.path.join(self.mkdtemp(), 'archive')
-
- # using compress and testing the PendingDeprecationWarning
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- with check_warnings() as w:
- warnings.simplefilter("always")
- make_tarball(base_name, 'dist', compress='compress')
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar.Z'
- self.assertTrue(os.path.exists(tarball))
- self.assertEqual(len(w.warnings), 1)
-
- # same test with dry_run
- os.remove(tarball)
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- with check_warnings() as w:
- warnings.simplefilter("always")
- 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')
- def test_make_zipfile(self):
- # creating something to tar
- tmpdir = self._create_files()
- base_name = os.path.join(self.mkdtemp(), 'archive')
- with change_cwd(tmpdir):
- make_zipfile(base_name, 'dist')
-
- # check if the compressed tarball was created
- tarball = base_name + '.zip'
- self.assertTrue(os.path.exists(tarball))
- with zipfile.ZipFile(tarball) as zf:
- self.assertEqual(sorted(zf.namelist()), self._zip_created_files)
-
- @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
- def test_make_zipfile_no_zlib(self):
- patch(self, archive_util.zipfile, 'zlib', None) # force zlib ImportError
-
- called = []
- zipfile_class = zipfile.ZipFile
- def fake_zipfile(*a, **kw):
- if kw.get('compression', None) == zipfile.ZIP_STORED:
- called.append((a, kw))
- return zipfile_class(*a, **kw)
-
- patch(self, archive_util.zipfile, 'ZipFile', fake_zipfile)
-
- # create something to tar and compress
- tmpdir = self._create_files()
- base_name = os.path.join(self.mkdtemp(), 'archive')
- with change_cwd(tmpdir):
- make_zipfile(base_name, 'dist')
-
- tarball = base_name + '.zip'
- 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']))
-
- def test_make_archive(self):
- tmpdir = self.mkdtemp()
- base_name = os.path.join(tmpdir, 'archive')
- self.assertRaises(ValueError, make_archive, base_name, 'xxx')
-
- def test_make_archive_cwd(self):
- current_dir = os.getcwd()
- def _breaks(*args, **kw):
- raise RuntimeError()
- ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
- try:
- try:
- make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
- except:
- pass
- self.assertEqual(os.getcwd(), current_dir)
- finally:
- del ARCHIVE_FORMATS['xxx']
-
- def test_make_archive_tar(self):
- 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')
- self.assertEqual(self._tarinfo(res), self._created_files)
-
- @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')
- res = make_archive(base_name, 'gztar', base_dir, 'dist')
- self.assertTrue(os.path.exists(res))
- self.assertEqual(os.path.basename(res), 'archive.tar.gz')
- self.assertEqual(self._tarinfo(res), self._created_files)
-
- @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')
- res = make_archive(base_name, 'bztar', base_dir, 'dist')
- self.assertTrue(os.path.exists(res))
- self.assertEqual(os.path.basename(res), 'archive.tar.bz2')
- self.assertEqual(self._tarinfo(res), self._created_files)
-
- @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')
- res = make_archive(base_name, 'xztar', base_dir, 'dist')
- self.assertTrue(os.path.exists(res))
- self.assertEqual(os.path.basename(res), 'archive.tar.xz')
- self.assertEqual(self._tarinfo(res), self._created_files)
-
- def test_make_archive_owner_group(self):
- # testing make_archive with owner and group, with various combinations
- # this works even if there's not gid/uid support
- if UID_GID_SUPPORT:
- group = grp.getgrgid(0)[0]
- owner = pwd.getpwuid(0)[0]
- else:
- group = owner = 'root'
-
- 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)
- 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)
- self.assertTrue(os.path.exists(res))
-
- 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")
- @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
- def test_tarfile_root_owner(self):
- 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)
- finally:
- os.chdir(old_dir)
-
- # check if the compressed tarball was created
- self.assertTrue(os.path.exists(archive_name))
-
- # now checks the rights
- archive = tarfile.open(archive_name)
- try:
- for member in archive.getmembers():
- self.assertEqual(member.uid, 0)
- self.assertEqual(member.gid, 0)
- finally:
- archive.close()
-
-def test_suite():
- return unittest.makeSuite(ArchiveUtilTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_bdist.py b/tests/test_bdist.py
deleted file mode 100644
index 130d8bf1..00000000
--- a/tests/test_bdist.py
+++ /dev/null
@@ -1,57 +0,0 @@
-"""Tests for distutils.command.bdist."""
-import os
-import unittest
-from test.support import run_unittest
-import warnings
-
-from distutils.command.bdist import bdist
-from distutils.tests import support
-
-
-class BuildTestCase(support.TempdirManager,
- unittest.TestCase):
-
- def test_formats(self):
- # let's create a command and make sure
- # we can set the format
- dist = self.create_dist()[1]
- cmd = bdist(dist)
- cmd.formats = ['msi']
- cmd.ensure_finalized()
- self.assertEqual(cmd.formats, ['msi'])
-
- # what formats does bdist offer?
- formats = ['bztar', 'gztar', 'msi', 'rpm', 'tar',
- 'wininst', 'xztar', 'zip', 'ztar']
- found = sorted(cmd.format_command)
- self.assertEqual(found, formats)
-
- def test_skip_build(self):
- # bug #10946: bdist --skip-build should trickle down to subcommands
- dist = self.create_dist()[1]
- cmd = bdist(dist)
- cmd.skip_build = 1
- cmd.ensure_finalized()
- dist.command_obj['bdist'] = cmd
-
- 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)
- 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)
-
-
-def test_suite():
- return unittest.makeSuite(BuildTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_bdist_dumb.py b/tests/test_bdist_dumb.py
deleted file mode 100644
index 01a233bc..00000000
--- a/tests/test_bdist_dumb.py
+++ /dev/null
@@ -1,97 +0,0 @@
-"""Tests for distutils.command.bdist_dumb."""
-
-import os
-import sys
-import zipfile
-import unittest
-from test.support import run_unittest
-
-from distutils.core import Distribution
-from distutils.command.bdist_dumb import bdist_dumb
-from distutils.tests import support
-
-SETUP_PY = """\
-from distutils.core import setup
-import foo
-
-setup(name='foo', version='0.1', py_modules=['foo'],
- url='xxx', author='xxx', author_email='xxx')
-
-"""
-
-try:
- import zlib
- ZLIB_SUPPORT = True
-except ImportError:
- ZLIB_SUPPORT = False
-
-
-class BuildDumbTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- super(BuildDumbTestCase, self).setUp()
- self.old_location = os.getcwd()
- self.old_sys_argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- os.chdir(self.old_location)
- sys.argv = self.old_sys_argv[0]
- sys.argv[:] = self.old_sys_argv[1]
- super(BuildDumbTestCase, self).tearDown()
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_simple_built(self):
-
- # let's create a simple package
- tmp_dir = self.mkdtemp()
- pkg_dir = os.path.join(tmp_dir, 'foo')
- os.mkdir(pkg_dir)
- self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
- self.write_file((pkg_dir, 'foo.py'), '#')
- 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.script_name = 'setup.py'
- os.chdir(pkg_dir)
-
- sys.argv = ['setup.py']
- cmd = bdist_dumb(dist)
-
- # so the output is the same no matter
- # what is the platform
- cmd.format = 'zip'
-
- cmd.ensure_finalized()
- cmd.run()
-
- # see what we have
- dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
- base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
-
- self.assertEqual(dist_created, [base])
-
- # now let's check what we have in the zip file
- fp = zipfile.ZipFile(os.path.join('dist', base))
- try:
- contents = fp.namelist()
- finally:
- fp.close()
-
- contents = sorted(filter(None, map(os.path.basename, contents)))
- wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
- if not sys.dont_write_bytecode:
- wanted.append('foo.%s.pyc' % sys.implementation.cache_tag)
- self.assertEqual(contents, sorted(wanted))
-
-def test_suite():
- return unittest.makeSuite(BuildDumbTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_bdist_msi.py b/tests/test_bdist_msi.py
deleted file mode 100644
index 418e60ec..00000000
--- a/tests/test_bdist_msi.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""Tests for distutils.command.bdist_msi."""
-import sys
-import unittest
-from test.support import run_unittest, check_warnings
-from distutils.tests import support
-
-
-@unittest.skipUnless(sys.platform == 'win32', 'these tests require Windows')
-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)
- cmd.ensure_finalized()
-
-
-def test_suite():
- return unittest.makeSuite(BDistMSITestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_bdist_rpm.py b/tests/test_bdist_rpm.py
deleted file mode 100644
index 6453a02b..00000000
--- a/tests/test_bdist_rpm.py
+++ /dev/null
@@ -1,135 +0,0 @@
-"""Tests for distutils.command.bdist_rpm."""
-
-import unittest
-import sys
-import os
-from test.support import run_unittest, requires_zlib
-
-from distutils.core import Distribution
-from distutils.command.bdist_rpm import bdist_rpm
-from distutils.tests import support
-from distutils.spawn import find_executable
-
-SETUP_PY = """\
-from distutils.core import setup
-import foo
-
-setup(name='foo', version='0.1', py_modules=['foo'],
- url='xxx', author='xxx', author_email='xxx')
-
-"""
-
-class BuildRpmTestCase(support.TempdirManager,
- support.EnvironGuard,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def setUp(self):
- try:
- sys.executable.encode("UTF-8")
- except UnicodeEncodeError:
- raise unittest.SkipTest("sys.executable is not encodable to UTF-8")
-
- super(BuildRpmTestCase, self).setUp()
- self.old_location = os.getcwd()
- self.old_sys_argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- os.chdir(self.old_location)
- sys.argv = self.old_sys_argv[0]
- sys.argv[:] = self.old_sys_argv[1]
- super(BuildRpmTestCase, self).tearDown()
-
- # 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')
- @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')
- def test_quiet(self):
- # let's create a package
- tmp_dir = self.mkdtemp()
- 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)
- self.write_file((pkg_dir, 'foo.py'), '#')
- 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.script_name = 'setup.py'
- os.chdir(pkg_dir)
-
- sys.argv = ['setup.py']
- cmd = bdist_rpm(dist)
- cmd.fix_python = True
-
- # running in quiet mode
- cmd.quiet = 1
- cmd.ensure_finalized()
- cmd.run()
-
- dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
- self.assertIn('foo-0.1-1.noarch.rpm', dist_created)
-
- # 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)
-
- # 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')
- @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')
- 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
- pkg_dir = os.path.join(tmp_dir, 'foo')
- os.mkdir(pkg_dir)
- self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
- self.write_file((pkg_dir, 'foo.py'), '#')
- 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.script_name = 'setup.py'
- os.chdir(pkg_dir)
-
- sys.argv = ['setup.py']
- cmd = bdist_rpm(dist)
- cmd.fix_python = True
-
- cmd.quiet = 1
- cmd.ensure_finalized()
- cmd.run()
-
- dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
- self.assertIn('foo-0.1-1.noarch.rpm', dist_created)
-
- # 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)
-
- os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
-
-def test_suite():
- return unittest.makeSuite(BuildRpmTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_bdist_wininst.py b/tests/test_bdist_wininst.py
deleted file mode 100644
index 5c3d025d..00000000
--- a/tests/test_bdist_wininst.py
+++ /dev/null
@@ -1,38 +0,0 @@
-"""Tests for distutils.command.bdist_wininst."""
-import sys
-import platform
-import unittest
-from test.support import run_unittest, 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):
-
- def test_get_exe_bytes(self):
-
- # issue5731: command was broken on non-windows platforms
- # this test makes sure it works now for every platform
- # let's create a command
- pkg_pth, dist = self.create_dist()
- with check_warnings(("", DeprecationWarning)):
- cmd = bdist_wininst(dist)
- cmd.ensure_finalized()
-
- # let's run the code that finds the right wininst*.exe file
- # and make sure it finds it and returns its content
- # no matter what platform we have
- exe_file = cmd.get_exe_bytes()
- self.assertGreater(len(exe_file), 10)
-
-def test_suite():
- return unittest.makeSuite(BuildWinInstTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_build.py b/tests/test_build.py
deleted file mode 100644
index b020a5ba..00000000
--- a/tests/test_build.py
+++ /dev/null
@@ -1,56 +0,0 @@
-"""Tests for distutils.command.build."""
-import unittest
-import os
-import sys
-from test.support import run_unittest
-
-from distutils.command.build import build
-from distutils.tests import support
-from sysconfig import get_platform
-
-class BuildTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- cmd = build(dist)
- cmd.finalize_options()
-
- # if not specified, plat_name gets the current platform
- self.assertEqual(cmd.plat_name, get_platform())
-
- # build_purelib is build + lib
- wanted = os.path.join(cmd.build_base, 'lib')
- self.assertEqual(cmd.build_purelib, wanted)
-
- # build_platlib is 'build/lib.platform-x.x[-pydebug]'
- # examples:
- # build/lib.macosx-10.3-i386-2.7
- plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
- if hasattr(sys, 'gettotalrefcount'):
- self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
- plat_spec += '-pydebug'
- wanted = os.path.join(cmd.build_base, 'lib' + plat_spec)
- self.assertEqual(cmd.build_platlib, wanted)
-
- # by default, build_lib = build_purelib
- self.assertEqual(cmd.build_lib, cmd.build_purelib)
-
- # build_temp is build/temp.<plat>
- wanted = os.path.join(cmd.build_base, 'temp' + plat_spec)
- 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])
- 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.makeSuite(BuildTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_build_clib.py b/tests/test_build_clib.py
deleted file mode 100644
index abd83137..00000000
--- a/tests/test_build_clib.py
+++ /dev/null
@@ -1,134 +0,0 @@
-"""Tests for distutils.command.build_clib."""
-import unittest
-import os
-import sys
-
-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):
-
- def test_check_library_dist(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- # 'libraries' option must be a list
- 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'])
-
- # 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')])
-
- # library name may not contain directory separators
- 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')])
-
- # those work
- libs = [('name', {}), ('name', {'ok': 'good'})]
- cmd.check_library_list(libs)
-
- def test_get_source_files(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- # "in 'libraries' option 'sources' must be present and must be
- # a list of source filenames
- cmd.libraries = [('name', {})]
- self.assertRaises(DistutilsSetupError, cmd.get_source_files)
-
- cmd.libraries = [('name', {'sources': 1})]
- self.assertRaises(DistutilsSetupError, cmd.get_source_files)
-
- cmd.libraries = [('name', {'sources': ['a', 'b']})]
- self.assertEqual(cmd.get_source_files(), ['a', 'b'])
-
- cmd.libraries = [('name', {'sources': ('a', 'b')})]
- self.assertEqual(cmd.get_source_files(), ['a', 'b'])
-
- 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()
-
- # build_libraries is also doing a bit of typo checking
- lib = [('name', {'sources': 'notvalid'})]
- self.assertRaises(DistutilsSetupError, cmd.build_libraries, lib)
-
- lib = [('name', {'sources': list()})]
- cmd.build_libraries(lib)
-
- lib = [('name', {'sources': tuple()})]
- cmd.build_libraries(lib)
-
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- cmd.include_dirs = 'one-dir'
- cmd.finalize_options()
- self.assertEqual(cmd.include_dirs, ['one-dir'])
-
- cmd.include_dirs = None
- cmd.finalize_options()
- self.assertEqual(cmd.include_dirs, [])
-
- cmd.distribution.libraries = 'WONTWORK'
- self.assertRaises(DistutilsSetupError, cmd.finalize_options)
-
- @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
- def test_run(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- foo_c = os.path.join(pkg_dir, 'foo.c')
- self.write_file(foo_c, 'int main(void) { return 1;}\n')
- cmd.libraries = [('foo', {'sources': [foo_c]})]
-
- build_temp = os.path.join(pkg_dir, 'build')
- os.mkdir(build_temp)
- cmd.build_temp = build_temp
- cmd.build_clib = build_temp
-
- # Before we run the command, we want to make sure
- # all commands are present on the system.
- ccmd = missing_compiler_executable()
- if ccmd is not None:
- self.skipTest('The %r command is not found' % ccmd)
-
- # this should work
- cmd.run()
-
- # let's check the result
- self.assertIn('libfoo.a', os.listdir(build_temp))
-
-def test_suite():
- return unittest.makeSuite(BuildCLibTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_build_ext.py b/tests/test_build_ext.py
deleted file mode 100644
index 5e47e077..00000000
--- a/tests/test_build_ext.py
+++ /dev/null
@@ -1,545 +0,0 @@
-import sys
-import os
-from io import StringIO
-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.extension import Extension
-from distutils.errors import (
- CompileError, DistutilsPlatformError, DistutilsSetupError,
- UnknownFileError)
-
-import unittest
-from test import support
-from test.support.script_helper import assert_python_ok
-
-# http://bugs.python.org/issue4373
-# Don't load the xx module more than once.
-ALREADY_TESTED = False
-
-
-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
- # working directory. Create a temporary working directory to cleanup
- # everything at the end of the test.
- change_cwd = support.change_cwd(self.tmp_dir)
- change_cwd.__enter__()
- self.addCleanup(change_cwd.__exit__, None, None, None)
-
- 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()
-
- def build_ext(self, *args, **kwargs):
- return build_ext(*args, **kwargs)
-
- def test_build_ext(self):
- cmd = support.missing_compiler_executable()
- if cmd is not None:
- self.skipTest('The %r command is not found' % cmd)
- global ALREADY_TESTED
- copy_xxmodule_c(self.tmp_dir)
- xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
- xx_ext = Extension('xx', [xx_c])
- dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
- dist.package_dir = self.tmp_dir
- cmd = self.build_ext(dist)
- fixup_build_ext(cmd)
- cmd.build_lib = self.tmp_dir
- cmd.build_temp = self.tmp_dir
-
- old_stdout = sys.stdout
- if not support.verbose:
- # silence compiler output
- sys.stdout = StringIO()
- try:
- cmd.ensure_finalized()
- cmd.run()
- finally:
- sys.stdout = old_stdout
-
- if ALREADY_TESTED:
- self.skipTest('Already tested in %s' % ALREADY_TESTED)
- else:
- ALREADY_TESTED = type(self).__name__
-
- code = textwrap.dedent(f"""
- tmp_dir = {self.tmp_dir!r}
-
- import sys
- import unittest
- from test import support
-
- sys.path.insert(0, tmp_dir)
- import xx
-
- class Tests(unittest.TestCase):
- def test_xx(self):
- for attr in ('error', 'foo', 'new', 'roj'):
- self.assertTrue(hasattr(xx, attr))
-
- self.assertEqual(xx.foo(2, 5), 7)
- self.assertEqual(xx.foo(13,15), 28)
- self.assertEqual(xx.new().demo(), None)
- if support.HAVE_DOCSTRINGS:
- doc = 'This is a template module just for instruction.'
- self.assertEqual(xx.__doc__, doc)
- self.assertIsInstance(xx.Null(), xx.Null)
- self.assertIsInstance(xx.Str(), xx.Str)
-
-
- unittest.main()
- """)
- assert_python_ok('-c', code)
-
- def test_solaris_enable_shared(self):
- dist = Distribution({'name': 'xx'})
- cmd = self.build_ext(dist)
- old = sys.platform
-
- 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:
- cmd.ensure_finalized()
- finally:
- sys.platform = old
- if old_var is None:
- del _config_vars['Py_ENABLE_SHARED']
- else:
- _config_vars['Py_ENABLE_SHARED'] = old_var
-
- # make sure we get some library dirs under solaris
- self.assertGreater(len(cmd.library_dirs), 0)
-
- 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]
- self.assertIn('user', options)
-
- # setting a value
- cmd.user = 1
-
- # setting user based lib and include
- lib = os.path.join(site.USER_BASE, 'lib')
- incl = os.path.join(site.USER_BASE, 'include')
- os.mkdir(lib)
- os.mkdir(incl)
-
- # let's run finalize
- cmd.ensure_finalized()
-
- # see if include_dirs and library_dirs
- # were set
- self.assertIn(lib, cmd.library_dirs)
- self.assertIn(lib, cmd.rpath)
- self.assertIn(incl, cmd.include_dirs)
-
- def test_optional_extension(self):
-
- # this extension will fail, but let's ignore this failure
- # with the optional argument.
- modules = [Extension('foo', ['xxx'], optional=False)]
- 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
-
- modules = [Extension('foo', ['xxx'], optional=True)]
- dist = Distribution({'name': 'xx', 'ext_modules': modules})
- cmd = self.build_ext(dist)
- cmd.ensure_finalized()
- cmd.run() # should pass
-
- def test_finalize_options(self):
- # Make sure Python's include directories (for Python.h, pyconfig.h,
- # etc.) are in the include search path.
- modules = [Extension('foo', ['xxx'], optional=False)]
- dist = Distribution({'name': 'xx', 'ext_modules': modules})
- cmd = self.build_ext(dist)
- cmd.finalize_options()
-
- py_include = sysconfig.get_python_inc()
- for p in py_include.split(os.path.pathsep):
- self.assertIn(p, cmd.include_dirs)
-
- plat_py_include = sysconfig.get_python_inc(plat_specific=1)
- for p in plat_py_include.split(os.path.pathsep):
- self.assertIn(p, cmd.include_dirs)
-
- # make sure cmd.libraries is turned into a list
- # if it's a string
- cmd = self.build_ext(dist)
- cmd.libraries = 'my_lib, other_lib lastlib'
- cmd.finalize_options()
- self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib'])
-
- # make sure cmd.library_dirs is turned into a list
- # if it's a string
- cmd = self.build_ext(dist)
- cmd.library_dirs = 'my_lib_dir%sother_lib_dir' % os.pathsep
- cmd.finalize_options()
- self.assertIn('my_lib_dir', cmd.library_dirs)
- self.assertIn('other_lib_dir', cmd.library_dirs)
-
- # make sure rpath is turned into a list
- # if it's a string
- cmd = self.build_ext(dist)
- cmd.rpath = 'one%stwo' % os.pathsep
- cmd.finalize_options()
- self.assertEqual(cmd.rpath, ['one', 'two'])
-
- # make sure cmd.link_objects is turned into a list
- # if it's a string
- cmd = build_ext(dist)
- cmd.link_objects = 'one two,three'
- cmd.finalize_options()
- self.assertEqual(cmd.link_objects, ['one', 'two', 'three'])
-
- # XXX more tests to perform for win32
-
- # make sure define is turned into 2-tuples
- # strings if they are ','-separated strings
- cmd = self.build_ext(dist)
- cmd.define = 'one,two'
- cmd.finalize_options()
- self.assertEqual(cmd.define, [('one', '1'), ('two', '1')])
-
- # make sure undef is turned into a list of
- # strings if they are ','-separated strings
- cmd = self.build_ext(dist)
- cmd.undef = 'one,two'
- cmd.finalize_options()
- self.assertEqual(cmd.undef, ['one', 'two'])
-
- # make sure swig_opts is turned into a list
- cmd = self.build_ext(dist)
- cmd.swig_opts = None
- cmd.finalize_options()
- self.assertEqual(cmd.swig_opts, [])
-
- cmd = self.build_ext(dist)
- cmd.swig_opts = '1 2'
- cmd.finalize_options()
- self.assertEqual(cmd.swig_opts, ['1', '2'])
-
- def test_check_extensions_list(self):
- dist = Distribution()
- cmd = self.build_ext(dist)
- cmd.finalize_options()
-
- #'extensions' option must be a list of Extension instances
- self.assertRaises(DistutilsSetupError,
- cmd.check_extensions_list, 'foo')
-
- # each element of 'ext_modules' option must be an
- # Extension instance or 2-tuple
- exts = [('bar', 'foo', 'bar'), 'foo']
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # first element of each tuple in 'ext_modules'
- # must be the extension name (a string) and match
- # a python dotted-separated name
- exts = [('foo-bar', '')]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # second element of each tuple in 'ext_modules'
- # must be a dictionary (build info)
- exts = [('foo.bar', '')]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # ok this one should pass
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar'})]
- cmd.check_extensions_list(exts)
- ext = exts[0]
- self.assertIsInstance(ext, Extension)
-
- # check_extensions_list adds in ext the values passed
- # when they are in ('include_dirs', 'library_dirs', 'libraries'
- # 'extra_objects', 'extra_compile_args', 'extra_link_args')
- self.assertEqual(ext.libraries, 'foo')
- 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']})]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- exts[0][1]['macros'] = [('1', '2'), ('3',)]
- cmd.check_extensions_list(exts)
- self.assertEqual(exts[0].undef_macros, ['3'])
- self.assertEqual(exts[0].define_macros, [('1', '2')])
-
- def test_get_source_files(self):
- modules = [Extension('foo', ['xxx'], optional=False)]
- dist = Distribution({'name': 'xx', 'ext_modules': modules})
- cmd = self.build_ext(dist)
- cmd.ensure_finalized()
- self.assertEqual(cmd.get_source_files(), ['xxx'])
-
- def test_unicode_module_names(self):
- modules = [
- Extension('foo', ['aaa'], optional=False),
- Extension('föö', ['uuu'], optional=False),
- ]
- dist = Distribution({'name': 'xx', 'ext_modules': modules})
- cmd = self.build_ext(dist)
- cmd.ensure_finalized()
- self.assertRegex(cmd.get_ext_filename(modules[0].name), r'foo(_d)?\..*')
- self.assertRegex(cmd.get_ext_filename(modules[1].name), r'föö(_d)?\..*')
- self.assertEqual(cmd.get_export_symbols(modules[0]), ['PyInit_foo'])
- self.assertEqual(cmd.get_export_symbols(modules[1]), ['PyInitU_f_gkaa'])
-
- def test_compiler_option(self):
- # cmd.compiler is an option and
- # should not be overridden by a compiler instance
- # when the command is run
- dist = Distribution()
- cmd = self.build_ext(dist)
- cmd.compiler = 'unix'
- cmd.ensure_finalized()
- cmd.run()
- self.assertEqual(cmd.compiler, 'unix')
-
- def test_get_outputs(self):
- cmd = support.missing_compiler_executable()
- if cmd is not None:
- self.skipTest('The %r command is not found' % cmd)
- tmp_dir = self.mkdtemp()
- 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]})
- cmd = self.build_ext(dist)
- fixup_build_ext(cmd)
- cmd.ensure_finalized()
- self.assertEqual(len(cmd.get_outputs()), 1)
-
- cmd.build_lib = os.path.join(self.tmp_dir, 'build')
- cmd.build_temp = os.path.join(self.tmp_dir, 'tempt')
-
- # issue #5977 : distutils build_ext.get_outputs
- # returns wrong result with --inplace
- other_tmp_dir = os.path.realpath(self.mkdtemp())
- old_wd = os.getcwd()
- os.chdir(other_tmp_dir)
- try:
- cmd.inplace = 1
- cmd.run()
- so_file = cmd.get_outputs()[0]
- finally:
- os.chdir(old_wd)
- self.assertTrue(os.path.exists(so_file))
- ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
- self.assertTrue(so_file.endswith(ext_suffix))
- so_dir = os.path.dirname(so_file)
- self.assertEqual(so_dir, other_tmp_dir)
-
- cmd.inplace = 0
- cmd.compiler = None
- cmd.run()
- so_file = cmd.get_outputs()[0]
- self.assertTrue(os.path.exists(so_file))
- self.assertTrue(so_file.endswith(ext_suffix))
- so_dir = os.path.dirname(so_file)
- self.assertEqual(so_dir, cmd.build_lib)
-
- # inplace = 0, cmd.package = 'bar'
- build_py = cmd.get_finalized_command('build_py')
- build_py.package_dir = {'': 'bar'}
- path = cmd.get_ext_fullpath('foo')
- # checking that the last directory is the build_dir
- path = os.path.split(path)[0]
- self.assertEqual(path, cmd.build_lib)
-
- # inplace = 1, cmd.package = 'bar'
- cmd.inplace = 1
- other_tmp_dir = os.path.realpath(self.mkdtemp())
- old_wd = os.getcwd()
- os.chdir(other_tmp_dir)
- try:
- path = cmd.get_ext_fullpath('foo')
- finally:
- os.chdir(old_wd)
- # checking that the last directory is bar
- path = os.path.split(path)[0]
- lastdir = os.path.split(path)[-1]
- self.assertEqual(lastdir, 'bar')
-
- 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]})
- dist = Distribution()
- cmd = self.build_ext(dist)
- cmd.inplace = 1
- cmd.distribution.package_dir = {'': 'src'}
- cmd.distribution.packages = ['lxml', 'lxml.html']
- curdir = os.getcwd()
- wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
- path = cmd.get_ext_fullpath('lxml.etree')
- self.assertEqual(wanted, path)
-
- # building lxml.etree not inplace
- cmd.inplace = 0
- cmd.build_lib = os.path.join(curdir, 'tmpdir')
- wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext)
- path = cmd.get_ext_fullpath('lxml.etree')
- self.assertEqual(wanted, path)
-
- # building twisted.runner.portmap not inplace
- build_py = cmd.get_finalized_command('build_py')
- 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)
- self.assertEqual(wanted, path)
-
- # building twisted.runner.portmap inplace
- cmd.inplace = 1
- path = cmd.get_ext_fullpath('twisted.runner.portmap')
- 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,
- # an extension module is compiled with the same deployment target as
- # the interpreter.
- self._try_compile_deployment_target('==', None)
-
- @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
- 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')
-
- @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX')
- def test_deployment_target_higher_ok(self):
- # Issue 9516: Test that an extension module can be compiled with a
- # deployment target higher than that of the interpreter: the ext
- # module may depend on some newer OS feature.
- deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
- if deptarget:
- # increment the minor version number (i.e. 10.6 -> 10.7)
- deptarget = [int(x) for x in deptarget.split('.')]
- deptarget[-1] += 1
- deptarget = '.'.join(str(i) for i in deptarget)
- self._try_compile_deployment_target('<', deptarget)
-
- def _try_compile_deployment_target(self, operator, target):
- orig_environ = os.environ
- os.environ = orig_environ.copy()
- self.addCleanup(setattr, os, 'environ', orig_environ)
-
- if target is None:
- if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
- del os.environ['MACOSX_DEPLOYMENT_TARGET']
- else:
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
-
- deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
-
- with open(deptarget_c, 'w') as fp:
- fp.write(textwrap.dedent('''\
- #include <AvailabilityMacros.h>
-
- int dummy;
-
- #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED
- #else
- #error "Unexpected target"
- #endif
-
- ''' % operator))
-
- # get the deployment target that the interpreter was built with
- target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
- target = tuple(map(int, target.split('.')[0:2]))
- # format the target value as defined in the Apple
- # Availability Macros. We can't use the macro names since
- # at least one value we test with will not exist yet.
- if target[1] < 10:
- # for 10.1 through 10.9.x -> "10n0"
- target = '%02d%01d0' % target
- else:
- # for 10.10 and beyond -> "10nn00"
- target = '%02d%02d00' % target
- deptarget_ext = Extension(
- 'deptarget',
- [deptarget_c],
- extra_compile_args=['-DTARGET=%s'%(target,)],
- )
- 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
- cmd.build_temp = self.tmp_dir
-
- try:
- old_stdout = sys.stdout
- if not support.verbose:
- # silence compiler output
- sys.stdout = StringIO()
- try:
- cmd.ensure_finalized()
- cmd.run()
- finally:
- sys.stdout = old_stdout
-
- except CompileError:
- self.fail("Wrong deployment target during compilation")
-
-
-class ParallelBuildExtTestCase(BuildExtTestCase):
-
- def build_ext(self, *args, **kwargs):
- build_ext = super().build_ext(*args, **kwargs)
- build_ext.parallel = True
- return build_ext
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(BuildExtTestCase))
- suite.addTest(unittest.makeSuite(ParallelBuildExtTestCase))
- return suite
-
-if __name__ == '__main__':
- support.run_unittest(__name__)
diff --git a/tests/test_build_py.py b/tests/test_build_py.py
deleted file mode 100644
index 0712e92c..00000000
--- a/tests/test_build_py.py
+++ /dev/null
@@ -1,179 +0,0 @@
-"""Tests for distutils.command.build_py."""
-
-import os
-import sys
-import unittest
-
-from distutils.command.build_py import build_py
-from distutils.core import Distribution
-from distutils.errors import DistutilsFileError
-
-from distutils.tests import support
-from test.support import run_unittest
-
-
-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")
- try:
- f.write("# Pretend this is a package.")
- finally:
- f.close()
- f = open(os.path.join(sources, "README.txt"), "w")
- try:
- f.write("Info about this package")
- finally:
- f.close()
-
- destination = self.mkdtemp()
-
- 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.packages = ["pkg"]
- dist.package_data = {"pkg": ["README.txt"]}
- dist.package_dir = {"pkg": sources}
-
- cmd = build_py(dist)
- cmd.compile = 1
- cmd.ensure_finalized()
- self.assertEqual(cmd.package_data, dist.package_data)
-
- cmd.run()
-
- # This makes sure the list of outputs includes byte-compiled
- # files for Python modules but not for package data files
- # (there shouldn't *be* byte-code files for those!).
- self.assertEqual(len(cmd.get_outputs()), 3)
- pkgdest = os.path.join(destination, "pkg")
- files = os.listdir(pkgdest)
- pycache_dir = os.path.join(pkgdest, "__pycache__")
- self.assertIn("__init__.py", files)
- self.assertIn("README.txt", files)
- if sys.dont_write_bytecode:
- 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)
-
- def test_empty_package_dir(self):
- # See bugs #1668596/#1720897
- sources = self.mkdtemp()
- open(os.path.join(sources, "__init__.py"), "w").close()
-
- testdir = os.path.join(sources, "doc")
- os.mkdir(testdir)
- open(os.path.join(testdir, "testfile"), "w").close()
-
- os.chdir(sources)
- 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"]
- dist.parse_command_line()
-
- try:
- dist.run_commands()
- except DistutilsFileError:
- self.fail("failed package_data test when package_dir is ''")
-
- @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
- def test_byte_compile(self):
- project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
- os.chdir(project_dir)
- self.write_file('boiledeggs.py', 'import antigravity')
- cmd = build_py(dist)
- cmd.compile = 1
- cmd.build_lib = 'here'
- cmd.finalize_options()
- cmd.run()
-
- 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])
-
- @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
- def test_byte_compile_optimized(self):
- project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
- os.chdir(project_dir)
- self.write_file('boiledeggs.py', 'import antigravity')
- cmd = build_py(dist)
- cmd.compile = 0
- cmd.optimize = 1
- cmd.build_lib = 'here'
- cmd.finalize_options()
- cmd.run()
-
- found = os.listdir(cmd.build_lib)
- self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
- found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
- expect = 'boiledeggs.{}.opt-1.pyc'.format(sys.implementation.cache_tag)
- self.assertEqual(sorted(found), [expect])
-
- def test_dir_in_package_data(self):
- """
- A directory in package_data should not be added to the filelist.
- """
- # See bug 19286
- sources = self.mkdtemp()
- pkg_dir = os.path.join(sources, "pkg")
-
- os.mkdir(pkg_dir)
- open(os.path.join(pkg_dir, "__init__.py"), "w").close()
-
- docdir = os.path.join(pkg_dir, "doc")
- os.mkdir(docdir)
- open(os.path.join(docdir, "testfile"), "w").close()
-
- # create the directory that could be incorrectly detected as a file
- os.mkdir(os.path.join(docdir, 'otherdir'))
-
- os.chdir(sources)
- 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"]
- dist.parse_command_line()
-
- try:
- dist.run_commands()
- except DistutilsFileError:
- self.fail("failed package_data when data dir includes a dir")
-
- def test_dont_write_bytecode(self):
- # makes sure byte_compile is not used
- dist = self.create_dist()[1]
- cmd = build_py(dist)
- cmd.compile = 1
- cmd.optimize = 1
-
- old_dont_write_bytecode = sys.dont_write_bytecode
- sys.dont_write_bytecode = True
- try:
- cmd.byte_compile([])
- finally:
- sys.dont_write_bytecode = old_dont_write_bytecode
-
- self.assertIn('byte-compiling is disabled',
- self.logs[0][1] % self.logs[0][2])
-
-
-def test_suite():
- return unittest.makeSuite(BuildPyTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_build_scripts.py b/tests/test_build_scripts.py
deleted file mode 100644
index 954fc763..00000000
--- a/tests/test_build_scripts.py
+++ /dev/null
@@ -1,112 +0,0 @@
-"""Tests for distutils.command.build_scripts."""
-
-import os
-import unittest
-
-from distutils.command.build_scripts import build_scripts
-from distutils.core import Distribution
-from distutils import sysconfig
-
-from distutils.tests import support
-from test.support import run_unittest
-
-
-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)
- self.assertIsNone(cmd.build_dir)
-
- cmd.finalize_options()
-
- self.assertTrue(cmd.force)
- self.assertEqual(cmd.build_dir, "/foo/bar")
-
- def test_build(self):
- source = self.mkdtemp()
- 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.finalize_options()
- cmd.run()
-
- built = os.listdir(target)
- for name in expected:
- self.assertIn(name, built)
-
- 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
- )
- 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"))
- expected.append("script2.py")
- 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"))
- return expected
-
- def write_script(self, dir, name, text):
- f = open(os.path.join(dir, name), "w")
- try:
- f.write(text)
- finally:
- f.close()
-
- def test_version_int(self):
- source = self.mkdtemp()
- 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.finalize_options()
-
- # http://bugs.python.org/issue4524
- #
- # On linux-g++-32 with command line `./configure --enable-ipv6
- # --with-suffix=3`, python is compiled okay but the build scripts
- # failed when writing the name of the executable
- old = sysconfig.get_config_vars().get('VERSION')
- sysconfig._config_vars['VERSION'] = 4
- try:
- cmd.run()
- finally:
- if old is not None:
- sysconfig._config_vars['VERSION'] = old
-
- built = os.listdir(target)
- for name in expected:
- self.assertIn(name, built)
-
-def test_suite():
- return unittest.makeSuite(BuildScriptsTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_check.py b/tests/test_check.py
deleted file mode 100644
index e534aca1..00000000
--- a/tests/test_check.py
+++ /dev/null
@@ -1,163 +0,0 @@
-"""Tests for distutils.command.check."""
-import os
-import textwrap
-import unittest
-from test.support import run_unittest
-
-from distutils.command.check import check, HAS_DOCUTILS
-from distutils.tests import support
-from distutils.errors import DistutilsSetupError
-
-try:
- import pygments
-except ImportError:
- pygments = None
-
-
-HERE = os.path.dirname(__file__)
-
-
-class CheckTestCase(support.LoggingSilencer,
- support.TempdirManager,
- unittest.TestCase):
-
- def _run(self, metadata=None, cwd=None, **options):
- if metadata is None:
- metadata = {}
- if cwd is not None:
- old_dir = os.getcwd()
- os.chdir(cwd)
- pkg_info, dist = self.create_dist(**metadata)
- cmd = check(dist)
- cmd.initialize_options()
- for name, value in options.items():
- setattr(cmd, name, value)
- cmd.ensure_finalized()
- cmd.run()
- if cwd is not None:
- os.chdir(old_dir)
- return cmd
-
- def test_check_metadata(self):
- # let's run the command with no metadata at all
- # by default, check is checking the metadata
- # should have some warnings
- cmd = self._run()
- self.assertEqual(cmd._warnings, 2)
-
- # 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'}
- cmd = self._run(metadata)
- self.assertEqual(cmd._warnings, 0)
-
- # now with the strict mode, we should
- # get an error if there are missing metadata
- self.assertRaises(DistutilsSetupError, self._run, {}, **{'strict': 1})
-
- # and of course, no error when all metadata are present
- cmd = self._run(metadata, strict=1)
- 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'}
- cmd = self._run(metadata)
- self.assertEqual(cmd._warnings, 0)
-
- @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
- def test_check_document(self):
- pkg_info, dist = self.create_dist()
- cmd = check(dist)
-
- # let's see if it detects broken rest
- broken_rest = 'title\n===\n\ntest'
- msgs = cmd._check_rst_data(broken_rest)
- self.assertEqual(len(msgs), 1)
-
- # and non-broken rest
- rest = 'title\n=====\n\ntest'
- msgs = cmd._check_rst_data(rest)
- self.assertEqual(len(msgs), 0)
-
- @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
- def test_check_restructuredtext(self):
- # let's see if it detects broken rest in long_description
- broken_rest = 'title\n===\n\ntest'
- pkg_info, dist = self.create_dist(long_description=broken_rest)
- cmd = check(dist)
- cmd.check_restructuredtext()
- 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})
-
- # and non-broken rest, including a non-ASCII character to test #12114
- metadata['long_description'] = 'title\n=====\n\ntest \u00df'
- cmd = self._run(metadata, strict=1, restructuredtext=1)
- self.assertEqual(cmd._warnings, 0)
-
- # check that includes work to test #31292
- metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
- cmd = self._run(metadata, cwd=HERE, strict=1, restructuredtext=1)
- self.assertEqual(cmd._warnings, 0)
-
- @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
- def test_check_restructuredtext_with_syntax_highlight(self):
- # Don't fail if there is a `code` or `code-block` directive
-
- example_rst_docs = []
- example_rst_docs.append(textwrap.dedent("""\
- Here's some code:
-
- .. code:: python
-
- def foo():
- pass
- """))
- 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)
- cmd = check(dist)
- cmd.check_restructuredtext()
- msgs = cmd._check_rst_data(rest_with_code)
- if pygments is not None:
- self.assertEqual(len(msgs), 0)
- else:
- self.assertEqual(len(msgs), 1)
- self.assertEqual(
- 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})
-
-def test_suite():
- return unittest.makeSuite(CheckTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_clean.py b/tests/test_clean.py
deleted file mode 100644
index c605afd8..00000000
--- a/tests/test_clean.py
+++ /dev/null
@@ -1,49 +0,0 @@
-"""Tests for distutils.command.clean."""
-import os
-import unittest
-
-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):
-
- 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')]
-
- for name, path in dirs:
- os.mkdir(path)
- setattr(cmd, name, path)
- if name == 'build_base':
- continue
- for f in ('one', 'two', 'three'):
- self.write_file(os.path.join(path, f))
-
- # let's run the command
- cmd.all = 1
- cmd.ensure_finalized()
- cmd.run()
-
- # make sure the files where removed
- for name, path in dirs:
- 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.makeSuite(cleanTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_cmd.py b/tests/test_cmd.py
deleted file mode 100644
index cf5197c3..00000000
--- a/tests/test_cmd.py
+++ /dev/null
@@ -1,126 +0,0 @@
-"""Tests for distutils.cmd."""
-import unittest
-import os
-from test.support import captured_stdout, run_unittest
-
-from distutils.cmd import Command
-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):
-
- def setUp(self):
- dist = Distribution()
- self.cmd = MyCmd(dist)
-
- def test_ensure_string_list(self):
-
- cmd = self.cmd
- cmd.not_string_list = ['one', 2, 'three']
- cmd.yes_string_list = ['one', 'two', 'three']
- cmd.not_string_list2 = object()
- cmd.yes_string_list2 = 'ok'
- 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_list2')
-
- cmd.option1 = 'ok,dok'
- cmd.ensure_string_list('option1')
- self.assertEqual(cmd.option1, ['ok', 'dok'])
-
- cmd.option2 = ['xxx', 'www']
- cmd.ensure_string_list('option2')
-
- cmd.option3 = ['ok', 2]
- 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=())
-
- # 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=())
-
- def test_dump_options(self):
-
- msgs = []
- def _announce(msg, level):
- msgs.append(msg)
- cmd = self.cmd
- cmd.announce = _announce
- cmd.option1 = 1
- cmd.option2 = 1
- cmd.user_options = [('option1', '', ''), ('option2', '', '')]
- cmd.dump_options()
-
- wanted = ["command options for 'MyCmd':", ' option1 = 1',
- ' option2 = 1']
- self.assertEqual(msgs, wanted)
-
- def test_ensure_string(self):
- cmd = self.cmd
- cmd.option1 = 'ok'
- cmd.ensure_string('option1')
-
- cmd.option2 = None
- cmd.ensure_string('option2', 'xxx')
- self.assertTrue(hasattr(cmd, 'option2'))
-
- cmd.option3 = 1
- self.assertRaises(DistutilsOptionError, cmd.ensure_string, 'option3')
-
- def test_ensure_filename(self):
- cmd = self.cmd
- cmd.option1 = __file__
- cmd.ensure_filename('option1')
- cmd.option2 = 'xxx'
- self.assertRaises(DistutilsOptionError, cmd.ensure_filename, 'option2')
-
- def test_ensure_dirname(self):
- cmd = self.cmd
- cmd.option1 = os.path.dirname(__file__) or os.curdir
- cmd.ensure_dirname('option1')
- cmd.option2 = 'xxx'
- self.assertRaises(DistutilsOptionError, cmd.ensure_dirname, 'option2')
-
- def test_debug_print(self):
- cmd = self.cmd
- with captured_stdout() as stdout:
- cmd.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
-
- debug.DEBUG = True
- try:
- with captured_stdout() as stdout:
- cmd.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), 'xxx\n')
- finally:
- debug.DEBUG = False
-
-def test_suite():
- return unittest.makeSuite(CommandTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_config.py b/tests/test_config.py
deleted file mode 100644
index 344084af..00000000
--- a/tests/test_config.py
+++ /dev/null
@@ -1,141 +0,0 @@
-"""Tests for distutils.pypirc.pypirc."""
-import os
-import unittest
-
-from distutils.core import PyPIRCCommand
-from distutils.core import Distribution
-from distutils.log import set_threshold
-from distutils.log import WARN
-
-from distutils.tests import support
-from test.support import run_unittest
-
-PYPIRC = """\
-[distutils]
-
-index-servers =
- server1
- server2
- server3
-
-[server1]
-username:me
-password:secret
-
-[server2]
-username:meagain
-password: secret
-realm:acme
-repository:http://another.pypi/
-
-[server3]
-username:cbiggles
-password:yh^%#rest-of-my-password
-"""
-
-PYPIRC_OLD = """\
-[server-login]
-username:tarek
-password:secret
-"""
-
-WANTED = """\
-[distutils]
-index-servers =
- pypi
-
-[pypi]
-username:tarek
-password:xxx
-"""
-
-
-class BasePyPIRCCommandTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- """Patches the environment."""
- super(BasePyPIRCCommandTestCase, self).setUp()
- self.tmp_dir = self.mkdtemp()
- os.environ['HOME'] = self.tmp_dir
- os.environ['USERPROFILE'] = self.tmp_dir
- self.rc = os.path.join(self.tmp_dir, '.pypirc')
- self.dist = Distribution()
-
- class command(PyPIRCCommand):
- def __init__(self, dist):
- PyPIRCCommand.__init__(self, dist)
- def initialize_options(self):
- pass
- finalize_options = initialize_options
-
- self._cmd = command
- self.old_threshold = set_threshold(WARN)
-
- def tearDown(self):
- """Removes the patch."""
- set_threshold(self.old_threshold)
- super(BasePyPIRCCommandTestCase, self).tearDown()
-
-
-class PyPIRCCommandTestCase(BasePyPIRCCommandTestCase):
-
- def test_server_registration(self):
- # This test makes sure PyPIRCCommand knows how to:
- # 1. handle several sections in .pypirc
- # 2. handle the old format
-
- # new format
- self.write_file(self.rc, PYPIRC)
- cmd = self._cmd(self.dist)
- config = cmd._read_pypirc()
-
- config = list(sorted(config.items()))
- 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')]
- self.assertEqual(config, waited)
-
- def test_server_empty_registration(self):
- cmd = self._cmd(self.dist)
- rc = cmd._get_rc_file()
- self.assertFalse(os.path.exists(rc))
- cmd._store_pypirc('tarek', 'xxx')
- self.assertTrue(os.path.exists(rc))
- f = open(rc)
- try:
- content = f.read()
- self.assertEqual(content, WANTED)
- finally:
- f.close()
-
- def test_config_interpolation(self):
- # using the % character in .pypirc should not raise an error (#20120)
- self.write_file(self.rc, PYPIRC)
- cmd = self._cmd(self.dist)
- cmd.repository = 'server3'
- 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')]
- self.assertEqual(config, waited)
-
-
-def test_suite():
- return unittest.makeSuite(PyPIRCCommandTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_config_cmd.py b/tests/test_config_cmd.py
deleted file mode 100644
index 9aeab07b..00000000
--- a/tests/test_config_cmd.py
+++ /dev/null
@@ -1,96 +0,0 @@
-"""Tests for distutils.command.config."""
-import unittest
-import os
-import sys
-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):
-
- def _info(self, msg, *args):
- for line in msg.splitlines():
- self._logs.append(line)
-
- def setUp(self):
- super(ConfigTestCase, self).setUp()
- self._logs = []
- self.old_log = log.info
- log.info = self._info
-
- def tearDown(self):
- log.info = self.old_log
- super(ConfigTestCase, self).tearDown()
-
- def test_dump_file(self):
- this_file = os.path.splitext(__file__)[0] + '.py'
- f = open(this_file)
- try:
- numlines = len(f.readlines())
- finally:
- f.close()
-
- dump_file(this_file, 'I am the header')
- self.assertEqual(len(self._logs), numlines+1)
-
- @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
- def test_search_cpp(self):
- cmd = missing_compiler_executable(['preprocessor'])
- if cmd is not None:
- self.skipTest('The %r command is not found' % cmd)
- pkg_dir, dist = self.create_dist()
- cmd = config(dist)
- 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')
-
- # simple pattern searches
- match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
- self.assertEqual(match, 0)
-
- match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
- self.assertEqual(match, 1)
-
- def test_finalize_options(self):
- # finalize_options does a bit of transformation
- # on options
- pkg_dir, dist = self.create_dist()
- cmd = config(dist)
- cmd.include_dirs = 'one%stwo' % os.pathsep
- cmd.libraries = 'one'
- cmd.library_dirs = 'three%sfour' % os.pathsep
- cmd.ensure_finalized()
-
- self.assertEqual(cmd.include_dirs, ['one', 'two'])
- self.assertEqual(cmd.libraries, ['one'])
- self.assertEqual(cmd.library_dirs, ['three', 'four'])
-
- def test_clean(self):
- # _clean removes files
- tmp_dir = self.mkdtemp()
- f1 = os.path.join(tmp_dir, 'one')
- f2 = os.path.join(tmp_dir, 'two')
-
- self.write_file(f1, 'xxx')
- self.write_file(f2, 'xxx')
-
- for f in (f1, f2):
- self.assertTrue(os.path.exists(f))
-
- pkg_dir, dist = self.create_dist()
- cmd = config(dist)
- cmd._clean(f1, f2)
-
- for f in (f1, f2):
- self.assertFalse(os.path.exists(f))
-
-def test_suite():
- return unittest.makeSuite(ConfigTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_core.py b/tests/test_core.py
deleted file mode 100644
index 27ce7324..00000000
--- a/tests/test_core.py
+++ /dev/null
@@ -1,140 +0,0 @@
-"""Tests for distutils.core."""
-
-import io
-import distutils.core
-import os
-import shutil
-import sys
-import test.support
-from test.support import captured_stdout, run_unittest
-import unittest
-from distutils.tests import support
-from distutils import log
-
-# setup script that uses __file__
-setup_using___file__ = """\
-
-__file__
-
-from distutils.core import setup
-setup()
-"""
-
-setup_prints_cwd = """\
-
-import os
-print(os.getcwd())
-
-from distutils.core import setup
-setup()
-"""
-
-setup_does_nothing = """\
-from distutils.core import setup
-setup()
-"""
-
-
-setup_defines_subclass = """\
-from distutils.core import setup
-from distutils.command.install import install as _install
-
-class install(_install):
- sub_commands = _install.sub_commands + ['cmd']
-
-setup(cmdclass={'install': install})
-"""
-
-class CoreTestCase(support.EnvironGuard, unittest.TestCase):
-
- def setUp(self):
- super(CoreTestCase, self).setUp()
- self.old_stdout = sys.stdout
- self.cleanup_testfn()
- self.old_argv = sys.argv, sys.argv[:]
- self.addCleanup(log.set_threshold, log._global_log.threshold)
-
- def tearDown(self):
- sys.stdout = self.old_stdout
- self.cleanup_testfn()
- sys.argv = self.old_argv[0]
- sys.argv[:] = self.old_argv[1]
- super(CoreTestCase, self).tearDown()
-
- def cleanup_testfn(self):
- path = test.support.TESTFN
- if os.path.isfile(path):
- os.remove(path)
- elif os.path.isdir(path):
- shutil.rmtree(path)
-
- def write_setup(self, text, path=test.support.TESTFN):
- f = open(path, "w")
- try:
- f.write(text)
- finally:
- f.close()
- return path
-
- 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__))
-
- 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))
- 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))
- install = dist.get_command_obj('install')
- self.assertIn('cmd', install.sub_commands)
-
- def test_run_setup_uses_current_dir(self):
- # This tests that the setup script is run with the current directory
- # as its own current directory; this was temporarily broken by a
- # previous patch when TESTFN did not use the current directory.
- sys.stdout = io.StringIO()
- cwd = os.getcwd()
-
- # Create a directory and write the setup.py file there:
- os.mkdir(test.support.TESTFN)
- setup_py = os.path.join(test.support.TESTFN, "setup.py")
- distutils.core.run_setup(
- self.write_setup(setup_prints_cwd, path=setup_py))
-
- output = sys.stdout.getvalue()
- if output.endswith("\n"):
- output = output[:-1]
- self.assertEqual(cwd, output)
-
- def test_debug_mode(self):
- # this covers the code called when DEBUG is set
- sys.argv = ['setup.py', '--name']
- with captured_stdout() as stdout:
- distutils.core.setup(name='bar')
- stdout.seek(0)
- self.assertEqual(stdout.read(), 'bar\n')
-
- distutils.core.DEBUG = True
- try:
- with captured_stdout() as stdout:
- distutils.core.setup(name='bar')
- finally:
- distutils.core.DEBUG = False
- stdout.seek(0)
- wanted = "options (after parsing config files):\n"
- self.assertEqual(stdout.readlines()[0], wanted)
-
-def test_suite():
- return unittest.makeSuite(CoreTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_cygwinccompiler.py b/tests/test_cygwinccompiler.py
deleted file mode 100644
index 9dc869de..00000000
--- a/tests/test_cygwinccompiler.py
+++ /dev/null
@@ -1,154 +0,0 @@
-"""Tests for distutils.cygwinccompiler."""
-import unittest
-import sys
-import os
-from io import BytesIO
-from test.support import run_unittest
-
-from distutils import cygwinccompiler
-from distutils.cygwinccompiler import (check_config_h,
- CONFIG_H_OK, CONFIG_H_NOTOK,
- CONFIG_H_UNCERTAIN, get_versions,
- get_msvcr)
-from distutils.tests import support
-
-class FakePopen(object):
- test_class = None
-
- def __init__(self, cmd, shell, stdout):
- self.cmd = cmd.split()[0]
- exes = self.test_class._exes
- if self.cmd in exes:
- # issue #6438 in Python 3.x, Popen returns bytes
- self.stdout = BytesIO(exes[self.cmd])
- else:
- self.stdout = os.popen(cmd, 'r')
-
-
-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
- self.old_find_executable = cygwinccompiler.find_executable
- cygwinccompiler.find_executable = self._find_executable
- self._exes = {}
- self.old_popen = cygwinccompiler.Popen
- FakePopen.test_class = self
- cygwinccompiler.Popen = FakePopen
-
- def tearDown(self):
- sys.version = self.version
- from distutils import sysconfig
- sysconfig.get_config_h_filename = self.old_get_config_h_filename
- cygwinccompiler.find_executable = self.old_find_executable
- cygwinccompiler.Popen = self.old_popen
- super(CygwinCCompilerTestCase, self).tearDown()
-
- def _get_config_h_filename(self):
- return self.python_h
-
- def _find_executable(self, name):
- if name in self._exes:
- return name
- return None
-
- 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)]')
-
- self.assertEqual(check_config_h()[0], CONFIG_H_OK)
-
- # then it tries to see if it can find "__GNUC__" in pyconfig.h
- sys.version = 'something without the *CC word'
-
- # if the file doesn't exist it returns CONFIG_H_UNCERTAIN
- self.assertEqual(check_config_h()[0], CONFIG_H_UNCERTAIN)
-
- # if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK
- self.write_file(self.python_h, 'xxx')
- self.assertEqual(check_config_h()[0], CONFIG_H_NOTOK)
-
- # and CONFIG_H_OK if __GNUC__ is found
- self.write_file(self.python_h, 'xxx __GNUC__ xxx')
- self.assertEqual(check_config_h()[0], CONFIG_H_OK)
-
- def test_get_versions(self):
-
- # get_versions calls distutils.spawn.find_executable on
- # 'gcc', 'ld' and 'dllwrap'
- self.assertEqual(get_versions(), (None, None, None))
-
- # Let's fake we have 'gcc' and it returns '3.4.5'
- self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF'
- res = get_versions()
- self.assertEqual(str(res[0]), '3.4.5')
-
- # and let's see what happens when the version
- # doesn't match the regular expression
- # (\d+\.\d+(\.\d+)*)
- self._exes['gcc'] = b'very strange output'
- res = get_versions()
- self.assertEqual(res[0], None)
-
- # same thing for ld
- self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
- res = get_versions()
- self.assertEqual(str(res[1]), '2.17.50')
- self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
- res = get_versions()
- self.assertEqual(res[1], None)
-
- # and dllwrap
- self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
- res = get_versions()
- self.assertEqual(str(res[2]), '2.17.50')
- self._exes['dllwrap'] = b'Cheese Wrap'
- res = get_versions()
- self.assertEqual(res[2], None)
-
- 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)]')
- 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)]')
- 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)]')
- 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)]')
- 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)]')
- self.assertEqual(get_msvcr(), ['msvcr90'])
-
- # unknown
- sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
- '[MSC v.1999 32 bits (Intel)]')
- self.assertRaises(ValueError, get_msvcr)
-
-def test_suite():
- return unittest.makeSuite(CygwinCCompilerTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_dep_util.py b/tests/test_dep_util.py
deleted file mode 100644
index c6fae39c..00000000
--- a/tests/test_dep_util.py
+++ /dev/null
@@ -1,80 +0,0 @@
-"""Tests for distutils.dep_util."""
-import unittest
-import os
-
-from distutils.dep_util import newer, newer_pairwise, newer_group
-from distutils.errors import DistutilsFileError
-from distutils.tests import support
-from test.support import run_unittest
-
-class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
-
- def test_newer(self):
-
- tmpdir = self.mkdtemp()
- new_file = os.path.join(tmpdir, 'new')
- old_file = os.path.abspath(__file__)
-
- # Raise DistutilsFileError if 'new_file' does not exist.
- self.assertRaises(DistutilsFileError, newer, new_file, old_file)
-
- # Return true if 'new_file' exists and is more recently modified than
- # 'old_file', or if 'new_file' exists and 'old_file' doesn't.
- self.write_file(new_file)
- self.assertTrue(newer(new_file, 'I_dont_exist'))
- self.assertTrue(newer(new_file, old_file))
-
- # Return false if both exist and 'old_file' is the same age or younger
- # than 'new_file'.
- self.assertFalse(newer(old_file, new_file))
-
- def test_newer_pairwise(self):
- tmpdir = self.mkdtemp()
- sources = os.path.join(tmpdir, 'sources')
- targets = os.path.join(tmpdir, 'targets')
- os.mkdir(sources)
- 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
- 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]))
-
- def test_newer_group(self):
- tmpdir = self.mkdtemp()
- sources = os.path.join(tmpdir, 'sources')
- os.mkdir(sources)
- one = os.path.join(sources, 'one')
- two = os.path.join(sources, 'two')
- three = os.path.join(sources, 'three')
- old_file = os.path.abspath(__file__)
-
- # return true if 'old_file' is out-of-date with respect to any file
- # listed in 'sources'.
- self.write_file(one)
- self.write_file(two)
- self.write_file(three)
- self.assertTrue(newer_group([one, two, three], old_file))
- self.assertFalse(newer_group([one, two, old_file], three))
-
- # missing handling
- 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.assertTrue(newer_group([one, two, old_file], three,
- missing='newer'))
-
-
-def test_suite():
- return unittest.makeSuite(DepUtilTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_dir_util.py b/tests/test_dir_util.py
deleted file mode 100644
index d436cf83..00000000
--- a/tests/test_dir_util.py
+++ /dev/null
@@ -1,139 +0,0 @@
-"""Tests for distutils.dir_util."""
-import unittest
-import os
-import stat
-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 import log
-from distutils.tests import support
-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)
- else:
- self._logs.append(msg)
-
- def setUp(self):
- super(DirUtilTestCase, self).setUp()
- self._logs = []
- tmp_dir = self.mkdtemp()
- self.root_target = os.path.join(tmp_dir, 'deep')
- self.target = os.path.join(self.root_target, 'here')
- self.target2 = os.path.join(tmp_dir, 'deep2')
- self.old_log = log.info
- log.info = self._log
-
- def tearDown(self):
- log.info = self.old_log
- super(DirUtilTestCase, self).tearDown()
-
- def test_mkpath_remove_tree_verbosity(self):
-
- mkpath(self.target, verbose=0)
- wanted = []
- self.assertEqual(self._logs, wanted)
- remove_tree(self.root_target, verbose=0)
-
- mkpath(self.target, verbose=1)
- wanted = ['creating %s' % self.root_target,
- 'creating %s' % self.target]
- self.assertEqual(self._logs, wanted)
- self._logs = []
-
- remove_tree(self.root_target, verbose=1)
- 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.")
- 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)
- mkpath(self.target2, 0o555)
- self.assertEqual(
- stat.S_IMODE(os.stat(self.target2).st_mode), 0o555 & ~umask)
-
- def test_create_tree_verbosity(self):
-
- create_tree(self.root_target, ['one', 'two', 'three'], verbose=0)
- self.assertEqual(self._logs, [])
- remove_tree(self.root_target, verbose=0)
-
- wanted = ['creating %s' % self.root_target]
- create_tree(self.root_target, ['one', 'two', 'three'], verbose=1)
- self.assertEqual(self._logs, wanted)
-
- remove_tree(self.root_target, verbose=0)
-
- def test_copy_tree_verbosity(self):
-
- mkpath(self.target, verbose=0)
-
- copy_tree(self.target, self.target2, verbose=0)
- self.assertEqual(self._logs, [])
-
- remove_tree(self.root_target, verbose=0)
-
- mkpath(self.target, verbose=0)
- a_file = os.path.join(self.target, 'ok.txt')
- with open(a_file, 'w') as f:
- f.write('some content')
-
- wanted = ['copying %s -> %s' % (a_file, self.target2)]
- copy_tree(self.target, self.target2, verbose=1)
- self.assertEqual(self._logs, wanted)
-
- remove_tree(self.root_target, verbose=0)
- remove_tree(self.target2, verbose=0)
-
- def test_copy_tree_skips_nfs_temp_files(self):
- mkpath(self.target, verbose=0)
-
- a_file = os.path.join(self.target, 'ok.txt')
- nfs_file = os.path.join(self.target, '.nfs123abc')
- for f in a_file, nfs_file:
- with open(f, 'w') as fh:
- fh.write('some content')
-
- copy_tree(self.target, self.target2)
- self.assertEqual(os.listdir(self.target2), ['ok.txt'])
-
- remove_tree(self.root_target, verbose=0)
- remove_tree(self.target2, verbose=0)
-
- def test_ensure_relative(self):
- if os.sep == '/':
- self.assertEqual(ensure_relative('/home/foo'), 'home/foo')
- self.assertEqual(ensure_relative('some/path'), 'some/path')
- else: # \\
- self.assertEqual(ensure_relative('c:\\home\\foo'), 'c:home\\foo')
- self.assertEqual(ensure_relative('home\\foo'), 'home\\foo')
-
- def test_copy_tree_exception_in_listdir(self):
- """
- An exception in listdir should raise a DistutilsFileError
- """
- with patch("os.listdir", side_effect=OSError()), \
- self.assertRaises(errors.DistutilsFileError):
- src = self.tempdirs[-1]
- dir_util.copy_tree(src, None)
-
-
-def test_suite():
- return unittest.makeSuite(DirUtilTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_dist.py b/tests/test_dist.py
deleted file mode 100644
index 60956dad..00000000
--- a/tests/test_dist.py
+++ /dev/null
@@ -1,528 +0,0 @@
-"""Tests for distutils.dist."""
-import os
-import io
-import sys
-import unittest
-import warnings
-import textwrap
-
-from unittest import mock
-
-from distutils.dist import Distribution, fix_help_options
-from distutils.cmd import Command
-
-from test.support import (
- TESTFN, captured_stdout, captured_stderr, run_unittest
-)
-from distutils.tests import support
-from distutils import log
-
-
-class test_dist(Command):
- """Sample distutils extension command."""
-
- user_options = [
- ("sample-option=", "S", "help text"),
- ]
-
- def initialize_options(self):
- self.sample_option = None
-
-
-class TestDistribution(Distribution):
- """Distribution subclasses that avoids the default search for
- configuration files.
-
- The ._config_files attribute must be set before
- .parse_config_files() is called.
- """
-
- def find_config_files(self):
- return self._config_files
-
-
-class DistributionTestCase(support.LoggingSilencer,
- support.TempdirManager,
- support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- super(DistributionTestCase, self).setUp()
- self.argv = sys.argv, sys.argv[:]
- del sys.argv[1:]
-
- def tearDown(self):
- sys.argv = self.argv[0]
- sys.argv[:] = self.argv[1]
- super(DistributionTestCase, self).tearDown()
-
- def create_distribution(self, configfiles=()):
- d = TestDistribution()
- d._config_files = configfiles
- d.parse_config_files()
- d.parse_command_line()
- return d
-
- def test_command_packages_unspecified(self):
- sys.argv.append("build")
- d = self.create_distribution()
- self.assertEqual(d.get_command_packages(), ["distutils.command"])
-
- 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",
- ])
- 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"])
- cmd = d.get_command_obj("test_dist")
- self.assertIsInstance(cmd, test_dist)
- self.assertEqual(cmd.sample_option, "sometext")
-
- def test_venv_install_options(self):
- sys.argv.append("install")
- self.addCleanup(os.unlink, TESTFN)
-
- 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)
-
- # Base case: Not in a Virtual Environment
- with mock.patch.multiple(sys, prefix='/a', base_prefix='/a') as values:
- d = self.create_distribution([TESTFN])
-
- option_tuple = (TESTFN, fakepath)
-
- result_dict = {
- 'install_base': option_tuple,
- 'install_platbase': option_tuple,
- 'install_lib': option_tuple,
- 'install_platlib': option_tuple,
- 'install_purelib': option_tuple,
- 'install_headers': option_tuple,
- 'install_scripts': option_tuple,
- 'install_data': option_tuple,
- 'prefix': option_tuple,
- 'exec_prefix': option_tuple,
- 'home': option_tuple,
- 'user': option_tuple,
- 'root': option_tuple,
- }
-
- self.assertEqual(
- 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])
-
- # Test case: In a Virtual Environment
- with mock.patch.multiple(sys, prefix='/a', base_prefix='/b') as values:
- d = self.create_distribution([TESTFN])
-
- for key in result_dict.keys():
- self.assertNotIn(key, d.command_options.get('install', {}))
-
- def test_command_packages_configfile(self):
- sys.argv.append("build")
- self.addCleanup(os.unlink, TESTFN)
- f = open(TESTFN, "w")
- try:
- print("[global]", file=f)
- print("command_packages = foo.bar, splat", file=f)
- finally:
- f.close()
-
- d = self.create_distribution([TESTFN])
- 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"])
-
- # Setting --command-packages to '' should cause the default to
- # be used even if a config file specified something else:
- sys.argv[1:] = ["--command-packages", "", "build"]
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(), ["distutils.command"])
-
- def test_empty_options(self):
- # an empty options dictionary should not stay in the
- # list of attributes
-
- # catching warnings
- warns = []
-
- def _warn(msg):
- warns.append(msg)
-
- self.addCleanup(setattr, warnings, 'warn', warnings.warn)
- warnings.warn = _warn
- 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'}
-
- dist = Distribution(attrs=attrs)
- dist.finalize_options()
-
- # finalize_option splits platforms and keywords
- self.assertEqual(dist.metadata.platforms, ['one', 'two'])
- self.assertEqual(dist.metadata.keywords, ['one', 'two'])
-
- attrs = {'keywords': 'foo bar',
- 'platforms': 'foo bar'}
- dist = Distribution(attrs=attrs)
- dist.finalize_options()
- self.assertEqual(dist.metadata.platforms, ['foo bar'])
- self.assertEqual(dist.metadata.keywords, ['foo bar'])
-
- def test_get_command_packages(self):
- dist = Distribution()
- self.assertEqual(dist.command_packages, None)
- cmds = dist.get_command_packages()
- self.assertEqual(cmds, ['distutils.command'])
- self.assertEqual(dist.command_packages,
- ['distutils.command'])
-
- dist.command_packages = 'one,two'
- cmds = dist.get_command_packages()
- self.assertEqual(cmds, ['distutils.command', 'one', 'two'])
-
- def test_announce(self):
- # make sure the level is known
- dist = Distribution()
- args = ('ok',)
- 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()
- if os.name == 'posix':
- user_filename = os.path.join(temp_home, ".pydistutils.cfg")
- else:
- user_filename = os.path.join(temp_home, "pydistutils.cfg")
-
- with open(user_filename, 'w') as f:
- f.write('[distutils]\n')
-
- def _expander(path):
- return temp_home
-
- old_expander = os.path.expanduser
- os.path.expanduser = _expander
- try:
- d = Distribution()
- all_files = d.find_config_files()
-
- d = Distribution(attrs={'script_args': ['--no-user-cfg']})
- files = d.find_config_files()
- finally:
- os.path.expanduser = old_expander
-
- # make sure --no-user-cfg disables the user cfg file
- self.assertEqual(len(all_files)-1, len(files))
-
-class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- super(MetadataTestCase, self).setUp()
- self.argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- sys.argv = self.argv[0]
- sys.argv[:] = self.argv[1]
- super(MetadataTestCase, self).tearDown()
-
- def format_metadata(self, dist):
- sio = io.StringIO()
- dist.metadata.write_pkg_file(sio)
- return sio.getvalue()
-
- def test_simple_metadata(self):
- attrs = {"name": "package",
- "version": "1.0"}
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- self.assertIn("Metadata-Version: 1.0", meta)
- self.assertNotIn("provides:", meta.lower())
- self.assertNotIn("requires:", meta.lower())
- self.assertNotIn("obsoletes:", meta.lower())
-
- def test_provides(self):
- 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"])
- 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)"]})
-
- def test_requires(self):
- 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)"])
- meta = self.format_metadata(dist)
- self.assertIn("Metadata-Version: 1.1", meta)
- self.assertNotIn("provides:", meta.lower())
- self.assertIn("Requires: other", meta)
- self.assertIn("Requires: another (==1.0)", meta)
- self.assertNotIn("obsoletes:", meta.lower())
-
- def test_requires_illegal(self):
- 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"])}
- dist = Distribution(attrs)
- self.assertIsInstance(dist.metadata.requires, list)
-
-
- def test_obsoletes(self):
- 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)"])
- meta = self.format_metadata(dist)
- self.assertIn("Metadata-Version: 1.1", meta)
- self.assertNotIn("provides:", meta.lower())
- self.assertNotIn("requires:", meta.lower())
- self.assertIn("Obsoletes: other", meta)
- 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)"]})
-
- def test_obsoletes_to_list(self):
- 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']}
- dist = Distribution(attrs)
- 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',)}
- 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']))
-
- def test_keywords(self):
- 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'])
-
- def test_keywords_invalid_type(self):
- 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
- self.assertIn('should be a list', error.getvalue())
- # should be converted to a list
- self.assertIsInstance(d.metadata.keywords, list)
- self.assertEqual(d.metadata.keywords, list(attrs['keywords']))
-
- def test_platforms(self):
- 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'])
-
- def test_platforms_invalid_types(self):
- 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
- self.assertIn('should be a list', error.getvalue())
- # should be converted to a list
- self.assertIsInstance(d.metadata.platforms, list)
- 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'}
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- self.assertIn('Metadata-Version: 1.1', meta)
-
- def test_long_description(self):
- long_desc = textwrap.dedent("""\
- example::
- We start here
- and continue here
- and end here.""")
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": long_desc}
-
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- meta = meta.replace('\n' + 8 * ' ', '\n')
- self.assertIn(long_desc, meta)
-
- def test_custom_pydistutils(self):
- # fixes #2166
- # make sure pydistutils.cfg is found
- if os.name == 'posix':
- user_filename = ".pydistutils.cfg"
- else:
- user_filename = "pydistutils.cfg"
-
- temp_dir = self.mkdtemp()
- user_filename = os.path.join(temp_dir, user_filename)
- f = open(user_filename, 'w')
- try:
- f.write('.')
- finally:
- f.close()
-
- try:
- dist = Distribution()
-
- # linux-style
- if sys.platform in ('linux', 'darwin'):
- os.environ['HOME'] = temp_dir
- files = dist.find_config_files()
- self.assertIn(user_filename, files)
-
- # win32-style
- if sys.platform == 'win32':
- # 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))
- finally:
- os.remove(user_filename)
-
- def test_fix_help_options(self):
- help_tuples = [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
- fancy_options = fix_help_options(help_tuples)
- self.assertEqual(fancy_options[0], ('a', 'b', 'c'))
- self.assertEqual(fancy_options[1], (1, 2, 3))
-
- def test_show_help(self):
- # smoke test, just makes sure some help is displayed
- self.addCleanup(log.set_threshold, log._global_log.threshold)
- dist = Distribution()
- sys.argv = []
- dist.help = 1
- dist.script_name = 'setup.py'
- with captured_stdout() as s:
- dist.parse_command_line()
-
- 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']}
-
- dist = Distribution(attrs)
- metadata = dist.metadata
-
- # write it then reloads it
- PKG_INFO = io.StringIO()
- metadata.write_pkg_file(PKG_INFO)
- PKG_INFO.seek(0)
- metadata.read_pkg_file(PKG_INFO)
-
- self.assertEqual(metadata.name, "package")
- self.assertEqual(metadata.version, "1.0")
- self.assertEqual(metadata.description, "xxx")
- self.assertEqual(metadata.download_url, 'http://example.com')
- self.assertEqual(metadata.keywords, ['one', 'two'])
- self.assertEqual(metadata.platforms, ['UNKNOWN'])
- self.assertEqual(metadata.obsoletes, None)
- self.assertEqual(metadata.requires, ['foo'])
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(DistributionTestCase))
- suite.addTest(unittest.makeSuite(MetadataTestCase))
- return suite
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_extension.py b/tests/test_extension.py
deleted file mode 100644
index e35f2738..00000000
--- a/tests/test_extension.py
+++ /dev/null
@@ -1,69 +0,0 @@
-"""Tests for distutils.extension."""
-import unittest
-import os
-import warnings
-
-from test.support import check_warnings, run_unittest
-from distutils.extension import read_setup_file, Extension
-
-class ExtensionTestCase(unittest.TestCase):
-
- def test_read_setup_file(self):
- # trying to read a Setup file
- # (sample extracted from the PyGame project)
- setup = os.path.join(os.path.dirname(__file__), 'Setup.sample')
-
- exts = read_setup_file(setup)
- names = [ext.name for ext in exts]
- names.sort()
-
- # 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']
-
- self.assertEqual(names, wanted)
-
- def test_extension_init(self):
- # the first argument, which is the name, must be a string
- self.assertRaises(AssertionError, Extension, 1, [])
- ext = Extension('name', [])
- self.assertEqual(ext.name, 'name')
-
- # the second argument, which is the list of files, must
- # be a list of strings
- self.assertRaises(AssertionError, Extension, 'name', 'file')
- self.assertRaises(AssertionError, Extension, 'name', ['file', 1])
- ext = Extension('name', ['file1', 'file2'])
- 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'):
- self.assertEqual(getattr(ext, attr), [])
-
- self.assertEqual(ext.language, None)
- self.assertEqual(ext.optional, None)
-
- # if there are unknown keyword options, warn about them
- with check_warnings() as w:
- warnings.simplefilter('always')
- ext = Extension('name', ['file1', 'file2'], chic=True)
-
- self.assertEqual(len(w.warnings), 1)
- self.assertEqual(str(w.warnings[0].message),
- "Unknown Extension options: 'chic'")
-
-def test_suite():
- return unittest.makeSuite(ExtensionTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_file_util.py b/tests/test_file_util.py
deleted file mode 100644
index a4e2d025..00000000
--- a/tests/test_file_util.py
+++ /dev/null
@@ -1,122 +0,0 @@
-"""Tests for distutils.file_util."""
-import unittest
-import os
-import errno
-from unittest.mock import patch
-
-from distutils.file_util import move_file, copy_file
-from distutils import log
-from distutils.tests import support
-from distutils.errors import DistutilsFileError
-from test.support import run_unittest, unlink
-
-class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
-
- def _log(self, msg, *args):
- if len(args) > 0:
- self._logs.append(msg % args)
- else:
- self._logs.append(msg)
-
- def setUp(self):
- super(FileUtilTestCase, self).setUp()
- self._logs = []
- self.old_log = log.info
- log.info = self._log
- tmp_dir = self.mkdtemp()
- self.source = os.path.join(tmp_dir, 'f1')
- self.target = os.path.join(tmp_dir, 'f2')
- self.target_dir = os.path.join(tmp_dir, 'd1')
-
- def tearDown(self):
- log.info = self.old_log
- super(FileUtilTestCase, self).tearDown()
-
- def test_move_file_verbosity(self):
- f = open(self.source, 'w')
- try:
- f.write('some content')
- finally:
- f.close()
-
- move_file(self.source, self.target, verbose=0)
- wanted = []
- self.assertEqual(self._logs, wanted)
-
- # back to original state
- move_file(self.target, self.source, verbose=0)
-
- move_file(self.source, self.target, verbose=1)
- wanted = ['moving %s -> %s' % (self.source, self.target)]
- self.assertEqual(self._logs, wanted)
-
- # back to original state
- move_file(self.target, self.source, verbose=0)
-
- self._logs = []
- # now the target is a dir
- os.mkdir(self.target_dir)
- move_file(self.source, self.target_dir, verbose=1)
- wanted = ['moving %s -> %s' % (self.source, self.target_dir)]
- self.assertEqual(self._logs, wanted)
-
- def test_move_file_exception_unpacking_rename(self):
- # see issue 22182
- 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 open(self.source, 'w') as fobj:
- fobj.write('spam eggs')
- move_file(self.source, self.target, verbose=0)
-
- def test_copy_file_hard_link(self):
- with open(self.source, 'w') as f:
- f.write('some content')
- # Check first that copy_file() will not fall back on copying the file
- # instead of creating the hard link.
- try:
- os.link(self.source, self.target)
- except OSError as e:
- self.skipTest('os.link: %s' % e)
- else:
- unlink(self.target)
- st = os.stat(self.source)
- copy_file(self.source, self.target, link='hard')
- st2 = os.stat(self.source)
- st3 = os.stat(self.target)
- self.assertTrue(os.path.samestat(st, st2), (st, st2))
- self.assertTrue(os.path.samestat(st2, st3), (st2, st3))
- with open(self.source, 'r') as f:
- self.assertEqual(f.read(), 'some content')
-
- def test_copy_file_hard_link_failure(self):
- # If hard linking fails, copy_file() falls back on copying file
- # (some special filesystems don't support hard linking even under
- # Unix, see issue #8876).
- with open(self.source, 'w') as f:
- f.write('some content')
- st = os.stat(self.source)
- with patch("os.link", side_effect=OSError(0, "linking unsupported")):
- copy_file(self.source, self.target, link='hard')
- st2 = os.stat(self.source)
- st3 = os.stat(self.target)
- self.assertTrue(os.path.samestat(st, st2), (st, st2))
- self.assertFalse(os.path.samestat(st2, st3), (st2, st3))
- for fn in (self.source, self.target):
- with open(fn, 'r') as f:
- self.assertEqual(f.read(), 'some content')
-
-
-def test_suite():
- return unittest.makeSuite(FileUtilTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_filelist.py b/tests/test_filelist.py
deleted file mode 100644
index c71342d0..00000000
--- a/tests/test_filelist.py
+++ /dev/null
@@ -1,340 +0,0 @@
-"""Tests for distutils.filelist."""
-import os
-import re
-import unittest
-from distutils import debug
-from distutils.log import WARN
-from distutils.errors import DistutilsTemplateError
-from distutils.filelist import glob_to_re, translate_pattern, FileList
-from distutils import filelist
-
-import test.support
-from test.support import captured_stdout, run_unittest
-from distutils.tests import support
-
-MANIFEST_IN = """\
-include ok
-include xo
-exclude xo
-include foo.tmp
-include buildout.cfg
-global-include *.x
-global-include *.txt
-global-exclude *.tmp
-recursive-include f *.oo
-recursive-exclude global *.x
-graft dir
-prune dir3
-"""
-
-
-def make_local_path(s):
- """Converts '/' in a string to os.sep"""
- return s.replace('/', os.sep)
-
-
-class FileListTestCase(support.LoggingSilencer,
- unittest.TestCase):
-
- def assertNoWarnings(self):
- self.assertEqual(self.get_logs(WARN), [])
- self.clear_logs()
-
- def assertWarnings(self):
- self.assertGreater(len(self.get_logs(WARN)), 0)
- self.clear_logs()
-
- def test_glob_to_re(self):
- sep = os.sep
- if os.sep == '\\':
- sep = re.escape(os.sep)
-
- for glob, regex in (
- # simple cases
- ('foo*', r'(?s:foo[^%(sep)s]*)\Z'),
- ('foo?', r'(?s:foo[^%(sep)s])\Z'),
- ('foo??', r'(?s:foo[^%(sep)s][^%(sep)s])\Z'),
- # special cases
- (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')):
- regex = regex % {'sep': sep}
- 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
-
- # 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'),
- ]
-
- 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'),
- ]
-
- self.assertEqual(file_list.files, wanted)
-
- def test_debug_print(self):
- file_list = FileList()
- with captured_stdout() as stdout:
- file_list.debug_print('xxx')
- self.assertEqual(stdout.getvalue(), '')
-
- debug.DEBUG = True
- try:
- with captured_stdout() as stdout:
- file_list.debug_print('xxx')
- self.assertEqual(stdout.getvalue(), 'xxx\n')
- finally:
- debug.DEBUG = False
-
- def test_set_allfiles(self):
- file_list = FileList()
- files = ['a', 'b', 'c']
- file_list.set_allfiles(files)
- self.assertEqual(file_list.allfiles, files)
-
- def test_remove_duplicates(self):
- file_list = FileList()
- file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
- # files must be sorted beforehand (sdist does it)
- file_list.sort()
- file_list.remove_duplicates()
- self.assertEqual(file_list.files, ['a', 'b', 'c', 'g'])
-
- def test_translate_pattern(self):
- # not regex
- 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)
-
- # plain string flagged as regex
- 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'))
-
- def test_exclude_pattern(self):
- # return False if no match
- file_list = FileList()
- self.assertFalse(file_list.exclude_pattern('*.py'))
-
- # return True if files match
- file_list = FileList()
- file_list.files = ['a.py', 'b.py']
- self.assertTrue(file_list.exclude_pattern('*.py'))
-
- # test excludes
- file_list = FileList()
- file_list.files = ['a.py', 'a.txt']
- file_list.exclude_pattern('*.py')
- self.assertEqual(file_list.files, ['a.txt'])
-
- def test_include_pattern(self):
- # return False if no match
- file_list = FileList()
- file_list.set_allfiles([])
- self.assertFalse(file_list.include_pattern('*.py'))
-
- # return True if files match
- file_list = FileList()
- file_list.set_allfiles(['a.py', 'b.txt'])
- self.assertTrue(file_list.include_pattern('*.py'))
-
- # test * matches all files
- file_list = FileList()
- self.assertIsNone(file_list.allfiles)
- file_list.set_allfiles(['a.py', 'b.txt'])
- file_list.include_pattern('*')
- self.assertEqual(file_list.allfiles, ['a.py', 'b.txt'])
-
- def test_process_template(self):
- l = 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)
-
- # include
- file_list = FileList()
- file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])
-
- file_list.process_template_line('include *.py')
- self.assertEqual(file_list.files, ['a.py'])
- self.assertNoWarnings()
-
- file_list.process_template_line('include *.rb')
- self.assertEqual(file_list.files, ['a.py'])
- self.assertWarnings()
-
- # exclude
- file_list = FileList()
- file_list.files = ['a.py', 'b.txt', l('d/c.py')]
-
- file_list.process_template_line('exclude *.py')
- self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
- self.assertNoWarnings()
-
- file_list.process_template_line('exclude *.rb')
- self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
- self.assertWarnings()
-
- # global-include
- file_list = FileList()
- file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])
-
- file_list.process_template_line('global-include *.py')
- self.assertEqual(file_list.files, ['a.py', l('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.assertWarnings()
-
- # global-exclude
- file_list = FileList()
- file_list.files = ['a.py', 'b.txt', l('d/c.py')]
-
- file_list.process_template_line('global-exclude *.py')
- self.assertEqual(file_list.files, ['b.txt'])
- self.assertNoWarnings()
-
- file_list.process_template_line('global-exclude *.rb')
- self.assertEqual(file_list.files, ['b.txt'])
- self.assertWarnings()
-
- # 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.process_template_line('recursive-include d *.py')
- self.assertEqual(file_list.files, [l('d/b.py'), l('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.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.process_template_line('recursive-exclude d *.py')
- self.assertEqual(file_list.files, ['a.py', l('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.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.process_template_line('graft d')
- self.assertEqual(file_list.files, [l('d/b.py'), l('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.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.process_template_line('prune d')
- self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
- self.assertNoWarnings()
-
- file_list.process_template_line('prune e')
- self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
- self.assertWarnings()
-
-
-class FindAllTestCase(unittest.TestCase):
- @test.support.skip_unless_symlink
- def test_missing_symlink(self):
- with test.support.temp_cwd():
- os.symlink('foo', 'bar')
- self.assertEqual(filelist.findall(), [])
-
- def test_basic_discovery(self):
- """
- When findall is called with no parameters or with
- '.' as the parameter, the dot should be omitted from
- the results.
- """
- with test.support.temp_cwd():
- os.mkdir('foo')
- file1 = os.path.join('foo', 'file1.txt')
- test.support.create_empty_file(file1)
- os.mkdir('bar')
- file2 = os.path.join('bar', 'file2.txt')
- test.support.create_empty_file(file2)
- expected = [file2, file1]
- self.assertEqual(sorted(filelist.findall()), expected)
-
- def test_non_local_discovery(self):
- """
- When findall is called with another path, the full
- path name should be returned.
- """
- with test.support.temp_dir() as temp_dir:
- file1 = os.path.join(temp_dir, 'file1.txt')
- test.support.create_empty_file(file1)
- expected = [file1]
- self.assertEqual(filelist.findall(temp_dir), expected)
-
-
-def test_suite():
- return unittest.TestSuite([
- unittest.makeSuite(FileListTestCase),
- unittest.makeSuite(FindAllTestCase),
- ])
-
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_install.py b/tests/test_install.py
deleted file mode 100644
index 51c80e04..00000000
--- a/tests/test_install.py
+++ /dev/null
@@ -1,249 +0,0 @@
-"""Tests for distutils.command.install."""
-
-import os
-import sys
-import unittest
-import site
-
-from test.support import captured_stdout, run_unittest
-
-from distutils import sysconfig
-from distutils.command.install import install
-from distutils.command import install as install_module
-from distutils.command.build_ext import build_ext
-from distutils.command.install import INSTALL_SCHEMES
-from distutils.core import Distribution
-from distutils.errors import DistutilsOptionError
-from distutils.extension import Extension
-
-from distutils.tests import support
-from test import support as test_support
-
-
-def _make_ext_name(modname):
- return modname + sysconfig.get_config_var('EXT_SUFFIX')
-
-
-class InstallTestCase(support.TempdirManager,
- support.EnvironGuard,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_home_installation_scheme(self):
- # This ensure two things:
- # - that --home generates the desired set of directory names
- # - test --home is supported on all platforms
- builddir = self.mkdtemp()
- destination = os.path.join(builddir, "installation")
-
- dist = Distribution({"name": "foopkg"})
- # script_name need not exist, it just need to be initialized
- dist.script_name = os.path.join(builddir, "setup.py")
- dist.command_obj["build"] = support.DummyCommand(
- build_base=builddir,
- build_lib=os.path.join(builddir, "lib"),
- )
-
- cmd = install(dist)
- cmd.home = destination
- cmd.ensure_finalized()
-
- self.assertEqual(cmd.install_base, destination)
- self.assertEqual(cmd.install_platbase, destination)
-
- def check_path(got, expected):
- got = os.path.normpath(got)
- expected = os.path.normpath(expected)
- self.assertEqual(got, expected)
-
- libdir = os.path.join(destination, "lib", "python")
- check_path(cmd.install_lib, libdir)
- platlibdir = os.path.join(destination, sys.platlibdir, "python")
- check_path(cmd.install_platlib, platlibdir)
- check_path(cmd.install_purelib, libdir)
- check_path(cmd.install_headers,
- os.path.join(destination, "include", "python", "foopkg"))
- check_path(cmd.install_scripts, os.path.join(destination, "bin"))
- check_path(cmd.install_data, destination)
-
- def test_user_site(self):
- # test install with --user
- # preparing the environment for the test
- self.old_user_base = site.USER_BASE
- self.old_user_site = site.USER_SITE
- self.tmpdir = self.mkdtemp()
- self.user_base = os.path.join(self.tmpdir, 'B')
- self.user_site = os.path.join(self.tmpdir, 'S')
- site.USER_BASE = self.user_base
- site.USER_SITE = self.user_site
- install_module.USER_BASE = self.user_base
- install_module.USER_SITE = self.user_site
-
- def _expanduser(path):
- return self.tmpdir
- self.old_expand = os.path.expanduser
- os.path.expanduser = _expanduser
-
- def cleanup():
- site.USER_BASE = self.old_user_base
- site.USER_SITE = self.old_user_site
- install_module.USER_BASE = self.old_user_base
- install_module.USER_SITE = self.old_user_site
- os.path.expanduser = self.old_expand
-
- self.addCleanup(cleanup)
-
- for key in ('nt_user', 'unix_user'):
- self.assertIn(key, INSTALL_SCHEMES)
-
- dist = Distribution({'name': 'xx'})
- cmd = install(dist)
-
- # making sure the user option is there
- options = [name for name, short, lable in
- cmd.user_options]
- self.assertIn('user', options)
-
- # setting a value
- cmd.user = 1
-
- # user base and site shouldn't be created yet
- self.assertFalse(os.path.exists(self.user_base))
- self.assertFalse(os.path.exists(self.user_site))
-
- # let's run finalize
- cmd.ensure_finalized()
-
- # now they should
- self.assertTrue(os.path.exists(self.user_base))
- self.assertTrue(os.path.exists(self.user_site))
-
- self.assertIn('userbase', cmd.config_vars)
- self.assertIn('usersite', cmd.config_vars)
-
- def test_handle_extra_path(self):
- dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
- cmd = install(dist)
-
- # two elements
- cmd.handle_extra_path()
- self.assertEqual(cmd.extra_path, ['path', 'dirs'])
- self.assertEqual(cmd.extra_dirs, 'dirs')
- self.assertEqual(cmd.path_file, 'path')
-
- # one element
- cmd.extra_path = ['path']
- cmd.handle_extra_path()
- self.assertEqual(cmd.extra_path, ['path'])
- self.assertEqual(cmd.extra_dirs, 'path')
- self.assertEqual(cmd.path_file, 'path')
-
- # none
- dist.extra_path = cmd.extra_path = None
- cmd.handle_extra_path()
- self.assertEqual(cmd.extra_path, None)
- self.assertEqual(cmd.extra_dirs, '')
- self.assertEqual(cmd.path_file, None)
-
- # three elements (no way !)
- cmd.extra_path = 'path,dirs,again'
- self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
-
- def test_finalize_options(self):
- dist = Distribution({'name': 'xx'})
- cmd = install(dist)
-
- # must supply either prefix/exec-prefix/home or
- # install-base/install-platbase -- not both
- cmd.prefix = 'prefix'
- cmd.install_base = 'base'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- # must supply either home or prefix/exec-prefix -- not both
- cmd.install_base = None
- cmd.home = 'home'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- # can't combine user with prefix/exec_prefix/home or
- # install_(plat)base
- cmd.prefix = None
- cmd.user = 'user'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- def test_record(self):
- install_dir = self.mkdtemp()
- 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()')
-
- cmd = install(dist)
- dist.command_obj['install'] = cmd
- cmd.root = install_dir
- cmd.record = os.path.join(project_dir, 'filelist')
- cmd.ensure_finalized()
- cmd.run()
-
- f = open(cmd.record)
- try:
- content = f.read()
- finally:
- 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]]
- self.assertEqual(found, expected)
-
- def test_record_extensions(self):
- cmd = test_support.missing_compiler_executable()
- 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'])])
- os.chdir(project_dir)
- support.copy_xxmodule_c(project_dir)
-
- buildextcmd = build_ext(dist)
- support.fixup_build_ext(buildextcmd)
- buildextcmd.ensure_finalized()
-
- cmd = install(dist)
- dist.command_obj['install'] = cmd
- dist.command_obj['build_ext'] = buildextcmd
- cmd.root = install_dir
- cmd.record = os.path.join(project_dir, 'filelist')
- cmd.ensure_finalized()
- cmd.run()
-
- f = open(cmd.record)
- try:
- content = f.read()
- finally:
- 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]]
- self.assertEqual(found, expected)
-
- def test_debug_mode(self):
- # this covers the code called when DEBUG is set
- old_logs_len = len(self.logs)
- install_module.DEBUG = True
- try:
- with captured_stdout():
- self.test_record()
- finally:
- install_module.DEBUG = False
- self.assertGreater(len(self.logs), old_logs_len)
-
-
-def test_suite():
- return unittest.makeSuite(InstallTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_install_data.py b/tests/test_install_data.py
deleted file mode 100644
index 32ab296a..00000000
--- a/tests/test_install_data.py
+++ /dev/null
@@ -1,75 +0,0 @@
-"""Tests for distutils.command.install_data."""
-import os
-import unittest
-
-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):
-
- def test_simple_run(self):
- pkg_dir, dist = self.create_dist()
- cmd = install_data(dist)
- cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
-
- # data_files can contain
- # - simple files
- # - a tuple with a path, and a list of file
- one = os.path.join(pkg_dir, 'one')
- self.write_file(one, 'xxx')
- inst2 = os.path.join(pkg_dir, 'inst2')
- two = os.path.join(pkg_dir, 'two')
- self.write_file(two, 'xxx')
-
- cmd.data_files = [one, (inst2, [two])]
- self.assertEqual(cmd.get_inputs(), [one, (inst2, [two])])
-
- # let's run the command
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the result
- self.assertEqual(len(cmd.get_outputs()), 2)
- rtwo = os.path.split(two)[-1]
- self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
- rone = os.path.split(one)[-1]
- self.assertTrue(os.path.exists(os.path.join(inst, rone)))
- cmd.outfiles = []
-
- # let's try with warn_dir one
- cmd.warn_dir = 1
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the result
- self.assertEqual(len(cmd.get_outputs()), 2)
- self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
- self.assertTrue(os.path.exists(os.path.join(inst, rone)))
- cmd.outfiles = []
-
- # now using root and empty dir
- cmd.root = os.path.join(pkg_dir, 'root')
- inst3 = os.path.join(cmd.install_dir, 'inst3')
- 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.ensure_finalized()
- cmd.run()
-
- # let's check the result
- self.assertEqual(len(cmd.get_outputs()), 4)
- 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.makeSuite(InstallDataTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_install_headers.py b/tests/test_install_headers.py
deleted file mode 100644
index 2217b321..00000000
--- a/tests/test_install_headers.py
+++ /dev/null
@@ -1,39 +0,0 @@
-"""Tests for distutils.command.install_headers."""
-import os
-import unittest
-
-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):
-
- def test_simple_run(self):
- # we have two headers
- header_list = self.mkdtemp()
- header1 = os.path.join(header_list, 'header1')
- header2 = os.path.join(header_list, 'header2')
- self.write_file(header1)
- self.write_file(header2)
- headers = [header1, header2]
-
- pkg_dir, dist = self.create_dist(headers=headers)
- cmd = install_headers(dist)
- self.assertEqual(cmd.get_inputs(), headers)
-
- # let's run the command
- cmd.install_dir = os.path.join(pkg_dir, 'inst')
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the results
- self.assertEqual(len(cmd.get_outputs()), 2)
-
-def test_suite():
- return unittest.makeSuite(InstallHeadersTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_install_lib.py b/tests/test_install_lib.py
deleted file mode 100644
index fda6315b..00000000
--- a/tests/test_install_lib.py
+++ /dev/null
@@ -1,115 +0,0 @@
-"""Tests for distutils.command.install_data."""
-import sys
-import os
-import importlib.util
-import unittest
-
-from distutils.command.install_lib import install_lib
-from distutils.extension import Extension
-from distutils.tests import support
-from distutils.errors import DistutilsOptionError
-from test.support import run_unittest
-
-
-class InstallLibTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def test_finalize_options(self):
- dist = self.create_dist()[1]
- cmd = install_lib(dist)
-
- cmd.finalize_options()
- self.assertEqual(cmd.compile, 1)
- self.assertEqual(cmd.optimize, 0)
-
- # optimize must be 0, 1, or 2
- cmd.optimize = 'foo'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
- cmd.optimize = '4'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- cmd.optimize = '2'
- cmd.finalize_options()
- self.assertEqual(cmd.optimize, 2)
-
- @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
- def test_byte_compile(self):
- project_dir, dist = self.create_dist()
- os.chdir(project_dir)
- cmd = install_lib(dist)
- cmd.compile = cmd.optimize = 1
-
- f = os.path.join(project_dir, 'foo.py')
- 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)
- self.assertTrue(os.path.exists(pyc_file))
- self.assertTrue(os.path.exists(pyc_opt_file))
-
- def test_get_outputs(self):
- project_dir, dist = self.create_dist()
- os.chdir(project_dir)
- os.mkdir('spam')
- cmd = install_lib(dist)
-
- # setting up a dist environment
- cmd.compile = cmd.optimize = 1
- cmd.install_dir = self.mkdtemp()
- f = os.path.join(project_dir, 'spam', '__init__.py')
- self.write_file(f, '# python package')
- cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
- cmd.distribution.packages = ['spam']
- cmd.distribution.script_name = 'setup.py'
-
- # get_outputs should return 4 elements: spam/__init__.py and .pyc,
- # foo.import-tag-abiflags.so / foo.pyd
- outputs = cmd.get_outputs()
- self.assertEqual(len(outputs), 4, outputs)
-
- def test_get_inputs(self):
- project_dir, dist = self.create_dist()
- os.chdir(project_dir)
- os.mkdir('spam')
- cmd = install_lib(dist)
-
- # setting up a dist environment
- cmd.compile = cmd.optimize = 1
- cmd.install_dir = self.mkdtemp()
- f = os.path.join(project_dir, 'spam', '__init__.py')
- self.write_file(f, '# python package')
- cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
- cmd.distribution.packages = ['spam']
- cmd.distribution.script_name = 'setup.py'
-
- # get_inputs should return 2 elements: spam/__init__.py and
- # foo.import-tag-abiflags.so / foo.pyd
- inputs = cmd.get_inputs()
- self.assertEqual(len(inputs), 2, inputs)
-
- def test_dont_write_bytecode(self):
- # makes sure byte_compile is not used
- dist = self.create_dist()[1]
- cmd = install_lib(dist)
- cmd.compile = 1
- cmd.optimize = 1
-
- old_dont_write_bytecode = sys.dont_write_bytecode
- sys.dont_write_bytecode = True
- try:
- cmd.byte_compile([])
- finally:
- sys.dont_write_bytecode = old_dont_write_bytecode
-
- self.assertIn('byte-compiling is disabled',
- self.logs[0][1] % self.logs[0][2])
-
-
-def test_suite():
- return unittest.makeSuite(InstallLibTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_install_scripts.py b/tests/test_install_scripts.py
deleted file mode 100644
index 1f7b1038..00000000
--- a/tests/test_install_scripts.py
+++ /dev/null
@@ -1,82 +0,0 @@
-"""Tests for distutils.command.install_scripts."""
-
-import os
-import unittest
-
-from distutils.command.install_scripts import install_scripts
-from distutils.core import Distribution
-
-from distutils.tests import support
-from test.support import run_unittest
-
-
-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["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)
- self.assertIsNone(cmd.build_dir)
- self.assertIsNone(cmd.install_dir)
-
- cmd.finalize_options()
-
- self.assertTrue(cmd.force)
- self.assertTrue(cmd.skip_build)
- self.assertEqual(cmd.build_dir, "/foo/bar")
- self.assertEqual(cmd.install_dir, "/splat/funk")
-
- def test_installation(self):
- source = self.mkdtemp()
- expected = []
-
- def write_script(name, text):
- expected.append(name)
- f = open(os.path.join(source, name), "w")
- try:
- f.write(text)
- 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"))
-
- target = self.mkdtemp()
- dist = Distribution()
- dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
- dist.command_obj["install"] = support.DummyCommand(
- install_scripts=target,
- force=1,
- skip_build=1,
- )
- cmd = install_scripts(dist)
- cmd.finalize_options()
- cmd.run()
-
- installed = os.listdir(target)
- for name in expected:
- self.assertIn(name, installed)
-
-
-def test_suite():
- return unittest.makeSuite(InstallScriptsTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_log.py b/tests/test_log.py
deleted file mode 100644
index 75cf9006..00000000
--- a/tests/test_log.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""Tests for distutils.log"""
-
-import io
-import sys
-import unittest
-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'):
- with self.subTest(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):
- 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')
- 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')
-
-def test_suite():
- return unittest.makeSuite(TestLog)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_msvc9compiler.py b/tests/test_msvc9compiler.py
deleted file mode 100644
index 77a07ef3..00000000
--- a/tests/test_msvc9compiler.py
+++ /dev/null
@@ -1,184 +0,0 @@
-"""Tests for distutils.msvc9compiler."""
-import sys
-import unittest
-import os
-
-from distutils.errors import DistutilsPlatformError
-from distutils.tests import support
-from test.support import run_unittest
-
-# A manifest with the only assembly reference being the msvcrt assembly, so
-# should have the assembly completely stripped. Note that although the
-# assembly has a <security> reference the assembly is removed - that is
-# currently a "feature", not a bug :)
-_MANIFEST_WITH_ONLY_MSVC_REFERENCE = """\
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
-</assembly>
-"""
-
-# A manifest with references to assemblies other than msvcrt. When processed,
-# this assembly should be returned with just the msvcrt part removed.
-_MANIFEST_WITH_MULTIPLE_REFERENCES = """\
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX"></assemblyIdentity>
- </dependentAssembly>
- </dependency>
-</assembly>
-"""
-
-_CLEANED_MANIFEST = """\
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
-
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX"></assemblyIdentity>
- </dependentAssembly>
- </dependency>
-</assembly>"""
-
-if sys.platform=="win32":
- from distutils.msvccompiler import get_build_version
- 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):
-
- 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')
- 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
- # windows registry versions.
- path = r'Control Panel\Desktop'
- v = Reg.get_value(path, 'dragfullwindows')
- self.assertIn(v, ('0', '1', '2'))
-
- import winreg
- HKCU = winreg.HKEY_CURRENT_USER
- keys = Reg.read_keys(HKCU, 'xxxx')
- self.assertEqual(keys, None)
-
- keys = Reg.read_keys(HKCU, r'Control Panel')
- self.assertIn('Desktop', keys)
-
- 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')
- try:
- f.write(_MANIFEST_WITH_MULTIPLE_REFERENCES)
- finally:
- f.close()
-
- compiler = MSVCCompiler()
- compiler._remove_visual_c_ref(manifest)
-
- # see what we got
- f = open(manifest)
- try:
- # removing trailing spaces
- content = '\n'.join([line.rstrip() for line in f.readlines()])
- finally:
- f.close()
-
- # makes sure the manifest was properly cleaned
- self.assertEqual(content, _CLEANED_MANIFEST)
-
- def test_remove_entire_manifest(self):
- from distutils.msvc9compiler import MSVCCompiler
- tempdir = self.mkdtemp()
- manifest = os.path.join(tempdir, 'manifest')
- f = open(manifest, 'w')
- try:
- f.write(_MANIFEST_WITH_ONLY_MSVC_REFERENCE)
- finally:
- f.close()
-
- compiler = MSVCCompiler()
- got = compiler._remove_visual_c_ref(manifest)
- self.assertIsNone(got)
-
-
-def test_suite():
- return unittest.makeSuite(msvc9compilerTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_msvccompiler.py b/tests/test_msvccompiler.py
deleted file mode 100644
index b518d6a7..00000000
--- a/tests/test_msvccompiler.py
+++ /dev/null
@@ -1,81 +0,0 @@
-"""Tests for distutils._msvccompiler."""
-import sys
-import unittest
-import os
-
-from distutils.errors import DistutilsPlatformError
-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")
-
-@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
- def _find_vcvarsall(plat_spec):
- return None, None
-
- old_find_vcvarsall = _msvccompiler._find_vcvarsall
- _msvccompiler._find_vcvarsall = _find_vcvarsall
- try:
- self.assertRaises(DistutilsPlatformError,
- _msvccompiler._get_vc_env,
- 'wont find this version')
- finally:
- _msvccompiler._find_vcvarsall = old_find_vcvarsall
-
- def test_get_vc_env_unicode(self):
- import distutils._msvccompiler as _msvccompiler
-
- test_var = 'ṰḖṤṪ┅ṼẨṜ'
- test_value = '₃⁴₅'
-
- # Ensure we don't early exit from _get_vc_env
- old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
- os.environ[test_var] = test_value
- try:
- env = _msvccompiler._get_vc_env('x86')
- self.assertIn(test_var.lower(), env)
- self.assertEqual(test_value, env[test_var.lower()])
- finally:
- os.environ.pop(test_var)
- if old_distutils_use_sdk:
- os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
-
- def test_get_vc2017(self):
- import distutils._msvccompiler as _msvccompiler
-
- # This function cannot be mocked, so pass it if we find VS 2017
- # and mark it skipped if we do not.
- version, path = _msvccompiler._find_vc2017()
- if version:
- self.assertGreaterEqual(version, 15)
- self.assertTrue(os.path.isdir(path))
- else:
- raise unittest.SkipTest("VS 2017 is not installed")
-
- def test_get_vc2015(self):
- import distutils._msvccompiler as _msvccompiler
-
- # This function cannot be mocked, so pass it if we find VS 2015
- # and mark it skipped if we do not.
- version, path = _msvccompiler._find_vc2015()
- if version:
- self.assertGreaterEqual(version, 14)
- self.assertTrue(os.path.isdir(path))
- else:
- raise unittest.SkipTest("VS 2015 is not installed")
-
-def test_suite():
- return unittest.makeSuite(msvccompilerTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_register.py b/tests/test_register.py
deleted file mode 100644
index e68b0af3..00000000
--- a/tests/test_register.py
+++ /dev/null
@@ -1,323 +0,0 @@
-"""Tests for distutils.command.register."""
-import os
-import unittest
-import getpass
-import urllib
-import warnings
-
-from test.support import check_warnings, run_unittest
-
-from distutils.command import register as register_module
-from distutils.command.register import register
-from distutils.errors import DistutilsSetupError
-from distutils.log import INFO
-
-from distutils.tests.test_config import BasePyPIRCCommandTestCase
-
-try:
- import docutils
-except ImportError:
- docutils = None
-
-PYPIRC_NOPASSWORD = """\
-[distutils]
-
-index-servers =
- server1
-
-[server1]
-username:me
-"""
-
-WANTED_PYPIRC = """\
-[distutils]
-index-servers =
- pypi
-
-[pypi]
-username:tarek
-password:password
-"""
-
-class Inputs(object):
- """Fakes user inputs."""
- def __init__(self, *answers):
- self.answers = answers
- self.index = 0
-
- def __call__(self, prompt=''):
- try:
- return self.answers[self.index]
- finally:
- self.index += 1
-
-class FakeOpener(object):
- """Fakes a PyPI server"""
- def __init__(self):
- self.reqs = []
-
- def __call__(self, *args):
- return self
-
- def open(self, req, data=None, timeout=None):
- self.reqs.append(req)
- return self
-
- def read(self):
- return b'xxx'
-
- def getheader(self, name, default=None):
- return {
- 'content-type': 'text/plain; charset=utf-8',
- }.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
- self.conn = urllib.request.build_opener = FakeOpener()
-
- def tearDown(self):
- getpass.getpass = self._old_getpass
- urllib.request._opener = None
- urllib.request.build_opener = self.old_opener
- super(RegisterTestCase, self).tearDown()
-
- def _get_cmd(self, metadata=None):
- if metadata is None:
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx'}
- pkg_info, dist = self.create_dist(**metadata)
- return register(dist)
-
- def test_create_pypirc(self):
- # this test makes sure a .pypirc file
- # is created when requested.
-
- # let's create a register instance
- cmd = self._get_cmd()
-
- # we shouldn't have a .pypirc file yet
- self.assertFalse(os.path.exists(self.rc))
-
- # patching input and getpass.getpass
- # so register gets happy
- #
- # Here's what we are faking :
- # use your existing login (choice 1.)
- # Username : 'tarek'
- # Password : 'password'
- # Save your login (y/N)? : 'y'
- inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- del register_module.input
-
- # we should have a brand new .pypirc file
- self.assertTrue(os.path.exists(self.rc))
-
- # with the content similar to WANTED_PYPIRC
- f = open(self.rc)
- try:
- content = f.read()
- self.assertEqual(content, WANTED_PYPIRC)
- finally:
- f.close()
-
- # now let's make sure the .pypirc file generated
- # really works : we shouldn't be asked anything
- # if we run the command again
- def _no_way(prompt=''):
- raise AssertionError(prompt)
- register_module.input = _no_way
-
- cmd.show_response = 1
- cmd.run()
-
- # let's see what the server received : we should
- # have 2 similar requests
- self.assertEqual(len(self.conn.reqs), 2)
- req1 = dict(self.conn.reqs[0].headers)
- req2 = dict(self.conn.reqs[1].headers)
-
- self.assertEqual(req1['Content-length'], '1374')
- self.assertEqual(req2['Content-length'], '1374')
- self.assertIn(b'xxx', self.conn.reqs[1].data)
-
- def test_password_not_in_file(self):
-
- self.write_file(self.rc, PYPIRC_NOPASSWORD)
- cmd = self._get_cmd()
- cmd._set_config()
- cmd.finalize_options()
- cmd.send_metadata()
-
- # dist.password should be set
- # therefore used afterwards by other commands
- self.assertEqual(cmd.distribution.password, 'password')
-
- def test_registering(self):
- # this test runs choice 2
- cmd = self._get_cmd()
- inputs = Inputs('2', 'tarek', 'tarek@ziade.org')
- register_module.input = inputs.__call__
- try:
- # let's run the command
- cmd.run()
- finally:
- del register_module.input
-
- # we should have send a request
- self.assertEqual(len(self.conn.reqs), 1)
- req = self.conn.reqs[0]
- headers = dict(req.headers)
- self.assertEqual(headers['Content-length'], '608')
- self.assertIn(b'tarek', req.data)
-
- def test_password_reset(self):
- # this test runs choice 3
- cmd = self._get_cmd()
- inputs = Inputs('3', 'tarek@ziade.org')
- register_module.input = inputs.__call__
- try:
- # let's run the command
- cmd.run()
- finally:
- del register_module.input
-
- # we should have send a request
- self.assertEqual(len(self.conn.reqs), 1)
- req = self.conn.reqs[0]
- headers = dict(req.headers)
- self.assertEqual(headers['Content-length'], '290')
- self.assertIn(b'tarek', req.data)
-
- @unittest.skipUnless(docutils is not None, 'needs docutils')
- def test_strict(self):
- # testing the script option
- # when on, the register command stops if
- # the metadata is incomplete or if
- # long_description is not reSt compliant
-
- # empty metadata
- cmd = self._get_cmd({})
- cmd.ensure_finalized()
- cmd.strict = 1
- 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'}
-
- cmd = self._get_cmd(metadata)
- cmd.ensure_finalized()
- cmd.strict = 1
- self.assertRaises(DistutilsSetupError, cmd.run)
-
- # now something that works
- metadata['long_description'] = 'title\n=====\n\ntext'
- cmd = self._get_cmd(metadata)
- cmd.ensure_finalized()
- cmd.strict = 1
- inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- del register_module.input
-
- # strict is not by default
- cmd = self._get_cmd()
- cmd.ensure_finalized()
- inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- 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'}
-
- cmd = self._get_cmd(metadata)
- cmd.ensure_finalized()
- cmd.strict = 1
- inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- del register_module.input
-
- @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}
- cmd = self._get_cmd(metadata)
- cmd.ensure_finalized()
- cmd.strict = True
- inputs = Inputs('2', 'tarek', 'tarek@ziade.org')
- register_module.input = inputs
- self.addCleanup(delattr, register_module, 'input')
-
- self.assertRaises(DistutilsSetupError, cmd.run)
-
- def test_check_metadata_deprecated(self):
- # makes sure make_metadata is deprecated
- cmd = self._get_cmd()
- with check_warnings() as w:
- warnings.simplefilter("always")
- cmd.check_metadata()
- self.assertEqual(len(w.warnings), 1)
-
- def test_list_classifiers(self):
- cmd = self._get_cmd()
- cmd.list_classifiers = 1
- cmd.run()
- results = self.get_logs(INFO)
- self.assertEqual(results, ['running check', 'xxx'])
-
- def test_show_response(self):
- # test that the --show-response option return a well formatted response
- cmd = self._get_cmd()
- inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs.__call__
- cmd.show_response = 1
- try:
- cmd.run()
- finally:
- del register_module.input
-
- results = self.get_logs(INFO)
- self.assertEqual(results[3], 75 * '-' + '\nxxx\n' + 75 * '-')
-
-
-def test_suite():
- return unittest.makeSuite(RegisterTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_sdist.py b/tests/test_sdist.py
deleted file mode 100644
index 23db1269..00000000
--- a/tests/test_sdist.py
+++ /dev/null
@@ -1,492 +0,0 @@
-"""Tests for distutils.command.sdist."""
-import os
-import tarfile
-import unittest
-import warnings
-import zipfile
-from os.path import join
-from textwrap import dedent
-from test.support import captured_stdout, check_warnings, run_unittest
-
-try:
- import zlib
- ZLIB_SUPPORT = True
-except ImportError:
- ZLIB_SUPPORT = False
-
-try:
- import grp
- import pwd
- UID_GID_SUPPORT = True
-except ImportError:
- UID_GID_SUPPORT = False
-
-from distutils.command.sdist import sdist, show_formats
-from distutils.core import Distribution
-from distutils.tests.test_config import BasePyPIRCCommandTestCase
-from distutils.errors import DistutilsOptionError
-from distutils.spawn import find_executable
-from distutils.log import WARN
-from distutils.filelist import FileList
-from distutils.archive_util import ARCHIVE_FORMATS
-
-SETUP_PY = """
-from distutils.core import setup
-import somecode
-
-setup(name='fake')
-"""
-
-MANIFEST = """\
-# file GENERATED by distutils, do NOT edit
-README
-buildout.cfg
-inroot.txt
-setup.py
-data%(sep)sdata.dt
-scripts%(sep)sscript.py
-some%(sep)sfile.txt
-some%(sep)sother_file.txt
-somecode%(sep)s__init__.py
-somecode%(sep)sdoc.dat
-somecode%(sep)sdoc.txt
-"""
-
-class SDistTestCase(BasePyPIRCCommandTestCase):
-
- def setUp(self):
- # PyPIRCCommandTestCase creates a temp dir already
- # and put it in self.tmp_dir
- super(SDistTestCase, self).setUp()
- # setting up an environment
- self.old_path = os.getcwd()
- os.mkdir(join(self.tmp_dir, 'somecode'))
- os.mkdir(join(self.tmp_dir, 'dist'))
- # a package, and a README
- self.write_file((self.tmp_dir, 'README'), 'xxx')
- self.write_file((self.tmp_dir, 'somecode', '__init__.py'), '#')
- self.write_file((self.tmp_dir, 'setup.py'), SETUP_PY)
- os.chdir(self.tmp_dir)
-
- def tearDown(self):
- # back to normal
- os.chdir(self.old_path)
- super(SDistTestCase, self).tearDown()
-
- 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'}
- dist = Distribution(metadata)
- dist.script_name = 'setup.py'
- dist.packages = ['somecode']
- dist.include_package_data = True
- cmd = sdist(dist)
- cmd.dist_dir = 'dist'
- return dist, cmd
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_prune_file_list(self):
- # this test creates a project with some VCS dirs and an NFS rename
- # file, then launches sdist to check they get pruned on all systems
-
- # creating VCS directories with some files in them
- os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
- 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')
-
- 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', '.nfs0001'), 'xxx')
-
- # now building a sdist
- dist, cmd = self.get_cmd()
-
- # zip is available universally
- # (tar might not be installed under win32)
- cmd.formats = ['zip']
-
- cmd.ensure_finalized()
- cmd.run()
-
- # now let's check what we have
- dist_folder = join(self.tmp_dir, 'dist')
- files = os.listdir(dist_folder)
- self.assertEqual(files, ['fake-1.0.zip'])
-
- zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
- try:
- content = zip_file.namelist()
- finally:
- zip_file.close()
-
- # making sure everything has been pruned correctly
- 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")
- def test_make_distribution(self):
- # now building a sdist
- dist, cmd = self.get_cmd()
-
- # creating a gztar then a tar
- cmd.formats = ['gztar', 'tar']
- cmd.ensure_finalized()
- cmd.run()
-
- # making sure we have two files
- dist_folder = join(self.tmp_dir, 'dist')
- result = os.listdir(dist_folder)
- result.sort()
- self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
-
- os.remove(join(dist_folder, 'fake-1.0.tar'))
- os.remove(join(dist_folder, 'fake-1.0.tar.gz'))
-
- # now trying a tar then a gztar
- cmd.formats = ['tar', 'gztar']
-
- cmd.ensure_finalized()
- cmd.run()
-
- result = os.listdir(dist_folder)
- result.sort()
- self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_add_defaults(self):
-
- # http://bugs.python.org/issue2279
-
- # add_default should also include
- # data_files and package_data
- dist, cmd = self.get_cmd()
-
- # filling data_files by pointing files
- # in package_data
- 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'), '#')
-
- # adding some data in data_files
- data_dir = join(self.tmp_dir, 'data')
- os.mkdir(data_dir)
- self.write_file((data_dir, 'data.dt'), '#')
- some_dir = join(self.tmp_dir, 'some')
- os.mkdir(some_dir)
- # make sure VCS directories are pruned (#14004)
- hg_dir = join(self.tmp_dir, '.hg')
- os.mkdir(hg_dir)
- self.write_file((hg_dir, 'last-message.txt'), '#')
- # a buggy regex used to prevent this from working on windows (#6884)
- self.write_file((self.tmp_dir, 'buildout.cfg'), '#')
- self.write_file((self.tmp_dir, 'inroot.txt'), '#')
- 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']
-
- # adding a script
- script_dir = join(self.tmp_dir, 'scripts')
- os.mkdir(script_dir)
- self.write_file((script_dir, 'script.py'), '#')
- dist.scripts = [join('scripts', 'script.py')]
-
- cmd.formats = ['zip']
- cmd.use_defaults = True
-
- cmd.ensure_finalized()
- cmd.run()
-
- # now let's check what we have
- dist_folder = join(self.tmp_dir, 'dist')
- files = os.listdir(dist_folder)
- self.assertEqual(files, ['fake-1.0.zip'])
-
- zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
- try:
- content = zip_file.namelist()
- finally:
- 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']
- self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
-
- # checking the MANIFEST
- f = open(join(self.tmp_dir, 'MANIFEST'))
- try:
- manifest = f.read()
- finally:
- f.close()
- self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_metadata_check_option(self):
- # testing the `medata-check` option
- dist, cmd = self.get_cmd(metadata={})
-
- # this should raise some warnings !
- # with the `check` subcommand
- cmd.ensure_finalized()
- cmd.run()
- warnings = [msg for msg in self.get_logs(WARN) if
- msg.startswith('warning: check:')]
- self.assertEqual(len(warnings), 2)
-
- # trying with a complete set of metadata
- self.clear_logs()
- dist, cmd = self.get_cmd()
- cmd.ensure_finalized()
- cmd.metadata_check = 0
- cmd.run()
- 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):
- # makes sure make_metadata is deprecated
- dist, cmd = self.get_cmd()
- with check_warnings() as w:
- warnings.simplefilter("always")
- cmd.check_metadata()
- self.assertEqual(len(w.warnings), 1)
-
- def test_show_formats(self):
- with captured_stdout() as stdout:
- show_formats()
-
- # 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=')]
- self.assertEqual(len(output), num_formats)
-
- def test_finalize_options(self):
- dist, cmd = self.get_cmd()
- cmd.finalize_options()
-
- # default options set by finalize
- self.assertEqual(cmd.manifest, 'MANIFEST')
- self.assertEqual(cmd.template, 'MANIFEST.in')
- self.assertEqual(cmd.dist_dir, 'dist')
-
- # formats has to be a string splitable on (' ', ',') or
- # a stringlist
- cmd.formats = 1
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
- cmd.formats = ['zip']
- cmd.finalize_options()
-
- # formats has to be known
- cmd.formats = 'supazipa'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- # the following tests make sure there is a nice error message instead
- # of a traceback when parsing an invalid manifest template
-
- def _check_template(self, content):
- dist, cmd = self.get_cmd()
- os.chdir(self.tmp_dir)
- self.write_file('MANIFEST.in', content)
- cmd.ensure_finalized()
- cmd.filelist = FileList()
- cmd.read_template()
- warnings = self.get_logs(WARN)
- self.assertEqual(len(warnings), 1)
-
- def test_invalid_template_unknown_command(self):
- self._check_template('taunt knights *')
-
- def test_invalid_template_wrong_arguments(self):
- # this manifest command takes one argument
- self._check_template('prune')
-
- @unittest.skipIf(os.name != 'nt', 'test relevant for Windows only')
- def test_invalid_template_wrong_path(self):
- # on Windows, trailing slashes are not allowed
- # this used to crash instead of raising a warning: #8286
- self._check_template('include examples/')
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_get_file_list(self):
- # make sure MANIFEST is recalculated
- dist, cmd = self.get_cmd()
-
- # filling data_files by pointing files in package_data
- dist.package_data = {'somecode': ['*.txt']}
- self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
- cmd.formats = ['gztar']
- cmd.ensure_finalized()
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
- finally:
- f.close()
-
- self.assertEqual(len(manifest), 5)
-
- # adding a file
- self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
-
- # make sure build_py is reinitialized, like a fresh run
- build_py = dist.get_command_obj('build_py')
- build_py.finalized = False
- build_py.ensure_finalized()
-
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- manifest2 = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
- finally:
- f.close()
-
- # do we have the new file in MANIFEST ?
- self.assertEqual(len(manifest2), 6)
- self.assertIn('doc2.txt', manifest2[-1])
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_manifest_marker(self):
- # check that autogenerated MANIFESTs have a marker
- dist, cmd = self.get_cmd()
- cmd.ensure_finalized()
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- 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')
-
- @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("""\
- # bad.py
- #bad.py
- good.py
- """)
- dist, cmd = self.get_cmd()
- cmd.ensure_finalized()
- self.write_file((self.tmp_dir, cmd.manifest), contents)
- self.write_file((self.tmp_dir, 'good.py'), '# pick me!')
- self.write_file((self.tmp_dir, 'bad.py'), "# don't pick me!")
- self.write_file((self.tmp_dir, '#bad.py'), "# don't pick me!")
- cmd.run()
- self.assertEqual(cmd.filelist.files, ['good.py'])
-
- @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
- def test_manual_manifest(self):
- # check that a MANIFEST without a marker is left alone
- dist, cmd = self.get_cmd()
- 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.')
- 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() != '']
- finally:
- f.close()
-
- self.assertEqual(manifest, ['README.manual'])
-
- archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
- archive = tarfile.open(archive_name)
- try:
- 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'])
-
- @unittest.skipUnless(ZLIB_SUPPORT, "requires zlib")
- @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
- @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()
-
- # creating a gztar and specifying the owner+group
- cmd.formats = ['gztar']
- cmd.owner = pwd.getpwuid(0)[0]
- cmd.group = grp.getgrgid(0)[0]
- cmd.ensure_finalized()
- cmd.run()
-
- # making sure we have the good rights
- archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
- archive = tarfile.open(archive_name)
- try:
- for member in archive.getmembers():
- self.assertEqual(member.uid, 0)
- self.assertEqual(member.gid, 0)
- finally:
- archive.close()
-
- # building a sdist again
- dist, cmd = self.get_cmd()
-
- # creating a gztar
- cmd.formats = ['gztar']
- cmd.ensure_finalized()
- cmd.run()
-
- # making sure we have the good rights
- archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
- archive = tarfile.open(archive_name)
-
- # note that we are not testing the group ownership here
- # because, depending on the platforms and the container
- # rights (see #7408)
- try:
- for member in archive.getmembers():
- self.assertEqual(member.uid, os.getuid())
- finally:
- archive.close()
-
-def test_suite():
- return unittest.makeSuite(SDistTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_spawn.py b/tests/test_spawn.py
deleted file mode 100644
index cf1faad5..00000000
--- a/tests/test_spawn.py
+++ /dev/null
@@ -1,132 +0,0 @@
-"""Tests for distutils.spawn."""
-import os
-import stat
-import sys
-import unittest.mock
-from test.support import run_unittest, unix_shell
-from test import support as test_support
-
-from distutils.spawn import find_executable
-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')
- def test_spawn(self):
- tmpdir = self.mkdtemp()
-
- # creating something executable
- # through the shell that returns 1
- if sys.platform != 'win32':
- exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!%s\nexit 1' % unix_shell)
- else:
- exe = os.path.join(tmpdir, 'foo.bat')
- self.write_file(exe, 'exit 1')
-
- os.chmod(exe, 0o777)
- self.assertRaises(DistutilsExecError, spawn, [exe])
-
- # now something that works
- if sys.platform != 'win32':
- exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!%s\nexit 0' % unix_shell)
- else:
- exe = os.path.join(tmpdir, 'foo.bat')
- self.write_file(exe, 'exit 0')
-
- os.chmod(exe, 0o777)
- spawn([exe]) # should work without any error
-
- def test_find_executable(self):
- with test_support.temp_dir() as tmp_dir:
- # use TESTFN to get a pseudo-unique filename
- program_noeext = test_support.TESTFN
- # Give the temporary program an ".exe" suffix for all.
- # It's needed on Windows and not harmful on other platforms.
- program = program_noeext + ".exe"
-
- filename = os.path.join(tmp_dir, program)
- with open(filename, "wb"):
- pass
- os.chmod(filename, stat.S_IXUSR)
-
- # test path parameter
- rv = find_executable(program, path=tmp_dir)
- self.assertEqual(rv, filename)
-
- if sys.platform == 'win32':
- # test without ".exe" extension
- rv = find_executable(program_noeext, path=tmp_dir)
- self.assertEqual(rv, filename)
-
- # test find in the current directory
- with test_support.change_cwd(tmp_dir):
- rv = find_executable(program)
- self.assertEqual(rv, program)
-
- # test non-existent program
- dont_exist_program = "dontexist_" + program
- rv = find_executable(dont_exist_program , path=tmp_dir)
- self.assertIsNone(rv)
-
- # PATH='': no match, except in the current directory
- with test_support.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):
- rv = find_executable(program)
- self.assertIsNone(rv)
-
- # look in current directory
- with test_support.change_cwd(tmp_dir):
- rv = find_executable(program)
- self.assertEqual(rv, program)
-
- # PATH=':': explicitly looks in the current directory
- with test_support.EnvironmentVarGuard() as env:
- env['PATH'] = os.pathsep
- 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)
-
- # look in current directory
- with test_support.change_cwd(tmp_dir):
- rv = find_executable(program)
- self.assertEqual(rv, program)
-
- # missing PATH: test os.confstr("CS_PATH") and os.defpath
- with test_support.EnvironmentVarGuard() as env:
- 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):
- 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', ''):
- rv = find_executable(program)
- self.assertEqual(rv, filename)
-
-
-def test_suite():
- return unittest.makeSuite(SpawnTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_sysconfig.py b/tests/test_sysconfig.py
deleted file mode 100644
index 236755d0..00000000
--- a/tests/test_sysconfig.py
+++ /dev/null
@@ -1,274 +0,0 @@
-"""Tests for distutils.sysconfig."""
-import contextlib
-import os
-import shutil
-import subprocess
-import sys
-import textwrap
-import unittest
-
-from distutils import sysconfig
-from distutils.ccompiler import get_default_compiler
-from distutils.tests import support
-from test.support import TESTFN, run_unittest, check_warnings, swap_item
-
-class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
- def setUp(self):
- super(SysconfigTestCase, self).setUp()
- self.makefile = None
-
- def tearDown(self):
- if self.makefile is not None:
- os.unlink(self.makefile)
- self.cleanup_testfn()
- super(SysconfigTestCase, self).tearDown()
-
- def cleanup_testfn(self):
- if os.path.isfile(TESTFN):
- os.remove(TESTFN)
- elif os.path.isdir(TESTFN):
- shutil.rmtree(TESTFN)
-
- def test_get_config_h_filename(self):
- config_h = sysconfig.get_config_h_filename()
- self.assertTrue(os.path.isfile(config_h), config_h)
-
- 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)
- # test for pythonxx.lib?
- self.assertNotEqual(sysconfig.get_python_lib(),
- sysconfig.get_python_lib(prefix=TESTFN))
-
- def test_get_config_vars(self):
- cvars = sysconfig.get_config_vars()
- self.assertIsInstance(cvars, dict)
- self.assertTrue(cvars)
-
- def test_srcdir(self):
- # See Issues #15322, #15364.
- srcdir = sysconfig.get_config_var('srcdir')
-
- self.assertTrue(os.path.isabs(srcdir), srcdir)
- self.assertTrue(os.path.isdir(srcdir), srcdir)
-
- if sysconfig.python_build:
- # The python executable has not been installed so srcdir
- # should be a full source checkout.
- Python_h = os.path.join(srcdir, 'Include', 'Python.h')
- 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)
-
- def test_srcdir_independent_of_cwd(self):
- # srcdir should be independent of the current working directory
- # See Issues #15322, #15364.
- srcdir = sysconfig.get_config_var('srcdir')
- cwd = os.getcwd()
- try:
- os.chdir('..')
- srcdir2 = sysconfig.get_config_var('srcdir')
- finally:
- os.chdir(cwd)
- self.assertEqual(srcdir, srcdir2)
-
- def customize_compiler(self):
- # make sure AR gets caught
- class compiler:
- compiler_type = 'unix'
-
- def set_executables(self, **kw):
- self.exes = kw
-
- sysconfig_vars = {
- 'AR': 'sc_ar',
- 'CC': 'sc_cc',
- 'CXX': 'sc_cxx',
- 'ARFLAGS': '--sc-arflags',
- 'CFLAGS': '--sc-cflags',
- 'CCSHARED': '--sc-ccshared',
- 'LDSHARED': 'sc_ldshared',
- 'SHLIB_SUFFIX': 'sc_shutil_suffix',
-
- # On macOS, disable _osx_support.customize_compiler()
- 'CUSTOMIZED_OSX_COMPILER': 'True',
- }
-
- comp = compiler()
- with contextlib.ExitStack() as cm:
- for key, value in sysconfig_vars.items():
- cm.enter_context(swap_item(sysconfig._config_vars, key, value))
- sysconfig.customize_compiler(comp)
-
- return comp
-
- @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()
-
- os.environ['AR'] = 'env_ar'
- os.environ['CC'] = 'env_cc'
- os.environ['CPP'] = 'env_cpp'
- os.environ['CXX'] = 'env_cxx --env-cxx-flags'
- os.environ['LDSHARED'] = 'env_ldshared'
- os.environ['LDFLAGS'] = '--env-ldflags'
- os.environ['ARFLAGS'] = '--env-arflags'
- os.environ['CFLAGS'] = '--env-cflags'
- os.environ['CPPFLAGS'] = '--env-cppflags'
-
- 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.shared_lib_extension, 'sc_shutil_suffix')
-
- del os.environ['AR']
- del os.environ['CC']
- del os.environ['CPP']
- del os.environ['CXX']
- del os.environ['LDSHARED']
- del os.environ['LDFLAGS']
- del os.environ['ARFLAGS']
- del os.environ['CFLAGS']
- del os.environ['CPPFLAGS']
-
- 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.shared_lib_extension, 'sc_shutil_suffix')
-
- def test_parse_makefile_base(self):
- self.makefile = TESTFN
- fd = open(self.makefile, 'w')
- try:
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- finally:
- fd.close()
- d = sysconfig.parse_makefile(self.makefile)
- self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
- 'OTHER': 'foo'})
-
- def test_parse_makefile_literal_dollar(self):
- self.makefile = TESTFN
- fd = open(self.makefile, 'w')
- try:
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- finally:
- fd.close()
- d = sysconfig.parse_makefile(self.makefile)
- 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')
- 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
- # configurations. This requires customization of some of the
- # compiler configuration directives to suit the environment on
- # the installed machine. Some of these customizations may require
- # running external programs and, so, are deferred until needed by
- # the first extension module build. With Python 3.3, only
- # the Distutils version of sysconfig is used for extension module
- # builds, which happens earlier in the Distutils tests. This may
- # cause the following tests to fail since no tests have caused
- # the global version of sysconfig to call the customization yet.
- # The solution for now is to simply skip this test in this case.
- # 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')
- 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'])
-
- 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('''\
- 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)
- outs, errs = p.communicate()
- self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(SysconfigTestCase))
- return suite
-
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/tests/test_text_file.py b/tests/test_text_file.py
deleted file mode 100644
index 7e76240a..00000000
--- a/tests/test_text_file.py
+++ /dev/null
@@ -1,107 +0,0 @@
-"""Tests for distutils.text_file."""
-import os
-import unittest
-from distutils.text_file import TextFile
-from distutils.tests import support
-from test.support import run_unittest
-
-TEST_DATA = """# test file
-
-line 3 \\
-# intervening comment
- continues on next line
-"""
-
-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']
-
- # result 2: just strip comments
- 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"]
-
- # result 4: default, strip comments, blank lines,
- # and trailing whitespace
- result4 = ["line 3 \\",
- " continues on next line"]
-
- # result 5: strip comments and blanks, plus join lines (but don't
- # "collapse" joined lines
- result5 = ["line 3 continues on next line"]
-
- # result 6: strip comments and blanks, plus join lines (and
- # "collapse" joined lines
- result6 = ["line 3 continues on next line"]
-
- def test_input(count, description, file, expected_result):
- result = file.readlines()
- self.assertEqual(result, expected_result)
-
- tmpdir = self.mkdtemp()
- filename = os.path.join(tmpdir, "test.txt")
- out_file = open(filename, "w")
- try:
- out_file.write(TEST_DATA)
- finally:
- out_file.close()
-
- 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)
- 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)
- try:
- test_input(3, "strip blanks", in_file, result3)
- finally:
- in_file.close()
-
- in_file = TextFile(filename)
- try:
- test_input(4, "default processing", in_file, result4)
- finally:
- in_file.close()
-
- 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)
- try:
- test_input(6, "join lines with collapsing", in_file, result6)
- finally:
- in_file.close()
-
-def test_suite():
- return unittest.makeSuite(TextFileTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_unixccompiler.py b/tests/test_unixccompiler.py
deleted file mode 100644
index eef702cf..00000000
--- a/tests/test_unixccompiler.py
+++ /dev/null
@@ -1,141 +0,0 @@
-"""Tests for distutils.unixccompiler."""
-import sys
-import unittest
-from test.support import EnvironmentVarGuard, run_unittest
-
-from distutils import sysconfig
-from distutils.unixccompiler import UnixCCompiler
-
-class UnixCCompilerTestCase(unittest.TestCase):
-
- def setUp(self):
- self._backup_platform = sys.platform
- self._backup_get_config_var = sysconfig.get_config_var
- class CompilerWrapper(UnixCCompiler):
- def rpath_foo(self):
- return self.runtime_library_dir_option('/foo')
- self.cc = CompilerWrapper()
-
- def tearDown(self):
- sys.platform = self._backup_platform
- sysconfig.get_config_var = self._backup_get_config_var
-
- @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
- def test_runtime_libdir_option(self):
- # Issue#5900
- #
- # Ensure RUNPATH is added to extension modules with RPATH if
- # GNU ld is used
-
- # darwin
- sys.platform = 'darwin'
- self.assertEqual(self.cc.rpath_foo(), '-L/foo')
-
- # hp-ux
- sys.platform = 'hp-ux'
- old_gcv = sysconfig.get_config_var
- 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'])
-
- sysconfig.get_config_var = old_gcv
-
- # 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')
-
- # 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(), '-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(), '-R/foo')
-
- @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
- def test_osx_cc_overrides_ldshared(self):
- # Issue #18080:
- # ensure that setting CC env variable also changes default linker
- def gcv(v):
- if v == 'LDSHARED':
- return 'gcc-4.2 -bundle -undefined dynamic_lookup '
- return 'gcc-4.2'
- sysconfig.get_config_var = gcv
- with EnvironmentVarGuard() as env:
- env['CC'] = 'my_cc'
- del env['LDSHARED']
- sysconfig.customize_compiler(self.cc)
- self.assertEqual(self.cc.linker_so[0], 'my_cc')
-
- @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for OS X')
- def test_osx_explicit_ldshared(self):
- # Issue #18080:
- # ensure that setting CC env variable does not change
- # explicit LDSHARED setting for linker
- def gcv(v):
- if v == 'LDSHARED':
- return 'gcc-4.2 -bundle -undefined dynamic_lookup '
- return 'gcc-4.2'
- sysconfig.get_config_var = gcv
- with EnvironmentVarGuard() as env:
- env['CC'] = 'my_cc'
- env['LDSHARED'] = 'my_ld -bundle -dynamic'
- sysconfig.customize_compiler(self.cc)
- self.assertEqual(self.cc.linker_so[0], 'my_ld')
-
-
-def test_suite():
- return unittest.makeSuite(UnixCCompilerTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_upload.py b/tests/test_upload.py
deleted file mode 100644
index bca5516d..00000000
--- a/tests/test_upload.py
+++ /dev/null
@@ -1,223 +0,0 @@
-"""Tests for distutils.command.upload."""
-import os
-import unittest
-import unittest.mock as mock
-from urllib.request import HTTPError
-
-from test.support import run_unittest
-
-from distutils.command import upload as upload_mod
-from distutils.command.upload import upload
-from distutils.core import Distribution
-from distutils.errors import DistutilsError
-from distutils.log import ERROR, INFO
-
-from distutils.tests.test_config import PYPIRC, BasePyPIRCCommandTestCase
-
-PYPIRC_LONG_PASSWORD = """\
-[distutils]
-
-index-servers =
- server1
- server2
-
-[server1]
-username:me
-password:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
-[server2]
-username:meagain
-password: secret
-realm:acme
-repository:http://another.pypi/
-"""
-
-
-PYPIRC_NOPASSWORD = """\
-[distutils]
-
-index-servers =
- server1
-
-[server1]
-username:me
-"""
-
-class FakeOpen(object):
-
- def __init__(self, url, msg=None, code=None):
- self.url = url
- if not isinstance(url, str):
- self.req = url
- else:
- self.req = None
- self.msg = msg or 'OK'
- self.code = code or 200
-
- def getheader(self, name, default=None):
- return {
- 'content-type': 'text/plain; charset=utf-8',
- }.get(name.lower(), default)
-
- def read(self):
- return b'xyzzy'
-
- def getcode(self):
- return self.code
-
-
-class uploadTestCase(BasePyPIRCCommandTestCase):
-
- def setUp(self):
- super(uploadTestCase, self).setUp()
- self.old_open = upload_mod.urlopen
- upload_mod.urlopen = self._urlopen
- self.last_open = None
- self.next_msg = None
- self.next_code = None
-
- def tearDown(self):
- upload_mod.urlopen = self.old_open
- super(uploadTestCase, self).tearDown()
-
- def _urlopen(self, url):
- self.last_open = FakeOpen(url, msg=self.next_msg, code=self.next_code)
- return self.last_open
-
- def test_finalize_options(self):
-
- # new format
- self.write_file(self.rc, PYPIRC)
- dist = Distribution()
- cmd = upload(dist)
- cmd.finalize_options()
- 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):
- # file with no password
- self.write_file(self.rc, PYPIRC_NOPASSWORD)
-
- # make sure it passes
- dist = Distribution()
- cmd = upload(dist)
- cmd.finalize_options()
- self.assertEqual(cmd.password, None)
-
- # make sure we get it as well, if another command
- # initialized it at the dist level
- dist.password = 'xxx'
- cmd = upload(dist)
- cmd.finalize_options()
- self.assertEqual(cmd.password, 'xxx')
-
- def test_upload(self):
- tmp = self.mkdtemp()
- path = os.path.join(tmp, 'xxx')
- self.write_file(path)
- command, pyversion, filename = 'xxx', '2.6', path
- dist_files = [(command, pyversion, filename)]
- self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
-
- # lets run it
- pkg_dir, dist = self.create_dist(dist_files=dist_files)
- cmd = upload(dist)
- cmd.show_response = 1
- cmd.ensure_finalized()
- cmd.run()
-
- # what did we send ?
- headers = dict(self.last_open.req.headers)
- self.assertGreaterEqual(int(headers['Content-length']), 2162)
- content_type = headers['Content-type']
- self.assertTrue(content_type.startswith('multipart/form-data'))
- self.assertEqual(self.last_open.req.get_method(), 'POST')
- 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'protocol_version', data)
- self.assertIn(b'sha256_digest', data)
- self.assertIn(
- b'cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf'
- b'6860',
- data
- )
- if b'md5_digest' in data:
- self.assertIn(b'f561aaf6ef0bf14d4208bb46a4ccb3ad', data)
- if b'blake2_256_digest' in data:
- self.assertIn(
- b'b6f289a27d4fe90da63c503bfe0a9b761a8f76bb86148565065f040be'
- b'6d1c3044cf7ded78ef800509bccb4b648e507d88dc6383d67642aadcc'
- b'ce443f1534330a',
- data
- )
-
- # The PyPI response body was echoed
- results = self.get_logs(INFO)
- self.assertEqual(results[-1], 75 * '-' + '\nxyzzy\n' + 75 * '-')
-
- # bpo-32304: archives whose last byte was b'\r' were corrupted due to
- # normalization intended for Mac OS 9.
- def test_upload_correct_cr(self):
- # content that ends with \r should not be modified.
- tmp = self.mkdtemp()
- path = os.path.join(tmp, 'xxx')
- self.write_file(path, content='yy\r')
- command, pyversion, filename = 'xxx', '2.6', path
- dist_files = [(command, pyversion, filename)]
- self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
-
- # 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'
- )
- cmd = upload(dist)
- cmd.show_response = 1
- cmd.ensure_finalized()
- cmd.run()
-
- headers = dict(self.last_open.req.headers)
- self.assertGreaterEqual(int(headers['Content-length']), 2172)
- self.assertIn(b'long description\r', self.last_open.req.data)
-
- def test_upload_fails(self):
- self.next_msg = "Not Found"
- self.next_code = 404
- self.assertRaises(DistutilsError, self.test_upload)
-
- def test_wrong_exception_order(self):
- tmp = self.mkdtemp()
- path = os.path.join(tmp, 'xxx')
- self.write_file(path)
- dist_files = [('xxx', '2.6', path)] # command, pyversion, filename
- self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
-
- 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),
- ]
- 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 self.assertRaises(raised_exception):
- cmd = upload(dist)
- cmd.ensure_finalized()
- cmd.run()
- results = self.get_logs(ERROR)
- self.assertIn(expected, results[-1])
- self.clear_logs()
-
-
-def test_suite():
- return unittest.makeSuite(uploadTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_util.py b/tests/test_util.py
deleted file mode 100644
index bf0d4333..00000000
--- a/tests/test_util.py
+++ /dev/null
@@ -1,309 +0,0 @@
-"""Tests for distutils.util."""
-import os
-import sys
-import unittest
-from copy import copy
-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)
-from distutils import util # used to patch _environ_checked
-from distutils.sysconfig import get_config_vars
-from distutils import sysconfig
-from distutils.tests import support
-import _osx_support
-
-class UtilTestCase(support.EnvironGuard, unittest.TestCase):
-
- def setUp(self):
- super(UtilTestCase, self).setUp()
- # saving the environment
- self.name = os.name
- self.platform = sys.platform
- self.version = sys.version
- self.sep = os.sep
- self.join = os.path.join
- self.isabs = os.path.isabs
- self.splitdrive = os.path.splitdrive
- self._config_vars = copy(sysconfig._config_vars)
-
- # patching os.uname
- if hasattr(os, 'uname'):
- self.uname = os.uname
- self._uname = os.uname()
- else:
- self.uname = None
- self._uname = None
-
- os.uname = self._get_uname
-
- def tearDown(self):
- # getting back the environment
- os.name = self.name
- sys.platform = self.platform
- sys.version = self.version
- os.sep = self.sep
- os.path.join = self.join
- os.path.isabs = self.isabs
- os.path.splitdrive = self.splitdrive
- if self.uname is not None:
- os.uname = self.uname
- else:
- del os.uname
- sysconfig._config_vars = copy(self._config_vars)
- super(UtilTestCase, self).tearDown()
-
- def _set_uname(self, uname):
- self._uname = uname
-
- def _get_uname(self):
- return self._uname
-
- def test_get_platform(self):
-
- # windows XP, 32bits
- os.name = 'nt'
- sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
- '[MSC v.1310 32 bit (Intel)]')
- sys.platform = 'win32'
- self.assertEqual(get_platform(), 'win32')
-
- # windows XP, amd64
- os.name = 'nt'
- sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
- '[MSC v.1310 32 bit (Amd64)]')
- sys.platform = 'win32'
- self.assertEqual(get_platform(), 'win-amd64')
-
- # macbook
- os.name = 'posix'
- sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
- '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
- sys.platform = 'darwin'
- self._set_uname(('Darwin', 'macziade', '8.11.1',
- ('Darwin Kernel Version 8.11.1: '
- 'Wed Oct 10 18:23:28 PDT 2007; '
- 'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
-
- get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
- '-fwrapv -O3 -Wall -Wstrict-prototypes')
-
- cursize = sys.maxsize
- sys.maxsize = (2 ** 31)-1
- try:
- self.assertEqual(get_platform(), 'macosx-10.3-i386')
- finally:
- sys.maxsize = cursize
-
- # macbook with fat binaries (fat, universal or fat64)
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
- get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
- '/Developer/SDKs/MacOSX10.4u.sdk '
- '-fno-strict-aliasing -fno-common '
- '-dynamic -DNDEBUG -g -O3')
-
- self.assertEqual(get_platform(), 'macosx-10.4-fat')
-
- _osx_support._remove_original_values(get_config_vars())
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.1'
- self.assertEqual(get_platform(), 'macosx-10.4-fat')
-
-
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
- '/Developer/SDKs/MacOSX10.4u.sdk '
- '-fno-strict-aliasing -fno-common '
- '-dynamic -DNDEBUG -g -O3')
-
- self.assertEqual(get_platform(), 'macosx-10.4-intel')
-
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
- '/Developer/SDKs/MacOSX10.4u.sdk '
- '-fno-strict-aliasing -fno-common '
- '-dynamic -DNDEBUG -g -O3')
- self.assertEqual(get_platform(), 'macosx-10.4-fat3')
-
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
- '/Developer/SDKs/MacOSX10.4u.sdk '
- '-fno-strict-aliasing -fno-common '
- '-dynamic -DNDEBUG -g -O3')
- self.assertEqual(get_platform(), 'macosx-10.4-universal')
-
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
- '/Developer/SDKs/MacOSX10.4u.sdk '
- '-fno-strict-aliasing -fno-common '
- '-dynamic -DNDEBUG -g -O3')
-
- self.assertEqual(get_platform(), 'macosx-10.4-fat64')
-
- for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
- _osx_support._remove_original_values(get_config_vars())
- get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
- '/Developer/SDKs/MacOSX10.4u.sdk '
- '-fno-strict-aliasing -fno-common '
- '-dynamic -DNDEBUG -g -O3'%(arch,))
-
- self.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch,))
-
-
- # linux debian sarge
- os.name = 'posix'
- sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) '
- '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]')
- sys.platform = 'linux2'
- self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7',
- '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
-
- self.assertEqual(get_platform(), 'linux-i686')
-
- # XXX more platforms to tests here
-
- 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')
-
- # 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)
-
- 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')
-
- # 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')
-
- # BugsBunny os (it's a great os)
- os.name = 'BugsBunny'
- self.assertRaises(DistutilsPlatformError,
- change_root, 'c:\\root', 'its\\here')
-
- # XXX platforms to be covered: mac
-
- def test_check_environ(self):
- util._environ_checked = 0
- os.environ.pop('HOME', None)
-
- check_environ()
-
- self.assertEqual(os.environ['PLAT'], get_platform())
- self.assertEqual(util._environ_checked, 1)
-
- @unittest.skipUnless(os.name == 'posix', 'specific to posix')
- def test_check_environ_getpwuid(self):
- util._environ_checked = 0
- os.environ.pop('HOME', None)
-
- import pwd
-
- # only set pw_dir field, other fields are not used
- 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')
-
- util._environ_checked = 0
- os.environ.pop('HOME', None)
-
- # bpo-10496: Catch pwd.getpwuid() error
- with mock.patch.object(pwd, 'getpwuid', side_effect=KeyError):
- check_environ()
- self.assertNotIn('HOME', os.environ)
-
- def test_split_quoted(self):
- 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')
- no = ('n', 'no', 'f', 'false', 'off', '0', 'Off', 'No', 'N')
-
- for y in yes:
- self.assertTrue(strtobool(y))
-
- for n in no:
- self.assertFalse(strtobool(n))
-
- 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*' '}
- self.assertEqual(res, wanted)
-
- def test_dont_write_bytecode(self):
- # makes sure byte_compile raise a DistutilsError
- # if sys.dont_write_bytecode is True
- old_dont_write_bytecode = sys.dont_write_bytecode
- sys.dont_write_bytecode = True
- try:
- self.assertRaises(DistutilsByteCompileError, byte_compile, [])
- finally:
- sys.dont_write_bytecode = old_dont_write_bytecode
-
- def test_grok_environment_error(self):
- # test obsolete function to ensure backward compat (#4931)
- exc = IOError("Unable to find batch file")
- msg = grok_environment_error(exc)
- self.assertEqual(msg, "error: Unable to find batch file")
-
-
-def test_suite():
- return unittest.makeSuite(UtilTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_version.py b/tests/test_version.py
deleted file mode 100644
index 8671cd2f..00000000
--- a/tests/test_version.py
+++ /dev/null
@@ -1,87 +0,0 @@
-"""Tests for distutils.version."""
-import unittest
-from distutils.version import LooseVersion
-from distutils.version import StrictVersion
-from test.support import run_unittest
-
-class VersionTestCase(unittest.TestCase):
-
- def test_prerelease(self):
- version = StrictVersion('1.2.3a1')
- self.assertEqual(version.version, (1, 2, 3))
- self.assertEqual(version.prerelease, ('a', 1))
- self.assertEqual(str(version), '1.2.3a1')
-
- version = StrictVersion('1.2.0')
- 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))
-
- for v1, v2, wanted in versions:
- try:
- res = StrictVersion(v1)._cmp(StrictVersion(v2))
- except ValueError:
- 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))
- res = StrictVersion(v1)._cmp(v2)
- 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))
-
-
- 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))
-
-
- 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))
- res = LooseVersion(v1)._cmp(v2)
- 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))
-
-def test_suite():
- return unittest.makeSuite(VersionTestCase)
-
-if __name__ == "__main__":
- run_unittest(test_suite())
diff --git a/tests/test_versionpredicate.py b/tests/test_versionpredicate.py
deleted file mode 100644
index 28ae09dc..00000000
--- a/tests/test_versionpredicate.py
+++ /dev/null
@@ -1,13 +0,0 @@
-"""Tests harness for distutils.versionpredicate.
-
-"""
-
-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())