2009-05-10 08:45:41 -03:00
|
|
|
"""Tests for distutils.command.install_data."""
|
2010-02-23 21:46:21 -04:00
|
|
|
import sys
|
2010-07-22 09:50:05 -03:00
|
|
|
import os
|
2011-10-07 19:34:13 -03:00
|
|
|
import imp
|
2009-05-10 08:45:41 -03:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from distutils.command.install_lib import install_lib
|
|
|
|
from distutils.extension import Extension
|
|
|
|
from distutils.tests import support
|
|
|
|
from distutils.errors import DistutilsOptionError
|
2010-11-05 23:44:43 -03:00
|
|
|
from test.support import run_unittest
|
2009-05-10 08:45:41 -03:00
|
|
|
|
2011-11-02 23:45:33 -03:00
|
|
|
|
2009-05-10 08:45:41 -03:00
|
|
|
class InstallLibTestCase(support.TempdirManager,
|
|
|
|
support.LoggingSilencer,
|
2009-10-18 08:34:51 -03:00
|
|
|
support.EnvironGuard,
|
2009-05-10 08:45:41 -03:00
|
|
|
unittest.TestCase):
|
|
|
|
|
|
|
|
def test_finalize_options(self):
|
2011-11-02 23:45:33 -03:00
|
|
|
dist = self.create_dist()[1]
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd = install_lib(dist)
|
|
|
|
|
|
|
|
cmd.finalize_options()
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(cmd.compile, 1)
|
|
|
|
self.assertEqual(cmd.optimize, 0)
|
2009-05-10 08:45:41 -03:00
|
|
|
|
|
|
|
# optimize must be 0, 1, or 2
|
|
|
|
cmd.optimize = 'foo'
|
|
|
|
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
|
|
|
|
cmd.optimize = '4'
|
|
|
|
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
|
|
|
|
|
|
|
|
cmd.optimize = '2'
|
|
|
|
cmd.finalize_options()
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(cmd.optimize, 2)
|
2009-05-10 08:45:41 -03:00
|
|
|
|
2011-10-07 19:34:13 -03:00
|
|
|
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
|
2010-07-22 09:50:05 -03:00
|
|
|
def test_byte_compile(self):
|
2011-11-02 23:45:33 -03:00
|
|
|
project_dir, dist = self.create_dist()
|
|
|
|
os.chdir(project_dir)
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd = install_lib(dist)
|
|
|
|
cmd.compile = cmd.optimize = 1
|
|
|
|
|
2011-11-02 23:45:33 -03:00
|
|
|
f = os.path.join(project_dir, 'foo.py')
|
2009-05-10 08:45:41 -03:00
|
|
|
self.write_file(f, '# python file')
|
|
|
|
cmd.byte_compile([f])
|
2011-11-02 23:45:33 -03:00
|
|
|
pyc_file = imp.cache_from_source('foo.py', debug_override=True)
|
2011-10-07 19:34:13 -03:00
|
|
|
pyo_file = imp.cache_from_source('foo.py', debug_override=False)
|
|
|
|
self.assertTrue(os.path.exists(pyc_file))
|
|
|
|
self.assertTrue(os.path.exists(pyo_file))
|
2009-05-10 08:45:41 -03:00
|
|
|
|
|
|
|
def test_get_outputs(self):
|
2011-11-02 23:45:33 -03:00
|
|
|
project_dir, dist = self.create_dist()
|
|
|
|
os.chdir(project_dir)
|
|
|
|
os.mkdir('spam')
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd = install_lib(dist)
|
|
|
|
|
|
|
|
# setting up a dist environment
|
|
|
|
cmd.compile = cmd.optimize = 1
|
2011-11-02 23:45:33 -03:00
|
|
|
cmd.install_dir = self.mkdtemp()
|
|
|
|
f = os.path.join(project_dir, 'spam', '__init__.py')
|
|
|
|
self.write_file(f, '# python package')
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
|
2011-11-02 23:45:33 -03:00
|
|
|
cmd.distribution.packages = ['spam']
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd.distribution.script_name = 'setup.py'
|
|
|
|
|
2011-11-02 23:45:33 -03:00
|
|
|
# get_outputs should return 4 elements: spam/__init__.py, .pyc and
|
|
|
|
# .pyo, foo.import-tag-abiflags.so / foo.pyd
|
|
|
|
outputs = cmd.get_outputs()
|
|
|
|
self.assertEqual(len(outputs), 4, outputs)
|
2009-05-10 08:45:41 -03:00
|
|
|
|
|
|
|
def test_get_inputs(self):
|
2011-11-02 23:45:33 -03:00
|
|
|
project_dir, dist = self.create_dist()
|
|
|
|
os.chdir(project_dir)
|
|
|
|
os.mkdir('spam')
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd = install_lib(dist)
|
|
|
|
|
|
|
|
# setting up a dist environment
|
|
|
|
cmd.compile = cmd.optimize = 1
|
2011-11-02 23:45:33 -03:00
|
|
|
cmd.install_dir = self.mkdtemp()
|
|
|
|
f = os.path.join(project_dir, 'spam', '__init__.py')
|
|
|
|
self.write_file(f, '# python package')
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
|
2011-11-02 23:45:33 -03:00
|
|
|
cmd.distribution.packages = ['spam']
|
2009-05-10 08:45:41 -03:00
|
|
|
cmd.distribution.script_name = 'setup.py'
|
|
|
|
|
2011-11-02 23:45:33 -03:00
|
|
|
# get_inputs should return 2 elements: spam/__init__.py and
|
|
|
|
# foo.import-tag-abiflags.so / foo.pyd
|
|
|
|
inputs = cmd.get_inputs()
|
|
|
|
self.assertEqual(len(inputs), 2, inputs)
|
2009-05-10 08:45:41 -03:00
|
|
|
|
2009-10-25 20:08:47 -03:00
|
|
|
def test_dont_write_bytecode(self):
|
|
|
|
# makes sure byte_compile is not used
|
2011-11-02 23:45:33 -03:00
|
|
|
dist = self.create_dist()[1]
|
2009-10-25 20:08:47 -03:00
|
|
|
cmd = install_lib(dist)
|
|
|
|
cmd.compile = 1
|
|
|
|
cmd.optimize = 1
|
|
|
|
|
|
|
|
old_dont_write_bytecode = sys.dont_write_bytecode
|
|
|
|
sys.dont_write_bytecode = True
|
|
|
|
try:
|
|
|
|
cmd.byte_compile([])
|
|
|
|
finally:
|
|
|
|
sys.dont_write_bytecode = old_dont_write_bytecode
|
|
|
|
|
|
|
|
self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
|
2009-05-10 08:45:41 -03:00
|
|
|
|
2011-11-02 23:45:33 -03:00
|
|
|
|
2009-05-10 08:45:41 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(InstallLibTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-11-05 23:44:43 -03:00
|
|
|
run_unittest(test_suite())
|