~ubuntu-branches/ubuntu/raring/python3.2/raring

« back to all changes in this revision

Viewing changes to Lib/distutils/tests/test_build_ext.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-09-05 22:01:13 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: package-import@ubuntu.com-20110905220113-gmku3knwah89ojat
Tags: 3.2.2-0ubuntu1
* Python 3.2.2 release.
* Search headers in /usr/include/ncursesw for the curses/panel extensions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import sys
2
2
import os
3
 
import shutil
4
3
from io import StringIO
5
4
import textwrap
6
5
 
7
6
from distutils.core import Distribution
8
7
from distutils.command.build_ext import build_ext
9
8
from distutils import sysconfig
10
 
from distutils.tests.support import TempdirManager
11
 
from distutils.tests.support import LoggingSilencer
 
9
from distutils.tests.support import (TempdirManager, LoggingSilencer,
 
10
                                     copy_xxmodule_c, fixup_build_ext)
12
11
from distutils.extension import Extension
13
12
from distutils.errors import (
14
13
    CompileError, DistutilsPlatformError, DistutilsSetupError,
16
15
 
17
16
import unittest
18
17
from test import support
19
 
from test.support import run_unittest
20
18
 
21
19
# http://bugs.python.org/issue4373
22
20
# Don't load the xx module more than once.
23
21
ALREADY_TESTED = False
24
22
 
25
 
def _get_source_filename():
26
 
    # use installed copy if available
27
 
    tests_f = os.path.join(os.path.dirname(__file__), 'xxmodule.c')
28
 
    if os.path.exists(tests_f):
29
 
        return tests_f
30
 
    # otherwise try using copy from build directory
31
 
    srcdir = sysconfig.get_config_var('srcdir')
32
 
    return os.path.join(srcdir, 'Modules', 'xxmodule.c')
33
23
 
34
24
class BuildExtTestCase(TempdirManager,
35
25
                       LoggingSilencer,
41
31
        self.tmp_dir = self.mkdtemp()
42
32
        self.sys_path = sys.path, sys.path[:]
43
33
        sys.path.append(self.tmp_dir)
44
 
        filename = _get_source_filename()
45
 
        if os.path.exists(filename):
46
 
            shutil.copy(filename, self.tmp_dir)
47
34
        if sys.version > "2.6":
48
35
            import site
49
36
            self.old_user_base = site.USER_BASE
51
38
            from distutils.command import build_ext
52
39
            build_ext.USER_BASE = site.USER_BASE
53
40
 
54
 
    def _fixup_command(self, cmd):
55
 
        # When Python was build with --enable-shared, -L. is not good enough
56
 
        # to find the libpython<blah>.so.  This is because regrtest runs it
57
 
        # under a tempdir, not in the top level where the .so lives.  By the
58
 
        # time we've gotten here, Python's already been chdir'd to the
59
 
        # tempdir.
60
 
        #
61
 
        # To further add to the fun, we can't just add library_dirs to the
62
 
        # Extension() instance because that doesn't get plumbed through to the
63
 
        # final compiler command.
64
 
        if (sysconfig.get_config_var('Py_ENABLE_SHARED') and
65
 
            not sys.platform.startswith('win')):
66
 
            runshared = sysconfig.get_config_var('RUNSHARED')
67
 
            if runshared is None:
68
 
                cmd.library_dirs = ['.']
69
 
            else:
70
 
                name, equals, value = runshared.partition('=')
71
 
                cmd.library_dirs = value.split(os.pathsep)
72
 
 
73
41
    def test_build_ext(self):
74
42
        global ALREADY_TESTED
 
43
        copy_xxmodule_c(self.tmp_dir)
75
44
        xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
76
 
        if not os.path.exists(xx_c):
77
 
            return
78
45
        xx_ext = Extension('xx', [xx_c])
79
46
        dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
80
47
        dist.package_dir = self.tmp_dir
81
48
        cmd = build_ext(dist)
82
 
        self._fixup_command(cmd)
83
 
        if os.name == "nt":
84
 
            # On Windows, we must build a debug version iff running
85
 
            # a debug build of Python
86
 
            cmd.debug = sys.executable.endswith("_d.exe")
 
49
        fixup_build_ext(cmd)
87
50
        cmd.build_lib = self.tmp_dir
88
51
        cmd.build_temp = self.tmp_dir
89
52
 
176
139
 
177
140
        # see if include_dirs and library_dirs
178
141
        # were set
179
 
        self.assertTrue(lib in cmd.library_dirs)
180
 
        self.assertTrue(lib in cmd.rpath)
181
 
        self.assertTrue(incl in cmd.include_dirs)
 
142
        self.assertIn(lib, cmd.library_dirs)
 
143
        self.assertIn(lib, cmd.rpath)
 
144
        self.assertIn(incl, cmd.include_dirs)
182
145
 
183
146
    def test_optional_extension(self):
184
147
 
334
297
        dist = Distribution({'name': 'xx',
335
298
                             'ext_modules': [ext]})
336
299
        cmd = build_ext(dist)
337
 
        self._fixup_command(cmd)
 
300
        fixup_build_ext(cmd)
338
301
        cmd.ensure_finalized()
339
302
        self.assertEqual(len(cmd.get_outputs()), 1)
340
303
 
341
 
        if os.name == "nt":
342
 
            cmd.debug = sys.executable.endswith("_d.exe")
343
 
 
344
304
        cmd.build_lib = os.path.join(self.tmp_dir, 'build')
345
305
        cmd.build_temp = os.path.join(self.tmp_dir, 'tempt')
346
306
 
518
478
 
519
479
 
520
480
def test_suite():
521
 
    src = _get_source_filename()
522
 
    if not os.path.exists(src):
523
 
        if support.verbose:
524
 
            print('test_build_ext: Cannot find source code (test'
525
 
                  ' must run in python build dir)')
526
 
        return unittest.TestSuite()
527
 
    else: return unittest.makeSuite(BuildExtTestCase)
 
481
    return unittest.makeSuite(BuildExtTestCase)
528
482
 
529
483
if __name__ == '__main__':
530
484
    support.run_unittest(test_suite())