2009-05-06 04:17:52 -03:00
|
|
|
"""Tests for distutils.command.build_clib."""
|
|
|
|
import unittest
|
2009-05-07 18:20:34 -03:00
|
|
|
import os
|
|
|
|
import sys
|
2009-05-06 04:17:52 -03:00
|
|
|
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
from test.test_support import run_unittest
|
|
|
|
|
2009-05-06 04:17:52 -03:00
|
|
|
from distutils.command.build_clib import build_clib
|
|
|
|
from distutils.errors import DistutilsSetupError
|
|
|
|
from distutils.tests import support
|
2009-05-07 18:20:34 -03:00
|
|
|
from distutils.spawn import find_executable
|
2009-05-06 04:17:52 -03:00
|
|
|
|
|
|
|
class BuildCLibTestCase(support.TempdirManager,
|
|
|
|
support.LoggingSilencer,
|
|
|
|
unittest.TestCase):
|
|
|
|
|
|
|
|
def test_check_library_dist(self):
|
|
|
|
pkg_dir, dist = self.create_dist()
|
|
|
|
cmd = build_clib(dist)
|
|
|
|
|
|
|
|
# 'libraries' option must be a list
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.check_library_list, 'foo')
|
|
|
|
|
|
|
|
# each element of 'libraries' must a 2-tuple
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
|
|
|
['foo1', 'foo2'])
|
|
|
|
|
|
|
|
# first element of each tuple in 'libraries'
|
|
|
|
# must be a string (the library name)
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
|
|
|
[(1, 'foo1'), ('name', 'foo2')])
|
|
|
|
|
|
|
|
# library name may not contain directory separators
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
|
|
|
[('name', 'foo1'),
|
|
|
|
('another/name', 'foo2')])
|
|
|
|
|
|
|
|
# second element of each tuple must be a dictionary (build info)
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.check_library_list,
|
|
|
|
[('name', {}),
|
|
|
|
('another', 'foo2')])
|
|
|
|
|
|
|
|
# those work
|
|
|
|
libs = [('name', {}), ('name', {'ok': 'good'})]
|
|
|
|
cmd.check_library_list(libs)
|
|
|
|
|
2009-05-06 05:05:47 -03:00
|
|
|
def test_get_source_files(self):
|
|
|
|
pkg_dir, dist = self.create_dist()
|
|
|
|
cmd = build_clib(dist)
|
|
|
|
|
|
|
|
# "in 'libraries' option 'sources' must be present and must be
|
|
|
|
# a list of source filenames
|
|
|
|
cmd.libraries = [('name', {})]
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.get_source_files)
|
|
|
|
|
|
|
|
cmd.libraries = [('name', {'sources': 1})]
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.get_source_files)
|
|
|
|
|
|
|
|
cmd.libraries = [('name', {'sources': ['a', 'b']})]
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.get_source_files(), ['a', 'b'])
|
2009-05-06 05:05:47 -03:00
|
|
|
|
|
|
|
cmd.libraries = [('name', {'sources': ('a', 'b')})]
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.get_source_files(), ['a', 'b'])
|
2009-05-06 05:05:47 -03:00
|
|
|
|
|
|
|
cmd.libraries = [('name', {'sources': ('a', 'b')}),
|
|
|
|
('name2', {'sources': ['c', 'd']})]
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.get_source_files(), ['a', 'b', 'c', 'd'])
|
2009-05-06 05:05:47 -03:00
|
|
|
|
|
|
|
def test_build_libraries(self):
|
|
|
|
|
|
|
|
pkg_dir, dist = self.create_dist()
|
|
|
|
cmd = build_clib(dist)
|
|
|
|
class FakeCompiler:
|
|
|
|
def compile(*args, **kw):
|
|
|
|
pass
|
|
|
|
create_static_lib = compile
|
|
|
|
|
|
|
|
cmd.compiler = FakeCompiler()
|
|
|
|
|
|
|
|
# build_libraries is also doing a bit of typoe checking
|
|
|
|
lib = [('name', {'sources': 'notvalid'})]
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.build_libraries, lib)
|
|
|
|
|
|
|
|
lib = [('name', {'sources': list()})]
|
|
|
|
cmd.build_libraries(lib)
|
|
|
|
|
|
|
|
lib = [('name', {'sources': tuple()})]
|
|
|
|
cmd.build_libraries(lib)
|
|
|
|
|
|
|
|
def test_finalize_options(self):
|
|
|
|
pkg_dir, dist = self.create_dist()
|
|
|
|
cmd = build_clib(dist)
|
|
|
|
|
|
|
|
cmd.include_dirs = 'one-dir'
|
|
|
|
cmd.finalize_options()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.include_dirs, ['one-dir'])
|
2009-05-06 05:05:47 -03:00
|
|
|
|
|
|
|
cmd.include_dirs = None
|
|
|
|
cmd.finalize_options()
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(cmd.include_dirs, [])
|
2009-05-06 05:05:47 -03:00
|
|
|
|
|
|
|
cmd.distribution.libraries = 'WONTWORK'
|
|
|
|
self.assertRaises(DistutilsSetupError, cmd.finalize_options)
|
2009-05-06 04:17:52 -03:00
|
|
|
|
2009-05-07 18:20:34 -03:00
|
|
|
def test_run(self):
|
|
|
|
# can't test on windows
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
return
|
|
|
|
|
|
|
|
pkg_dir, dist = self.create_dist()
|
|
|
|
cmd = build_clib(dist)
|
|
|
|
|
|
|
|
foo_c = os.path.join(pkg_dir, 'foo.c')
|
2009-05-11 05:45:17 -03:00
|
|
|
self.write_file(foo_c, 'int main(void) { return 1;}\n')
|
2009-05-07 18:20:34 -03:00
|
|
|
cmd.libraries = [('foo', {'sources': [foo_c]})]
|
|
|
|
|
|
|
|
build_temp = os.path.join(pkg_dir, 'build')
|
|
|
|
os.mkdir(build_temp)
|
|
|
|
cmd.build_temp = build_temp
|
|
|
|
cmd.build_clib = build_temp
|
|
|
|
|
|
|
|
# before we run the command, we want to make sure
|
|
|
|
# all commands are present on the system
|
|
|
|
# by creating a compiler and checking its executables
|
2010-01-23 05:23:15 -04:00
|
|
|
from distutils.ccompiler import new_compiler, customize_compiler
|
2009-05-07 18:20:34 -03:00
|
|
|
|
|
|
|
compiler = new_compiler()
|
|
|
|
customize_compiler(compiler)
|
|
|
|
for ccmd in compiler.executables.values():
|
|
|
|
if ccmd is None:
|
|
|
|
continue
|
|
|
|
if find_executable(ccmd[0]) is None:
|
|
|
|
return # can't test
|
|
|
|
|
|
|
|
# this should work
|
|
|
|
cmd.run()
|
|
|
|
|
|
|
|
# let's check the result
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue('libfoo.a' in os.listdir(build_temp))
|
2009-05-07 18:20:34 -03:00
|
|
|
|
2009-05-06 04:17:52 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(BuildCLibTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
run_unittest(test_suite())
|