diff options
Diffstat (limited to 'Lib/distutils/tests/test_build_ext.py')
-rw-r--r-- | Lib/distutils/tests/test_build_ext.py | 82 |
1 files changed, 28 insertions, 54 deletions
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 os 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 @@ ALREADY_TESTED = False 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 @@ class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase): 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 @@ class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase): 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 @@ class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase): 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 @@ class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase): 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 @@ class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase): 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): |