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

« back to all changes in this revision

Viewing changes to Lib/distutils/tests/test_install.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
"""Tests for distutils.command.install."""
2
2
 
3
3
import os
4
 
import os.path
5
4
import sys
6
5
import unittest
7
6
import site
8
7
 
9
8
from test.support import captured_stdout, run_unittest
10
9
 
 
10
from distutils import sysconfig
11
11
from distutils.command.install import install
12
12
from distutils.command import install as install_module
 
13
from distutils.command.build_ext import build_ext
13
14
from distutils.command.install import INSTALL_SCHEMES
14
15
from distutils.core import Distribution
15
16
from distutils.errors import DistutilsOptionError
 
17
from distutils.extension import Extension
16
18
 
17
19
from distutils.tests import support
18
20
 
 
21
 
 
22
def _make_ext_name(modname):
 
23
    if os.name == 'nt':
 
24
        if sys.executable.endswith('_d.exe'):
 
25
            modname += '_d'
 
26
    return modname + sysconfig.get_config_var('SO')
 
27
 
 
28
 
19
29
class InstallTestCase(support.TempdirManager,
20
30
                      support.EnvironGuard,
21
31
                      support.LoggingSilencer,
167
177
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)
168
178
 
169
179
    def test_record(self):
170
 
 
171
 
        install_dir = self.mkdtemp()
172
 
        pkgdir, dist = self.create_dist()
173
 
 
174
 
        dist = Distribution()
175
 
        cmd = install(dist)
176
 
        dist.command_obj['install'] = cmd
177
 
        cmd.root = install_dir
178
 
        cmd.record = os.path.join(pkgdir, 'RECORD')
179
 
        cmd.ensure_finalized()
180
 
 
181
 
        cmd.run()
182
 
 
183
 
        # let's check the RECORD file was created with one
184
 
        # line (the egg info file)
185
 
        f = open(cmd.record)
186
 
        try:
187
 
            self.assertEqual(len(f.readlines()), 1)
188
 
        finally:
189
 
            f.close()
 
180
        install_dir = self.mkdtemp()
 
181
        project_dir, dist = self.create_dist(scripts=['hello'])
 
182
        self.addCleanup(os.chdir, os.getcwd())
 
183
        os.chdir(project_dir)
 
184
        self.write_file('hello', "print('o hai')")
 
185
 
 
186
        cmd = install(dist)
 
187
        dist.command_obj['install'] = cmd
 
188
        cmd.root = install_dir
 
189
        cmd.record = os.path.join(project_dir, 'RECORD')
 
190
        cmd.ensure_finalized()
 
191
        cmd.run()
 
192
 
 
193
        f = open(cmd.record)
 
194
        try:
 
195
            content = f.read()
 
196
        finally:
 
197
            f.close()
 
198
 
 
199
        found = [os.path.basename(line) for line in content.splitlines()]
 
200
        expected = ['hello',
 
201
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
 
202
        self.assertEqual(found, expected)
 
203
 
 
204
    def test_record_extensions(self):
 
205
        install_dir = self.mkdtemp()
 
206
        project_dir, dist = self.create_dist(ext_modules=[
 
207
            Extension('xx', ['xxmodule.c'])])
 
208
        self.addCleanup(os.chdir, os.getcwd())
 
209
        os.chdir(project_dir)
 
210
        support.copy_xxmodule_c(project_dir)
 
211
 
 
212
        buildextcmd = build_ext(dist)
 
213
        support.fixup_build_ext(buildextcmd)
 
214
        buildextcmd.ensure_finalized()
 
215
 
 
216
        cmd = install(dist)
 
217
        dist.command_obj['install'] = cmd
 
218
        dist.command_obj['build_ext'] = buildextcmd
 
219
        cmd.root = install_dir
 
220
        cmd.record = os.path.join(project_dir, 'RECORD')
 
221
        cmd.ensure_finalized()
 
222
        cmd.run()
 
223
 
 
224
        f = open(cmd.record)
 
225
        try:
 
226
            content = f.read()
 
227
        finally:
 
228
            f.close()
 
229
 
 
230
        found = [os.path.basename(line) for line in content.splitlines()]
 
231
        expected = [_make_ext_name('xx'),
 
232
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
 
233
        self.assertEqual(found, expected)
190
234
 
191
235
    def test_debug_mode(self):
192
236
        # this covers the code called when DEBUG is set
193
237
        old_logs_len = len(self.logs)
194
238
        install_module.DEBUG = True
195
239
        try:
196
 
            with captured_stdout() as stdout:
 
240
            with captured_stdout():
197
241
                self.test_record()
198
242
        finally:
199
243
            install_module.DEBUG = False