reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py
index 45c9441..e258d2e 100644
--- a/Lib/distutils/tests/support.py
+++ b/Lib/distutils/tests/support.py
@@ -3,19 +3,11 @@
import shutil
import tempfile
from copy import deepcopy
-import warnings
from distutils import log
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
from distutils.core import Distribution
-def capture_warnings(func):
- def _capture_warnings(*args, **kw):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- return func(*args, **kw)
- return _capture_warnings
-
class LoggingSilencer(object):
def setUp(self):
@@ -63,8 +55,6 @@
super().tearDown()
while self.tempdirs:
d = self.tempdirs.pop()
- if not os.path.exists(d):
- continue
shutil.rmtree(d, os.name in ('nt', 'cygwin'))
def mkdtemp(self):
diff --git a/Lib/distutils/tests/test_archive_util.py b/Lib/distutils/tests/test_archive_util.py
index 682f19a..c6e08cb 100644
--- a/Lib/distutils/tests/test_archive_util.py
+++ b/Lib/distutils/tests/test_archive_util.py
@@ -15,30 +15,15 @@
from test.support import check_warnings
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')
-# some tests will fail if zlib is not available
-try:
- import zlib
-except ImportError:
- zlib = None
-
-
class ArchiveUtilTestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
- @unittest.skipUnless(zlib, "requires zlib")
def test_make_tarball(self):
# creating something to tar
tmpdir = self.mkdtemp()
@@ -49,7 +34,7 @@
tmpdir2 = self.mkdtemp()
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
- "source and target should be on same drive")
+ "Source and target should be on same drive")
base_name = os.path.join(tmpdir2, 'archive')
@@ -99,7 +84,6 @@
base_name = os.path.join(tmpdir2, 'archive')
return tmpdir, tmpdir2, base_name
- @unittest.skipUnless(zlib, "Requires zlib")
@unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
'Need the tar command to run')
def test_tarfile_vs_tar(self):
@@ -185,7 +169,6 @@
self.assertTrue(not os.path.exists(tarball))
self.assertEquals(len(w.warnings), 1)
- @unittest.skipUnless(zlib, "Requires zlib")
@unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
def test_make_zipfile(self):
# creating something to tar
@@ -210,59 +193,6 @@
base_name = os.path.join(tmpdir, 'archive')
self.assertRaises(ValueError, make_archive, base_name, 'xxx')
- @unittest.skipUnless(zlib, "Requires zlib")
- 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, root_dir, base_name = self._create_files()
- 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, "Requires zlib")
- @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
- def test_tarfile_root_owner(self):
- tmpdir, tmpdir2, base_name = self._create_files()
- 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.assertEquals(member.uid, 0)
- self.assertEquals(member.gid, 0)
- finally:
- archive.close()
-
def test_make_archive_cwd(self):
current_dir = os.getcwd()
def _breaks(*args, **kw):
diff --git a/Lib/distutils/tests/test_bdist.py b/Lib/distutils/tests/test_bdist.py
index 29dcc7c..f2849a9 100644
--- a/Lib/distutils/tests/test_bdist.py
+++ b/Lib/distutils/tests/test_bdist.py
@@ -5,8 +5,6 @@
import tempfile
import shutil
-from test.support import run_unittest
-
from distutils.core import Distribution
from distutils.command.bdist import bdist
from distutils.tests import support
@@ -42,4 +40,4 @@
return unittest.makeSuite(BuildTestCase)
if __name__ == '__main__':
- run_unittest(test_suite())
+ test_support.run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_bdist_dumb.py b/Lib/distutils/tests/test_bdist_dumb.py
index 746144b..5e76809 100644
--- a/Lib/distutils/tests/test_bdist_dumb.py
+++ b/Lib/distutils/tests/test_bdist_dumb.py
@@ -4,15 +4,6 @@
import sys
import os
-# zlib is not used here, but if it's not available
-# test_simple_built will fail
-try:
- import zlib
-except ImportError:
- zlib = None
-
-from test.support import run_unittest
-
from distutils.core import Distribution
from distutils.command.bdist_dumb import bdist_dumb
from distutils.tests import support
@@ -42,7 +33,6 @@
sys.argv[:] = self.old_sys_argv[1]
super(BuildDumbTestCase, self).tearDown()
- @unittest.skipUnless(zlib, "requires zlib")
def test_simple_built(self):
# let's create a simple package
@@ -83,23 +73,8 @@
# now let's check what we have in the zip file
# XXX to be done
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- os.chdir(pkg_dir)
- cmd = bdist_dumb(dist)
- self.assertEquals(cmd.bdist_dir, None)
- cmd.finalize_options()
-
- # bdist_dir is initialized to bdist_base/dumb if not set
- base = cmd.get_finalized_command('bdist').bdist_base
- self.assertEquals(cmd.bdist_dir, os.path.join(base, 'dumb'))
-
- # the format is set to a default value depending on the os.name
- default = cmd.default_format[os.name]
- self.assertEquals(cmd.format, default)
-
def test_suite():
return unittest.makeSuite(BuildDumbTestCase)
if __name__ == '__main__':
- run_unittest(test_suite())
+ test_support.run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_bdist_rpm.py b/Lib/distutils/tests/test_bdist_rpm.py
index 1014e54..2aa257f 100644
--- a/Lib/distutils/tests/test_bdist_rpm.py
+++ b/Lib/distutils/tests/test_bdist_rpm.py
@@ -6,8 +6,6 @@
import tempfile
import shutil
-from test.support import run_unittest
-
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
from distutils.tests import support
@@ -124,4 +122,4 @@
return unittest.makeSuite(BuildRpmTestCase)
if __name__ == '__main__':
- run_unittest(test_suite())
+ test_support.run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_bdist_wininst.py b/Lib/distutils/tests/test_bdist_wininst.py
index ffe4135..9b1ba6d 100644
--- a/Lib/distutils/tests/test_bdist_wininst.py
+++ b/Lib/distutils/tests/test_bdist_wininst.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.bdist_wininst."""
import unittest
-from test.support import run_unittest
-
from distutils.command.bdist_wininst import bdist_wininst
from distutils.tests import support
@@ -29,4 +27,4 @@
return unittest.makeSuite(BuildWinInstTestCase)
if __name__ == '__main__':
- run_unittest(test_suite())
+ test_support.run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_build_clib.py b/Lib/distutils/tests/test_build_clib.py
index 145eff5..536cd67 100644
--- a/Lib/distutils/tests/test_build_clib.py
+++ b/Lib/distutils/tests/test_build_clib.py
@@ -120,7 +120,8 @@
# before we run the command, we want to make sure
# all commands are present on the system
# by creating a compiler and checking its executables
- from distutils.ccompiler import new_compiler, customize_compiler
+ from distutils.ccompiler import new_compiler
+ from distutils.sysconfig import customize_compiler
compiler = new_compiler()
customize_compiler(compiler)
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index e41a824..b7cdc20 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -3,13 +3,10 @@
import tempfile
import shutil
from io import StringIO
-import warnings
-from test.support import check_warnings
-from test.support import captured_stdout
from distutils.core import Extension, Distribution
from distutils.command.build_ext import build_ext
-import sysconfig
+from distutils import sysconfig
from distutils.tests.support import TempdirManager
from distutils.tests.support import LoggingSilencer
from distutils.extension import Extension
@@ -25,23 +22,19 @@
def _get_source_filename():
srcdir = sysconfig.get_config_var('srcdir')
- if srcdir is None:
- return os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
return os.path.join(srcdir, 'Modules', 'xxmodule.c')
-_XX_MODULE_PATH = _get_source_filename()
-
-class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase):
-
+class BuildExtTestCase(TempdirManager,
+ LoggingSilencer,
+ unittest.TestCase):
def setUp(self):
# Create a simple test environment
# Note that we're making changes to sys.path
super(BuildExtTestCase, self).setUp()
self.tmp_dir = self.mkdtemp()
- if os.path.exists(_XX_MODULE_PATH):
- self.sys_path = sys.path[:]
- sys.path.append(self.tmp_dir)
- shutil.copy(_XX_MODULE_PATH, self.tmp_dir)
+ self.sys_path = sys.path, sys.path[:]
+ sys.path.append(self.tmp_dir)
+ shutil.copy(_get_source_filename(), self.tmp_dir)
if sys.version > "2.6":
import site
self.old_user_base = site.USER_BASE
@@ -49,19 +42,6 @@
from distutils.command import build_ext
build_ext.USER_BASE = site.USER_BASE
- def tearDown(self):
- # Get everything back to normal
- if os.path.exists(_XX_MODULE_PATH):
- support.unload('xx')
- sys.path[:] = self.sys_path
- # XXX on Windows the test leaves a directory
- # with xx module in TEMP
- shutil.rmtree(self.tmp_dir, os.name == 'nt' or
- sys.platform == 'cygwin')
- super(BuildExtTestCase, self).tearDown()
-
- @unittest.skipIf(not os.path.exists(_XX_MODULE_PATH),
- 'xxmodule.c not found')
def test_build_ext(self):
global ALREADY_TESTED
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
@@ -104,23 +84,35 @@
self.assertTrue(isinstance(xx.Null(), xx.Null))
self.assertTrue(isinstance(xx.Str(), xx.Str))
+ def tearDown(self):
+ # Get everything back to normal
+ support.unload('xx')
+ sys.path = self.sys_path[0]
+ sys.path[:] = self.sys_path[1]
+ if sys.version > "2.6":
+ 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 test_solaris_enable_shared(self):
dist = Distribution({'name': 'xx'})
cmd = build_ext(dist)
old = sys.platform
sys.platform = 'sunos' # fooling finalize_options
- from sysconfig import _CONFIG_VARS
- old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
- _CONFIG_VARS['Py_ENABLE_SHARED'] = 1
+ 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']
+ del _config_vars['Py_ENABLE_SHARED']
else:
- _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
+ _config_vars['Py_ENABLE_SHARED'] = old_var
# make sure we get some library dirs under solaris
self.assertTrue(len(cmd.library_dirs) > 0)
@@ -182,10 +174,11 @@
cmd = build_ext(dist)
cmd.finalize_options()
- py_include = sysconfig.get_path('include')
+ from distutils import sysconfig
+ py_include = sysconfig.get_python_inc()
self.assertTrue(py_include in cmd.include_dirs)
- plat_py_include = sysconfig.get_path('platinclude')
+ plat_py_include = sysconfig.get_python_inc(plat_specific=1)
self.assertTrue(plat_py_include in cmd.include_dirs)
# make sure cmd.libraries is turned into a list
@@ -336,6 +329,7 @@
self.assertEquals(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))
@@ -404,26 +398,6 @@
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
self.assertEquals(wanted, path)
- def test_compiler_deprecation_warning(self):
- dist = Distribution()
- cmd = build_ext(dist)
-
- class MyCompiler(object):
- def do_something(self):
- pass
-
- with check_warnings() as w:
- warnings.simplefilter("always")
- cmd.compiler = MyCompiler()
- self.assertEquals(len(w.warnings), 1)
- cmd.compile = 'unix'
- self.assertEquals(len(w.warnings), 1)
- cmd.compiler = MyCompiler()
- cmd.compiler.do_something()
- # two more warnings genereated by the get
- # and the set
- self.assertEquals(len(w.warnings), 3)
-
def test_suite():
src = _get_source_filename()
if not os.path.exists(src):
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
index 61e213a..3e45f6e 100644
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -16,7 +16,7 @@
support.LoggingSilencer,
unittest.TestCase):
- def _setup_package_data(self):
+ def test_package_data(self):
sources = self.mkdtemp()
f = open(os.path.join(sources, "__init__.py"), "w")
f.write("# Pretend this is a package.")
@@ -52,18 +52,9 @@
self.assertEqual(len(cmd.get_outputs()), 3)
pkgdest = os.path.join(destination, "pkg")
files = os.listdir(pkgdest)
- return files
-
- def test_package_data(self):
- files = self._setup_package_data()
self.assertTrue("__init__.py" in files)
- self.assertTrue("README.txt" in files)
-
- @unittest.skipIf(sys.flags.optimize >= 2,
- "pyc files are not written with -O2 and above")
- def test_package_data_pyc(self):
- files = self._setup_package_data()
self.assertTrue("__init__.pyc" in files)
+ self.assertTrue("README.txt" in files)
def test_empty_package_dir (self):
# See SF 1668596/1720897.
diff --git a/Lib/distutils/tests/test_build_scripts.py b/Lib/distutils/tests/test_build_scripts.py
index 72e8915..b1d2d07 100644
--- a/Lib/distutils/tests/test_build_scripts.py
+++ b/Lib/distutils/tests/test_build_scripts.py
@@ -5,7 +5,7 @@
from distutils.command.build_scripts import build_scripts
from distutils.core import Distribution
-import sysconfig
+from distutils import sysconfig
from distutils.tests import support
@@ -91,12 +91,12 @@
# --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
+ sysconfig._config_vars['VERSION'] = 4
try:
cmd.run()
finally:
if old is not None:
- sysconfig._CONFIG_VARS['VERSION'] = old
+ sysconfig._config_vars['VERSION'] = old
built = os.listdir(target)
for name in expected:
diff --git a/Lib/distutils/tests/test_ccompiler.py b/Lib/distutils/tests/test_ccompiler.py
deleted file mode 100644
index 27b51a0..0000000
--- a/Lib/distutils/tests/test_ccompiler.py
+++ /dev/null
@@ -1,81 +0,0 @@
-"""Tests for distutils.ccompiler."""
-import os
-import unittest
-from test.support import captured_stdout
-
-from distutils.ccompiler import (gen_lib_options, CCompiler,
- get_default_compiler, customize_compiler)
-from distutils import debug
-from distutils.tests import support
-
-class FakeCompiler(object):
- def library_dir_option(self, dir):
- return "-L" + dir
-
- def runtime_library_dir_option(self, dir):
- return ["-cool", "-R" + dir]
-
- def find_library_file(self, dirs, lib, debug=0):
- return 'found'
-
- def library_option(self, lib):
- return "-l" + lib
-
-class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
-
- def test_gen_lib_options(self):
- compiler = FakeCompiler()
- libdirs = ['lib1', 'lib2']
- runlibdirs = ['runlib1']
- libs = [os.path.join('dir', 'name'), 'name2']
-
- opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)
- wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found',
- '-lname2']
- self.assertEquals(opts, wanted)
-
- def test_debug_print(self):
-
- class MyCCompiler(CCompiler):
- executables = {}
-
- compiler = MyCCompiler()
- with captured_stdout() as stdout:
- compiler.debug_print('xxx')
- stdout.seek(0)
- self.assertEquals(stdout.read(), '')
-
- debug.DEBUG = True
- try:
- with captured_stdout() as stdout:
- compiler.debug_print('xxx')
- stdout.seek(0)
- self.assertEquals(stdout.read(), 'xxx\n')
- finally:
- debug.DEBUG = False
-
- def test_customize_compiler(self):
-
- # not testing if default compiler is not unix
- if get_default_compiler() != 'unix':
- return
-
- os.environ['AR'] = 'my_ar'
- os.environ['ARFLAGS'] = '-arflags'
-
- # make sure AR gets caught
- class compiler:
- compiler_type = 'unix'
-
- def set_executables(self, **kw):
- self.exes = kw
-
- comp = compiler()
- customize_compiler(comp)
- self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
-
-def test_suite():
- return unittest.makeSuite(CCompilerTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/Lib/distutils/tests/test_cmd.py b/Lib/distutils/tests/test_cmd.py
index 728652e..55ae421 100644
--- a/Lib/distutils/tests/test_cmd.py
+++ b/Lib/distutils/tests/test_cmd.py
@@ -1,7 +1,7 @@
"""Tests for distutils.cmd."""
import unittest
import os
-from test.support import captured_stdout, run_unittest
+from test.support import captured_stdout
from distutils.cmd import Command
from distutils.dist import Distribution
@@ -124,4 +124,4 @@
return unittest.makeSuite(CommandTestCase)
if __name__ == '__main__':
- run_unittest(test_suite())
+ test_support.run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py
index 374f392..a57694d 100644
--- a/Lib/distutils/tests/test_cygwinccompiler.py
+++ b/Lib/distutils/tests/test_cygwinccompiler.py
@@ -2,21 +2,29 @@
import unittest
import sys
import os
+from io import BytesIO
import subprocess
-import warnings
-import sysconfig
-
-from test.support import check_warnings, run_unittest
-from test.support import captured_stdout
from distutils import cygwinccompiler
from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
CONFIG_H_OK, CONFIG_H_NOTOK,
CONFIG_H_UNCERTAIN, get_versions,
- get_msvcr, RE_VERSION)
-from distutils.util import get_compiler_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):
@@ -24,17 +32,32 @@
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
@@ -58,6 +81,40 @@
self.write_file(self.python_h, 'xxx __GNUC__ xxx')
self.assertEquals(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.assertEquals(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.assertEquals(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.assertEquals(res[0], None)
+
+ # same thing for ld
+ self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
+ res = get_versions()
+ self.assertEquals(str(res[1]), '2.17.50')
+ self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
+ res = get_versions()
+ self.assertEquals(res[1], None)
+
+ # and dllwrap
+ self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
+ res = get_versions()
+ self.assertEquals(str(res[2]), '2.17.50')
+ self._exes['dllwrap'] = b'Cheese Wrap'
+ res = get_versions()
+ self.assertEquals(res[2], None)
+
def test_get_msvcr(self):
# none
@@ -90,23 +147,8 @@
'[MSC v.1999 32 bits (Intel)]')
self.assertRaises(ValueError, get_msvcr)
-
- def test_get_version_deprecated(self):
- with check_warnings() as w:
- warnings.simplefilter("always")
- # make sure get_compiler_versions and get_versions
- # returns the same thing
- self.assertEquals(get_compiler_versions(), get_versions())
- # make sure using get_version() generated a warning
- self.assertEquals(len(w.warnings), 1)
- # make sure any usage of RE_VERSION will also
- # generate a warning, but till works
- version = RE_VERSION.search('1.2').group(1)
- self.assertEquals(version, '1.2')
- self.assertEquals(len(w.warnings), 2)
-
def test_suite():
return unittest.makeSuite(CygwinCCompilerTestCase)
if __name__ == '__main__':
- run_unittest(test_suite())
+ test_support.run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py
index 4f51c16..3b7637f 100644
--- a/Lib/distutils/tests/test_dist.py
+++ b/Lib/distutils/tests/test_dist.py
@@ -7,9 +7,8 @@
import warnings
import textwrap
-from distutils.dist import Distribution, fix_help_options, DistributionMetadata
+from distutils.dist import Distribution, fix_help_options
from distutils.cmd import Command
-import distutils.dist
from test.support import TESTFN, captured_stdout
from distutils.tests import support
@@ -38,8 +37,7 @@
return self._config_files
-class DistributionTestCase(support.TempdirManager,
- support.LoggingSilencer,
+class DistributionTestCase(support.LoggingSilencer,
support.EnvironGuard,
unittest.TestCase):
@@ -60,27 +58,6 @@
d.parse_command_line()
return d
- def test_debug_mode(self):
- with open(TESTFN, "w") as f:
- f.write("[global]")
- f.write("command_packages = foo.bar, splat")
-
- files = [TESTFN]
- sys.argv.append("build")
-
- with captured_stdout() as stdout:
- self.create_distribution(files)
- stdout.seek(0)
- self.assertEquals(stdout.read(), '')
- distutils.dist.DEBUG = True
- try:
- with captured_stdout() as stdout:
- self.create_distribution(files)
- stdout.seek(0)
- self.assertEquals(stdout.read(), '')
- finally:
- distutils.dist.DEBUG = False
-
def test_command_packages_unspecified(self):
sys.argv.append("build")
d = self.create_distribution()
@@ -182,35 +159,6 @@
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 = distutils.dist.Distribution()
- all_files = d.find_config_files()
-
- d = distutils.dist.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.assertEquals(len(all_files)-1, len(files))
-
class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
unittest.TestCase):
@@ -364,38 +312,11 @@
"version": "1.0",
"long_description": long_desc}
- dist = distutils.dist.Distribution(attrs)
+ dist = Distribution(attrs)
meta = self.format_metadata(dist)
meta = meta.replace('\n' + 8 * ' ', '\n')
self.assertTrue(long_desc in meta)
- 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.assertEquals(metadata.name, "package")
- self.assertEquals(metadata.version, "1.0")
- self.assertEquals(metadata.description, "xxx")
- self.assertEquals(metadata.download_url, 'http://example.com')
- self.assertEquals(metadata.keywords, ['one', 'two'])
- self.assertEquals(metadata.platforms, ['UNKNOWN'])
- self.assertEquals(metadata.obsoletes, None)
- self.assertEquals(metadata.requires, ['foo'])
-
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(DistributionTestCase))
diff --git a/Lib/distutils/tests/test_emxccompiler.py b/Lib/distutils/tests/test_emxccompiler.py
deleted file mode 100644
index 1360f82..0000000
--- a/Lib/distutils/tests/test_emxccompiler.py
+++ /dev/null
@@ -1,33 +0,0 @@
-"""Tests for distutils.emxccompiler."""
-import unittest
-import sys
-import os
-import warnings
-
-from test.support import check_warnings, run_unittest
-from test.support import captured_stdout
-
-from distutils.emxccompiler import get_versions
-from distutils.util import get_compiler_versions
-from distutils.tests import support
-
-class EmxCCompilerTestCase(support.TempdirManager,
- unittest.TestCase):
-
- def test_get_version_deprecated(self):
- with check_warnings() as w:
- warnings.simplefilter("always")
- # make sure get_compiler_versions and get_versions
- # returns the same gcc
- gcc, ld, dllwrap = get_compiler_versions()
- emx_gcc, emx_ld = get_versions()
- self.assertEquals(gcc, emx_gcc)
-
- # make sure using get_version() generated a warning
- self.assertEquals(len(w.warnings), 1)
-
-def test_suite():
- return unittest.makeSuite(EmxCCompilerTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/Lib/distutils/tests/test_extension.py b/Lib/distutils/tests/test_extension.py
index 857284d..1ee3058 100755
--- a/Lib/distutils/tests/test_extension.py
+++ b/Lib/distutils/tests/test_extension.py
@@ -1,16 +1,13 @@
"""Tests for distutils.extension."""
-import os
-import sys
import unittest
+import os
import warnings
from test.support import check_warnings
from distutils.extension import read_setup_file, Extension
-from distutils.tests.support import capture_warnings
class ExtensionTestCase(unittest.TestCase):
- @capture_warnings
def test_read_setup_file(self):
# trying to read a Setup file
# (sample extracted from the PyGame project)
@@ -33,22 +30,16 @@
self.assertEquals(names, wanted)
- @unittest.skipIf(sys.flags.optimize >= 2,
- "Assertions are omitted with -O2 and above")
- def test_extension_init_assertions(self):
- # The first argument, which is the name, must be a string.
+ 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.assertEquals(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])
-
- def test_extension_init(self):
- ext = Extension('name', [])
- self.assertEquals(ext.name, 'name')
-
-
ext = Extension('name', ['file1', 'file2'])
self.assertEquals(ext.sources, ['file1', 'file2'])
diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py
index 99b421f..fac4a5d 100644
--- a/Lib/distutils/tests/test_file_util.py
+++ b/Lib/distutils/tests/test_file_util.py
@@ -3,7 +3,7 @@
import os
import shutil
-from distutils.file_util import move_file, write_file, copy_file
+from distutils.file_util import move_file
from distutils import log
from distutils.tests import support
@@ -55,21 +55,6 @@
wanted = ['moving %s -> %s' % (self.source, self.target_dir)]
self.assertEquals(self._logs, wanted)
- def test_write_file(self):
- lines = ['a', 'b', 'c']
- dir = self.mkdtemp()
- foo = os.path.join(dir, 'foo')
- write_file(foo, lines)
- content = [line.strip() for line in open(foo).readlines()]
- self.assertEquals(content, lines)
-
- def test_copy_file(self):
- src_dir = self.mkdtemp()
- foo = os.path.join(src_dir, 'foo')
- write_file(foo, 'content')
- dst_dir = self.mkdtemp()
- copy_file(foo, dst_dir)
- self.assertTrue(os.path.exists(os.path.join(dst_dir, 'foo')))
def test_suite():
return unittest.makeSuite(FileUtilTestCase)
diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py
index d98325a..331180d 100644
--- a/Lib/distutils/tests/test_filelist.py
+++ b/Lib/distutils/tests/test_filelist.py
@@ -1,25 +1,10 @@
"""Tests for distutils.filelist."""
-from os.path import join
import unittest
-from test.support import captured_stdout
from distutils.filelist import glob_to_re, FileList
+from test.support import captured_stdout
from distutils import debug
-MANIFEST_IN = """\
-include ok
-include xo
-exclude xo
-include foo.tmp
-global-include *.x
-global-include *.txt
-global-exclude *.tmp
-recursive-include f *.oo
-recursive-exclude global *.x
-graft dir
-prune dir3
-"""
-
class FileListTestCase(unittest.TestCase):
def test_glob_to_re(self):
@@ -34,34 +19,6 @@
self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
- def test_process_template_line(self):
- # testing all MANIFEST.in template patterns
- file_list = FileList()
-
- # simulated file list
- file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
- join('global', 'one.txt'),
- join('global', 'two.txt'),
- join('global', 'files.x'),
- join('global', 'here.tmp'),
- join('f', 'o', 'f.oo'),
- join('dir', 'graft-one'),
- join('dir', 'dir2', 'graft2'),
- join('dir3', 'ok'),
- join('dir3', 'sub', 'ok.txt')
- ]
-
- for line in MANIFEST_IN.split('\n'):
- if line.strip() == '':
- continue
- file_list.process_template_line(line)
-
- wanted = ['ok', 'four.txt', join('global', 'one.txt'),
- join('global', 'two.txt'), join('f', 'o', 'f.oo'),
- join('dir', 'graft-one'), join('dir', 'dir2', 'graft2')]
-
- self.assertEquals(file_list.files, wanted)
-
def test_debug_print(self):
file_list = FileList()
with captured_stdout() as stdout:
diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py
index 59e9080..76fa02a 100644
--- a/Lib/distutils/tests/test_install.py
+++ b/Lib/distutils/tests/test_install.py
@@ -5,14 +5,12 @@
import sys
import unittest
import site
-import sysconfig
-from sysconfig import (get_scheme_names, _CONFIG_VARS, _INSTALL_SCHEMES,
- get_config_var, get_path)
from test.support import captured_stdout
from distutils.command.install import install
from distutils.command import install as install_module
+from distutils.command.install import INSTALL_SCHEMES
from distutils.core import Distribution
from distutils.errors import DistutilsOptionError
@@ -38,23 +36,9 @@
build_lib=os.path.join(builddir, "lib"),
)
-
-
- posix_prefix = _INSTALL_SCHEMES['posix_prefix']
- old_posix_prefix = posix_prefix['platinclude']
- posix_prefix['platinclude'] = \
- '{platbase}/include/python{py_version_short}'
-
- posix_home = _INSTALL_SCHEMES['posix_home']
- old_posix_home = posix_home['platinclude']
- posix_home['platinclude'] = '{base}/include/python'
- try:
- cmd = install(dist)
- cmd.home = destination
- cmd.ensure_finalized()
- finally:
- posix_home['platinclude'] = old_posix_home
- posix_prefix['platinclude'] = old_posix_prefix
+ cmd = install(dist)
+ cmd.home = destination
+ cmd.ensure_finalized()
self.assertEqual(cmd.install_base, destination)
self.assertEqual(cmd.install_platbase, destination)
@@ -79,19 +63,18 @@
return
# preparing the environement for the test
- self.old_user_base = get_config_var('userbase')
- self.old_user_site = get_path('purelib', '%s_user' % os.name)
+ 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')
- _CONFIG_VARS['userbase'] = self.user_base
- scheme = _INSTALL_SCHEMES['%s_user' % os.name]
- scheme['purelib'] = self.user_site
+ 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):
- if path[0] == '~':
- path = os.path.normpath(self.tmpdir) + path[1:]
- return path
+ return self.tmpdir
self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser
@@ -99,17 +82,19 @@
# this is the actual test
self._test_user_site()
finally:
- _CONFIG_VARS['userbase'] = self.old_user_base
- scheme['purelib'] = self.old_user_site
+ 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
def _test_user_site(self):
- schemes = get_scheme_names()
- for key in ('nt_user', 'posix_user', 'os2_home'):
- self.assertTrue(key in schemes)
+ for key in ('nt_user', 'unix_user', 'os2_home'):
+ self.assertTrue(key in 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]
@@ -200,7 +185,7 @@
with open(cmd.record) as f:
self.assertEquals(len(f.readlines()), 1)
- def _test_debug_mode(self):
+ def test_debug_mode(self):
# this covers the code called when DEBUG is set
old_logs_len = len(self.logs)
install_module.DEBUG = True
diff --git a/Lib/distutils/tests/test_install_lib.py b/Lib/distutils/tests/test_install_lib.py
index 13d27ab..99a6d90 100644
--- a/Lib/distutils/tests/test_install_lib.py
+++ b/Lib/distutils/tests/test_install_lib.py
@@ -1,6 +1,6 @@
"""Tests for distutils.command.install_data."""
-import os
import sys
+import os
import unittest
from distutils.command.install_lib import install_lib
@@ -31,7 +31,9 @@
cmd.finalize_options()
self.assertEquals(cmd.optimize, 2)
- def _setup_byte_compile(self):
+ @unittest.skipUnless(not sys.dont_write_bytecode,
+ 'byte-compile not supported')
+ def test_byte_compile(self):
pkg_dir, dist = self.create_dist()
cmd = install_lib(dist)
cmd.compile = cmd.optimize = 1
@@ -39,15 +41,8 @@
f = os.path.join(pkg_dir, 'foo.py')
self.write_file(f, '# python file')
cmd.byte_compile([f])
- return pkg_dir
-
- @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile not enabled')
- def test_byte_compile(self):
- pkg_dir = self._setup_byte_compile()
- if sys.flags.optimize < 1:
- self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
- else:
- self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
+ self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
+ self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
def test_get_outputs(self):
pkg_dir, dist = self.create_dist()
diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py
index acda1b1..c03ad10 100644
--- a/Lib/distutils/tests/test_register.py
+++ b/Lib/distutils/tests/test_register.py
@@ -202,10 +202,10 @@
self.assertRaises(DistutilsSetupError, cmd.run)
# we don't test the reSt feature if docutils
- # is not installed or we our on py3k
+ # is not installed
try:
import docutils
- except Exception:
+ except ImportError:
return
# metadata are OK but long_description is broken
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
index 9a76eac..f95035d 100644
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -3,22 +3,6 @@
import unittest
import shutil
import zipfile
-import tarfile
-
-# zlib is not used here, but if it's not available
-# the tests that use zipfile may fail
-try:
- import zlib
-except ImportError:
- zlib = None
-
-try:
- import grp
- import pwd
- UID_GID_SUPPORT = True
-except ImportError:
- UID_GID_SUPPORT = False
-
from os.path import join
import sys
import tempfile
@@ -95,7 +79,6 @@
cmd.warn = _warn
return dist, cmd
- @unittest.skipUnless(zlib, "requires zlib")
def test_prune_file_list(self):
# this test creates a package with some vcs dirs in it
# and launch sdist to make sure they get pruned
@@ -137,7 +120,6 @@
# making sure everything has been pruned correctly
self.assertEquals(len(content), 4)
- @unittest.skipUnless(zlib, "requires zlib")
def test_make_distribution(self):
# check if tar and gzip are installed
@@ -174,7 +156,6 @@
self.assertEquals(result,
['fake-1.0.tar', 'fake-1.0.tar.gz'])
- @unittest.skipUnless(zlib, "requires zlib")
def test_add_defaults(self):
# http://bugs.python.org/issue2279
@@ -236,7 +217,6 @@
manifest = open(join(self.tmp_dir, 'MANIFEST')).read()
self.assertEquals(manifest, MANIFEST % {'sep': os.sep})
- @unittest.skipUnless(zlib, "requires zlib")
def test_metadata_check_option(self):
# testing the `medata-check` option
dist, cmd = self.get_cmd(metadata={})
@@ -296,57 +276,7 @@
cmd.formats = 'supazipa'
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
- @unittest.skipUnless(zlib, "requires zlib")
- @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
- def test_make_distribution_owner_group(self):
- # check if tar and gzip are installed
- if (find_executable('tar') is None or
- find_executable('gzip') is None):
- return
-
- # 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.assertEquals(member.uid, 0)
- self.assertEquals(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.assertEquals(member.uid, os.getuid())
- finally:
- archive.close()
-
- @unittest.skipUnless(zlib, "requires zlib")
def test_get_file_list(self):
# make sure MANIFEST is recalculated
dist, cmd = self.get_cmd()
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
index 9496950..edc755e 100644
--- a/Lib/distutils/tests/test_sysconfig.py
+++ b/Lib/distutils/tests/test_sysconfig.py
@@ -2,9 +2,9 @@
import os
import test
import unittest
-import shutil
from distutils import sysconfig
+from distutils.ccompiler import get_default_compiler
from distutils.tests import support
from test.support import TESTFN, run_unittest
@@ -26,7 +26,10 @@
elif os.path.isdir(TESTFN):
shutil.rmtree(TESTFN)
- @support.capture_warnings
+ 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):
lib_dir = sysconfig.get_python_lib()
# XXX doesn't work on Linux when Python was never installed before
@@ -34,11 +37,7 @@
# test for pythonxx.lib?
self.assertNotEqual(sysconfig.get_python_lib(),
sysconfig.get_python_lib(prefix=TESTFN))
- _sysconfig = __import__('sysconfig')
- res = sysconfig.get_python_lib(True, True)
- self.assertEquals(_sysconfig.get_path('platstdlib'), res)
- @support.capture_warnings
def test_get_python_inc(self):
inc_dir = sysconfig.get_python_inc()
# This is not much of a test. We make sure Python.h exists
@@ -48,7 +47,31 @@
python_h = os.path.join(inc_dir, "Python.h")
self.assertTrue(os.path.isfile(python_h), python_h)
- @support.capture_warnings
+ def test_get_config_vars(self):
+ cvars = sysconfig.get_config_vars()
+ self.assertTrue(isinstance(cvars, dict))
+ self.assertTrue(cvars)
+
+ def test_customize_compiler(self):
+
+ # not testing if default compiler is not unix
+ if get_default_compiler() != 'unix':
+ return
+
+ os.environ['AR'] = 'my_ar'
+ os.environ['ARFLAGS'] = '-arflags'
+
+ # make sure AR gets caught
+ class compiler:
+ compiler_type = 'unix'
+
+ def set_executables(self, **kw):
+ self.exes = kw
+
+ comp = compiler()
+ sysconfig.customize_compiler(comp)
+ self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
+
def test_parse_makefile_base(self):
self.makefile = TESTFN
fd = open(self.makefile, 'w')
diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py
index 6976dd5..3a41e6f 100644
--- a/Lib/distutils/tests/test_unixccompiler.py
+++ b/Lib/distutils/tests/test_unixccompiler.py
@@ -1,8 +1,8 @@
"""Tests for distutils.unixccompiler."""
import sys
import unittest
-import sysconfig
+from distutils import sysconfig
from distutils.unixccompiler import UnixCCompiler
class UnixCCompilerTestCase(unittest.TestCase):
@@ -114,14 +114,6 @@
sysconfig.get_config_var = gcv
self.assertEqual(self.cc.rpath_foo(), '-R/foo')
- # AIX C/C++ linker
- sys.platform = 'aix'
- def gcv(v):
- return 'xxx'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-blibpath:/foo')
-
-
def test_suite():
return unittest.makeSuite(UnixCCompilerTestCase)
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
index 979ab22..35e9700 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -2,8 +2,8 @@
import sys
import os
import unittest
+import http.client as httpclient
-from distutils.command import upload as upload_mod
from distutils.command.upload import upload
from distutils.core import Distribution
@@ -38,37 +38,48 @@
[server1]
username:me
"""
+class Response(object):
+ def __init__(self, status=200, reason='OK'):
+ self.status = status
+ self.reason = reason
-class FakeOpen(object):
+class FakeConnection(object):
- def __init__(self, url):
- self.url = url
- if not isinstance(url, str):
- self.req = url
- else:
- self.req = None
- self.msg = 'OK'
+ def __init__(self):
+ self.requests = []
+ self.headers = []
+ self.body = ''
- def getcode(self):
- return 200
+ def __call__(self, netloc):
+ return self
+ def connect(self):
+ pass
+ endheaders = connect
+
+ def putrequest(self, method, url):
+ self.requests.append((method, url))
+
+ def putheader(self, name, value):
+ self.headers.append((name, value))
+
+ def send(self, body):
+ self.body = body
+
+ def getresponse(self):
+ return Response()
class uploadTestCase(PyPIRCCommandTestCase):
def setUp(self):
super(uploadTestCase, self).setUp()
- self.old_open = upload_mod.urlopen
- upload_mod.urlopen = self._urlopen
- self.last_open = None
+ self.old_class = httpclient.HTTPConnection
+ self.conn = httpclient.HTTPConnection = FakeConnection()
def tearDown(self):
- upload_mod.urlopen = self.old_open
+ httpclient.HTTPConnection = self.old_class
super(uploadTestCase, self).tearDown()
- def _urlopen(self, url):
- self.last_open = FakeOpen(url)
- return self.last_open
-
def test_finalize_options(self):
# new format
@@ -113,15 +124,13 @@
cmd.run()
# what did we send ?
- headers = dict(self.last_open.req.headers)
+ headers = dict(self.conn.headers)
self.assertEquals(headers['Content-length'], '2087')
self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
- self.assertEquals(self.last_open.req.get_method(), 'POST')
- self.assertEquals(self.last_open.req.get_full_url(),
- 'http://pypi.python.org/pypi')
- self.assertTrue(b'xxx' in self.last_open.req.data)
- auth = self.last_open.req.headers['Authorization']
- self.assertFalse('\n' in auth)
+ self.assertFalse('\n' in headers['Authorization'])
+
+ self.assertEquals(self.conn.requests, [('POST', '/pypi')])
+ self.assert_((b'xxx') in self.conn.body)
def test_suite():
return unittest.makeSuite(uploadTestCase)
diff --git a/Lib/distutils/tests/test_util.py b/Lib/distutils/tests/test_util.py
index 896e1e0..0c732f8 100644
--- a/Lib/distutils/tests/test_util.py
+++ b/Lib/distutils/tests/test_util.py
@@ -3,33 +3,15 @@
import sys
import unittest
from copy import copy
-from io import BytesIO
-import subprocess
-from sysconfig import get_config_vars, get_platform
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
-from distutils.util import (convert_path, change_root,
+from distutils.util import (get_platform, convert_path, change_root,
check_environ, split_quoted, strtobool,
- rfc822_escape, get_compiler_versions,
- _find_exe_version, _MAC_OS_X_LD_VERSION,
- byte_compile)
-from distutils import util
+ rfc822_escape, byte_compile)
+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
-from distutils.version import LooseVersion
-
-class FakePopen(object):
- test_class = None
- def __init__(self, cmd, shell, stdout, stderr):
- self.cmd = cmd.split()[0]
- exes = self.test_class._exes
- if self.cmd not in exes:
- # we don't want to call the system, returning an empty
- # output so it doesn't match
- self.stdout = BytesIO()
- self.stderr = BytesIO()
- else:
- self.stdout = BytesIO(exes[self.cmd])
- self.stderr = BytesIO()
class UtilTestCase(support.EnvironGuard, unittest.TestCase):
@@ -43,7 +25,7 @@
self.join = os.path.join
self.isabs = os.path.isabs
self.splitdrive = os.path.splitdrive
- #self._config_vars = copy(sysconfig._config_vars)
+ self._config_vars = copy(sysconfig._config_vars)
# patching os.uname
if hasattr(os, 'uname'):
@@ -52,17 +34,8 @@
else:
self.uname = None
self._uname = None
- os.uname = self._get_uname
- # patching POpen
- self.old_find_executable = util.find_executable
- util.find_executable = self._find_executable
- self._exes = {}
- self.old_popen = subprocess.Popen
- self.old_stdout = sys.stdout
- self.old_stderr = sys.stderr
- FakePopen.test_class = self
- subprocess.Popen = FakePopen
+ os.uname = self._get_uname
def tearDown(self):
# getting back the environment
@@ -77,11 +50,7 @@
os.uname = self.uname
else:
del os.uname
- #sysconfig._config_vars = copy(self._config_vars)
- util.find_executable = self.old_find_executable
- subprocess.Popen = self.old_popen
- sys.old_stdout = self.old_stdout
- sys.old_stderr = self.old_stderr
+ sysconfig._config_vars = copy(self._config_vars)
super(UtilTestCase, self).tearDown()
def _set_uname(self, uname):
@@ -91,11 +60,103 @@
return self._uname
def test_get_platform(self):
- platform = util.get_platform()
- self.assertEquals(platform, get_platform())
- util.set_platform('MyOwnPlatform')
- self.assertEquals('MyOwnPlatform', util.get_platform())
- util.set_platform(platform)
+
+ # 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.assertEquals(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.assertEquals(get_platform(), 'win-amd64')
+
+ # windows XP, itanium
+ os.name = 'nt'
+ sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
+ '[MSC v.1310 32 bit (Itanium)]')
+ sys.platform = 'win32'
+ self.assertEquals(get_platform(), 'win-ia64')
+
+ # 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'))
+ os.environ['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.assertEquals(get_platform(), 'macosx-10.3-i386')
+ finally:
+ sys.maxsize = cursize
+
+ # macbook with fat binaries (fat, universal or fat64)
+ os.environ['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.assertEquals(get_platform(), 'macosx-10.4-fat')
+
+ 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.assertEquals(get_platform(), 'macosx-10.4-intel')
+
+ 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.assertEquals(get_platform(), 'macosx-10.4-fat3')
+
+ 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.assertEquals(get_platform(), 'macosx-10.4-universal')
+
+ 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.assertEquals(get_platform(), 'macosx-10.4-fat64')
+
+ for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
+ get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
+ '/Developer/SDKs/MacOSX10.4u.sdk '
+ '-fno-strict-aliasing -fno-common '
+ '-dynamic -DNDEBUG -g -O3'%(arch,))
+
+ self.assertEquals(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.assertEquals(get_platform(), 'linux-i686')
+
+ # XXX more platforms to tests here
def test_convert_path(self):
# linux/mac
@@ -199,70 +260,6 @@
'header%(8s)s') % {'8s': '\n'+8*' '}
self.assertEquals(res, wanted)
- def test_find_exe_version(self):
- # the ld version scheme under MAC OS is:
- # ^@(#)PROGRAM:ld PROJECT:ld64-VERSION
- #
- # where VERSION is a 2-digit number for major
- # revisions. For instance under Leopard, it's
- # currently 77
- #
- # Dots are used when branching is done.
- #
- # The SnowLeopard ld64 is currently 95.2.12
-
- for output, version in ((b'@(#)PROGRAM:ld PROJECT:ld64-77', '77'),
- (b'@(#)PROGRAM:ld PROJECT:ld64-95.2.12',
- '95.2.12')):
- result = _MAC_OS_X_LD_VERSION.search(output)
- self.assertEquals(result.group(1).decode(), version)
-
- def _find_executable(self, name):
- if name in self._exes:
- return name
- return None
-
- def test_get_compiler_versions(self):
- # get_versions calls distutils.spawn.find_executable on
- # 'gcc', 'ld' and 'dllwrap'
- self.assertEquals(get_compiler_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_compiler_versions()
- self.assertEquals(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_compiler_versions()
- self.assertEquals(res[0], None)
-
- # same thing for ld
- if sys.platform != 'darwin':
- self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
- res = get_compiler_versions()
- self.assertEquals(str(res[1]), '2.17.50')
- self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
- res = get_compiler_versions()
- self.assertEquals(res[1], None)
- else:
- self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
- res = get_compiler_versions()
- self.assertEquals(res[1], None)
- self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
- res = get_compiler_versions()
- self.assertEquals(str(res[1]), '77')
-
- # and dllwrap
- self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
- res = get_compiler_versions()
- self.assertEquals(str(res[2]), '2.17.50')
- self._exes['dllwrap'] = b'Cheese Wrap'
- res = get_compiler_versions()
- self.assertEquals(res[2], None)
-
def test_dont_write_bytecode(self):
# makes sure byte_compile raise a DistutilsError
# if sys.dont_write_bytecode is True