~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""Tests for distutils.command.install_data."""
2
2
import sys
3
3
import os
 
4
import imp
4
5
import unittest
5
6
 
6
7
from distutils.command.install_lib import install_lib
9
10
from distutils.errors import DistutilsOptionError
10
11
from test.support import run_unittest
11
12
 
 
13
 
12
14
class InstallLibTestCase(support.TempdirManager,
13
15
                         support.LoggingSilencer,
14
16
                         support.EnvironGuard,
15
17
                         unittest.TestCase):
16
18
 
17
19
    def test_finalize_options(self):
18
 
        pkg_dir, dist = self.create_dist()
 
20
        dist = self.create_dist()[1]
19
21
        cmd = install_lib(dist)
20
22
 
21
23
        cmd.finalize_options()
32
34
        cmd.finalize_options()
33
35
        self.assertEqual(cmd.optimize, 2)
34
36
 
35
 
    @unittest.skipUnless(not sys.dont_write_bytecode,
36
 
                         'byte-compile not supported')
 
37
    @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
37
38
    def test_byte_compile(self):
38
 
        pkg_dir, dist = self.create_dist()
 
39
        project_dir, dist = self.create_dist()
 
40
        os.chdir(project_dir)
39
41
        cmd = install_lib(dist)
40
42
        cmd.compile = cmd.optimize = 1
41
43
 
42
 
        f = os.path.join(pkg_dir, 'foo.py')
 
44
        f = os.path.join(project_dir, 'foo.py')
43
45
        self.write_file(f, '# python file')
44
46
        cmd.byte_compile([f])
45
 
        self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
46
 
        self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
 
47
        pyc_file = imp.cache_from_source('foo.py', debug_override=True)
 
48
        pyo_file = imp.cache_from_source('foo.py', debug_override=False)
 
49
        self.assertTrue(os.path.exists(pyc_file))
 
50
        self.assertTrue(os.path.exists(pyo_file))
47
51
 
48
52
    def test_get_outputs(self):
49
 
        pkg_dir, dist = self.create_dist()
 
53
        project_dir, dist = self.create_dist()
 
54
        os.chdir(project_dir)
 
55
        os.mkdir('spam')
50
56
        cmd = install_lib(dist)
51
57
 
52
58
        # setting up a dist environment
53
59
        cmd.compile = cmd.optimize = 1
54
 
        cmd.install_dir = pkg_dir
55
 
        f = os.path.join(pkg_dir, 'foo.py')
56
 
        self.write_file(f, '# python file')
57
 
        cmd.distribution.py_modules = [pkg_dir]
 
60
        cmd.install_dir = self.mkdtemp()
 
61
        f = os.path.join(project_dir, 'spam', '__init__.py')
 
62
        self.write_file(f, '# python package')
58
63
        cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
59
 
        cmd.distribution.packages = [pkg_dir]
 
64
        cmd.distribution.packages = ['spam']
60
65
        cmd.distribution.script_name = 'setup.py'
61
66
 
62
 
        # get_output should return 4 elements
63
 
        self.assertTrue(len(cmd.get_outputs()) >= 2)
 
67
        # get_outputs should return 4 elements: spam/__init__.py, .pyc and
 
68
        # .pyo, foo.import-tag-abiflags.so / foo.pyd
 
69
        outputs = cmd.get_outputs()
 
70
        self.assertEqual(len(outputs), 4, outputs)
64
71
 
65
72
    def test_get_inputs(self):
66
 
        pkg_dir, dist = self.create_dist()
 
73
        project_dir, dist = self.create_dist()
 
74
        os.chdir(project_dir)
 
75
        os.mkdir('spam')
67
76
        cmd = install_lib(dist)
68
77
 
69
78
        # setting up a dist environment
70
79
        cmd.compile = cmd.optimize = 1
71
 
        cmd.install_dir = pkg_dir
72
 
        f = os.path.join(pkg_dir, 'foo.py')
73
 
        self.write_file(f, '# python file')
74
 
        cmd.distribution.py_modules = [pkg_dir]
 
80
        cmd.install_dir = self.mkdtemp()
 
81
        f = os.path.join(project_dir, 'spam', '__init__.py')
 
82
        self.write_file(f, '# python package')
75
83
        cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
76
 
        cmd.distribution.packages = [pkg_dir]
 
84
        cmd.distribution.packages = ['spam']
77
85
        cmd.distribution.script_name = 'setup.py'
78
86
 
79
 
        # get_input should return 2 elements
80
 
        self.assertEqual(len(cmd.get_inputs()), 2)
 
87
        # get_inputs should return 2 elements: spam/__init__.py and
 
88
        # foo.import-tag-abiflags.so / foo.pyd
 
89
        inputs = cmd.get_inputs()
 
90
        self.assertEqual(len(inputs), 2, inputs)
81
91
 
82
92
    def test_dont_write_bytecode(self):
83
93
        # makes sure byte_compile is not used
84
 
        pkg_dir, dist = self.create_dist()
 
94
        dist = self.create_dist()[1]
85
95
        cmd = install_lib(dist)
86
96
        cmd.compile = 1
87
97
        cmd.optimize = 1
95
105
 
96
106
        self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
97
107
 
 
108
 
98
109
def test_suite():
99
110
    return unittest.makeSuite(InstallLibTestCase)
100
111