Tarek Ziadé | c27aca7 | 2009-05-10 11:45:41 +0000 | [diff] [blame] | 1 | """Tests for distutils.command.install_data.""" |
| 2 | import sys |
| 3 | import os |
| 4 | import unittest |
| 5 | |
| 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 |
| 10 | |
| 11 | class InstallLibTestCase(support.TempdirManager, |
| 12 | support.LoggingSilencer, |
Tarek Ziadé | 430fb63 | 2009-10-18 11:34:51 +0000 | [diff] [blame^] | 13 | support.EnvironGuard, |
Tarek Ziadé | c27aca7 | 2009-05-10 11:45:41 +0000 | [diff] [blame] | 14 | unittest.TestCase): |
| 15 | |
Tarek Ziadé | c27aca7 | 2009-05-10 11:45:41 +0000 | [diff] [blame] | 16 | def test_finalize_options(self): |
| 17 | pkg_dir, dist = self.create_dist() |
| 18 | cmd = install_lib(dist) |
| 19 | |
| 20 | cmd.finalize_options() |
| 21 | self.assertEquals(cmd.compile, 1) |
| 22 | self.assertEquals(cmd.optimize, 0) |
| 23 | |
| 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) |
| 29 | |
| 30 | cmd.optimize = '2' |
| 31 | cmd.finalize_options() |
| 32 | self.assertEquals(cmd.optimize, 2) |
| 33 | |
| 34 | def test_byte_compile(self): |
| 35 | pkg_dir, dist = self.create_dist() |
| 36 | cmd = install_lib(dist) |
| 37 | cmd.compile = cmd.optimize = 1 |
| 38 | |
| 39 | f = os.path.join(pkg_dir, 'foo.py') |
| 40 | self.write_file(f, '# python file') |
| 41 | cmd.byte_compile([f]) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 42 | self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc'))) |
| 43 | self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo'))) |
Tarek Ziadé | c27aca7 | 2009-05-10 11:45:41 +0000 | [diff] [blame] | 44 | |
| 45 | def test_get_outputs(self): |
| 46 | pkg_dir, dist = self.create_dist() |
| 47 | cmd = install_lib(dist) |
| 48 | |
| 49 | # setting up a dist environment |
| 50 | cmd.compile = cmd.optimize = 1 |
| 51 | cmd.install_dir = pkg_dir |
| 52 | f = os.path.join(pkg_dir, 'foo.py') |
| 53 | self.write_file(f, '# python file') |
| 54 | cmd.distribution.py_modules = [pkg_dir] |
| 55 | cmd.distribution.ext_modules = [Extension('foo', ['xxx'])] |
| 56 | cmd.distribution.packages = [pkg_dir] |
| 57 | cmd.distribution.script_name = 'setup.py' |
| 58 | |
| 59 | # get_output should return 4 elements |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 60 | self.assertTrue(len(cmd.get_outputs()) >= 2) |
Tarek Ziadé | c27aca7 | 2009-05-10 11:45:41 +0000 | [diff] [blame] | 61 | |
| 62 | def test_get_inputs(self): |
| 63 | pkg_dir, dist = self.create_dist() |
| 64 | cmd = install_lib(dist) |
| 65 | |
| 66 | # setting up a dist environment |
| 67 | cmd.compile = cmd.optimize = 1 |
| 68 | cmd.install_dir = pkg_dir |
| 69 | f = os.path.join(pkg_dir, 'foo.py') |
| 70 | self.write_file(f, '# python file') |
| 71 | cmd.distribution.py_modules = [pkg_dir] |
| 72 | cmd.distribution.ext_modules = [Extension('foo', ['xxx'])] |
| 73 | cmd.distribution.packages = [pkg_dir] |
| 74 | cmd.distribution.script_name = 'setup.py' |
| 75 | |
| 76 | # get_input should return 2 elements |
| 77 | self.assertEquals(len(cmd.get_inputs()), 2) |
| 78 | |
| 79 | |
| 80 | def test_suite(): |
| 81 | return unittest.makeSuite(InstallLibTestCase) |
| 82 | |
| 83 | if __name__ == "__main__": |
| 84 | unittest.main(defaultTest="test_suite") |