Issue #7575: An overflow test for math.expm1 was failing on OS X 10.4/Intel,
[python.git] / Lib / distutils / tests / test_install_lib.py
blob99a6d9062727972757a07fe29e1c0cac10055b5f
1 """Tests for distutils.command.install_data."""
2 import sys
3 import os
4 import unittest
6 from distutils.command.install_lib import install_lib
7 from distutils.extension import Extension
8 from distutils.tests import support
9 from distutils.errors import DistutilsOptionError
11 class InstallLibTestCase(support.TempdirManager,
12 support.LoggingSilencer,
13 support.EnvironGuard,
14 unittest.TestCase):
16 def test_finalize_options(self):
17 pkg_dir, dist = self.create_dist()
18 cmd = install_lib(dist)
20 cmd.finalize_options()
21 self.assertEquals(cmd.compile, 1)
22 self.assertEquals(cmd.optimize, 0)
24 # optimize must be 0, 1, or 2
25 cmd.optimize = 'foo'
26 self.assertRaises(DistutilsOptionError, cmd.finalize_options)
27 cmd.optimize = '4'
28 self.assertRaises(DistutilsOptionError, cmd.finalize_options)
30 cmd.optimize = '2'
31 cmd.finalize_options()
32 self.assertEquals(cmd.optimize, 2)
34 @unittest.skipUnless(not sys.dont_write_bytecode,
35 'byte-compile not supported')
36 def test_byte_compile(self):
37 pkg_dir, dist = self.create_dist()
38 cmd = install_lib(dist)
39 cmd.compile = cmd.optimize = 1
41 f = os.path.join(pkg_dir, 'foo.py')
42 self.write_file(f, '# python file')
43 cmd.byte_compile([f])
44 self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
45 self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
47 def test_get_outputs(self):
48 pkg_dir, dist = self.create_dist()
49 cmd = install_lib(dist)
51 # setting up a dist environment
52 cmd.compile = cmd.optimize = 1
53 cmd.install_dir = pkg_dir
54 f = os.path.join(pkg_dir, 'foo.py')
55 self.write_file(f, '# python file')
56 cmd.distribution.py_modules = [pkg_dir]
57 cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
58 cmd.distribution.packages = [pkg_dir]
59 cmd.distribution.script_name = 'setup.py'
61 # get_output should return 4 elements
62 self.assertTrue(len(cmd.get_outputs()) >= 2)
64 def test_get_inputs(self):
65 pkg_dir, dist = self.create_dist()
66 cmd = install_lib(dist)
68 # setting up a dist environment
69 cmd.compile = cmd.optimize = 1
70 cmd.install_dir = pkg_dir
71 f = os.path.join(pkg_dir, 'foo.py')
72 self.write_file(f, '# python file')
73 cmd.distribution.py_modules = [pkg_dir]
74 cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
75 cmd.distribution.packages = [pkg_dir]
76 cmd.distribution.script_name = 'setup.py'
78 # get_input should return 2 elements
79 self.assertEquals(len(cmd.get_inputs()), 2)
81 def test_dont_write_bytecode(self):
82 # makes sure byte_compile is not used
83 pkg_dir, dist = self.create_dist()
84 cmd = install_lib(dist)
85 cmd.compile = 1
86 cmd.optimize = 1
88 old_dont_write_bytecode = sys.dont_write_bytecode
89 sys.dont_write_bytecode = True
90 try:
91 cmd.byte_compile([])
92 finally:
93 sys.dont_write_bytecode = old_dont_write_bytecode
95 self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
97 def test_suite():
98 return unittest.makeSuite(InstallLibTestCase)
100 if __name__ == "__main__":
101 unittest.main(defaultTest="test_suite")