diff options
Diffstat (limited to 'Lib/distutils/tests')
-rw-r--r-- | Lib/distutils/tests/support.py | 8 | ||||
-rw-r--r-- | Lib/distutils/tests/test_build.py | 2 | ||||
-rw-r--r-- | Lib/distutils/tests/test_build_clib.py | 3 | ||||
-rw-r--r-- | Lib/distutils/tests/test_build_ext.py | 17 | ||||
-rw-r--r-- | Lib/distutils/tests/test_build_scripts.py | 6 | ||||
-rw-r--r-- | Lib/distutils/tests/test_ccompiler.py | 26 | ||||
-rw-r--r-- | Lib/distutils/tests/test_cygwinccompiler.py | 3 | ||||
-rwxr-xr-x | Lib/distutils/tests/test_extension.py | 2 | ||||
-rw-r--r-- | Lib/distutils/tests/test_install.py | 53 | ||||
-rw-r--r-- | Lib/distutils/tests/test_sysconfig.py | 36 | ||||
-rw-r--r-- | Lib/distutils/tests/test_unixccompiler.py | 2 | ||||
-rw-r--r-- | Lib/distutils/tests/test_util.py | 14 |
12 files changed, 94 insertions, 78 deletions
diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py index e258d2e..d60da85 100644 --- a/Lib/distutils/tests/support.py +++ b/Lib/distutils/tests/support.py @@ -3,11 +3,19 @@ import os 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): diff --git a/Lib/distutils/tests/test_build.py b/Lib/distutils/tests/test_build.py index 6bca27e..2418e16 100644 --- a/Lib/distutils/tests/test_build.py +++ b/Lib/distutils/tests/test_build.py @@ -5,7 +5,7 @@ import sys from distutils.command.build import build from distutils.tests import support -from distutils.util import get_platform +from sysconfig import get_platform class BuildTestCase(support.TempdirManager, support.LoggingSilencer, diff --git a/Lib/distutils/tests/test_build_clib.py b/Lib/distutils/tests/test_build_clib.py index 536cd67..145eff5 100644 --- a/Lib/distutils/tests/test_build_clib.py +++ b/Lib/distutils/tests/test_build_clib.py @@ -120,8 +120,7 @@ class BuildCLibTestCase(support.TempdirManager, # 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 - from distutils.sysconfig import customize_compiler + from distutils.ccompiler import new_compiler, 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 ebbb399..d097183 100644 --- a/Lib/distutils/tests/test_build_ext.py +++ b/Lib/distutils/tests/test_build_ext.py @@ -9,7 +9,7 @@ from test.support import captured_stdout from distutils.core import Extension, Distribution from distutils.command.build_ext import build_ext -from distutils import sysconfig +import sysconfig from distutils.tests.support import TempdirManager from distutils.tests.support import LoggingSilencer from distutils.extension import Extension @@ -105,17 +105,17 @@ class BuildExtTestCase(TempdirManager, 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 + from 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) @@ -177,11 +177,10 @@ class BuildExtTestCase(TempdirManager, cmd = build_ext(dist) cmd.finalize_options() - from distutils import sysconfig - py_include = sysconfig.get_python_inc() + py_include = sysconfig.get_path('include') self.assertTrue(py_include in cmd.include_dirs) - plat_py_include = sysconfig.get_python_inc(plat_specific=1) + plat_py_include = sysconfig.get_path('platinclude') self.assertTrue(plat_py_include in cmd.include_dirs) # make sure cmd.libraries is turned into a list diff --git a/Lib/distutils/tests/test_build_scripts.py b/Lib/distutils/tests/test_build_scripts.py index b1d2d07..72e8915 100644 --- a/Lib/distutils/tests/test_build_scripts.py +++ b/Lib/distutils/tests/test_build_scripts.py @@ -5,7 +5,7 @@ import unittest from distutils.command.build_scripts import build_scripts from distutils.core import Distribution -from distutils import sysconfig +import sysconfig from distutils.tests import support @@ -91,12 +91,12 @@ class BuildScriptsTestCase(support.TempdirManager, # --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 index 9db8d24..27b51a0 100644 --- a/Lib/distutils/tests/test_ccompiler.py +++ b/Lib/distutils/tests/test_ccompiler.py @@ -3,8 +3,10 @@ import os import unittest from test.support import captured_stdout -from distutils.ccompiler import gen_lib_options, CCompiler +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): @@ -19,7 +21,7 @@ class FakeCompiler(object): def library_option(self, lib): return "-l" + lib -class CCompilerTestCase(unittest.TestCase): +class CCompilerTestCase(support.EnvironGuard, unittest.TestCase): def test_gen_lib_options(self): compiler = FakeCompiler() @@ -52,6 +54,26 @@ class CCompilerTestCase(unittest.TestCase): 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) diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py index 98f0f08..4b95dfa 100644 --- a/Lib/distutils/tests/test_cygwinccompiler.py +++ b/Lib/distutils/tests/test_cygwinccompiler.py @@ -4,6 +4,7 @@ import sys import os import subprocess import warnings +import sysconfig from test.support import check_warnings from test.support import captured_stdout @@ -23,13 +24,11 @@ class CygwinCCompilerTestCase(support.TempdirManager, super(CygwinCCompilerTestCase, self).setUp() self.version = sys.version self.python_h = os.path.join(self.mkdtemp(), 'python.h') - from distutils import sysconfig self.old_get_config_h_filename = sysconfig.get_config_h_filename sysconfig.get_config_h_filename = self._get_config_h_filename def tearDown(self): sys.version = self.version - from distutils import sysconfig sysconfig.get_config_h_filename = self.old_get_config_h_filename super(CygwinCCompilerTestCase, self).tearDown() diff --git a/Lib/distutils/tests/test_extension.py b/Lib/distutils/tests/test_extension.py index 1ee3058..9d3cfe6 100755 --- a/Lib/distutils/tests/test_extension.py +++ b/Lib/distutils/tests/test_extension.py @@ -5,9 +5,11 @@ 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) diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py index 76fa02a..59e9080 100644 --- a/Lib/distutils/tests/test_install.py +++ b/Lib/distutils/tests/test_install.py @@ -5,12 +5,14 @@ import os.path 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 @@ -36,9 +38,23 @@ class InstallTestCase(support.TempdirManager, build_lib=os.path.join(builddir, "lib"), ) - cmd = install(dist) - cmd.home = destination - cmd.ensure_finalized() + + + 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 self.assertEqual(cmd.install_base, destination) self.assertEqual(cmd.install_platbase, destination) @@ -63,18 +79,19 @@ class InstallTestCase(support.TempdirManager, return # preparing the environement for the test - self.old_user_base = site.USER_BASE - self.old_user_site = site.USER_SITE + self.old_user_base = get_config_var('userbase') + self.old_user_site = get_path('purelib', '%s_user' % os.name) 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 + _CONFIG_VARS['userbase'] = self.user_base + scheme = _INSTALL_SCHEMES['%s_user' % os.name] + scheme['purelib'] = self.user_site def _expanduser(path): - return self.tmpdir + if path[0] == '~': + path = os.path.normpath(self.tmpdir) + path[1:] + return path self.old_expand = os.path.expanduser os.path.expanduser = _expanduser @@ -82,19 +99,17 @@ class InstallTestCase(support.TempdirManager, # this is the actual test self._test_user_site() finally: - 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 + _CONFIG_VARS['userbase'] = self.old_user_base + scheme['purelib'] = self.old_user_site os.path.expanduser = self.old_expand def _test_user_site(self): - for key in ('nt_user', 'unix_user', 'os2_home'): - self.assertTrue(key in INSTALL_SCHEMES) + schemes = get_scheme_names() + for key in ('nt_user', 'posix_user', 'os2_home'): + self.assertTrue(key in 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] @@ -185,7 +200,7 @@ class InstallTestCase(support.TempdirManager, 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_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py index edc755e..e7df803 100644 --- a/Lib/distutils/tests/test_sysconfig.py +++ b/Lib/distutils/tests/test_sysconfig.py @@ -4,7 +4,6 @@ import test 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 @@ -26,10 +25,7 @@ class SysconfigTestCase(support.EnvironGuard, 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) - + @support.capture_warnings def test_get_python_lib(self): lib_dir = sysconfig.get_python_lib() # XXX doesn't work on Linux when Python was never installed before @@ -37,7 +33,11 @@ class SysconfigTestCase(support.EnvironGuard, # 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 @@ -47,31 +47,7 @@ class SysconfigTestCase(support.EnvironGuard, python_h = os.path.join(inc_dir, "Python.h") self.assertTrue(os.path.isfile(python_h), python_h) - 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') - + @support.capture_warnings 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 008ae5d..6976dd5 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): diff --git a/Lib/distutils/tests/test_util.py b/Lib/distutils/tests/test_util.py index 8f8d4a1..ae6671d 100644 --- a/Lib/distutils/tests/test_util.py +++ b/Lib/distutils/tests/test_util.py @@ -6,15 +6,14 @@ 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 (get_platform, convert_path, change_root, +from distutils.util import (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 -from distutils.sysconfig import get_config_vars -from distutils import sysconfig from distutils.tests import support from distutils.version import LooseVersion @@ -44,7 +43,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): 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'): @@ -78,7 +77,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): os.uname = self.uname else: del os.uname - sysconfig._config_vars = copy(self._config_vars) + #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 @@ -91,7 +90,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): def _get_uname(self): return self._uname - def test_get_platform(self): + def _test_get_platform(self): # windows XP, 32bits os.name = 'nt' @@ -119,7 +118,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): 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; ' @@ -157,7 +155,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): finally: sys.maxsize = maxsize - # macbook with fat binaries (fat, universal or fat64) os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4' get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot ' @@ -201,7 +198,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): 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) ' |