Issue #7575: An overflow test for math.expm1 was failing on OS X 10.4/Intel,
[python.git] / Lib / distutils / tests / test_extension.py
blob159ac2b76e35e6dc0c319e6fdab75643498b76c2
1 """Tests for distutils.extension."""
2 import unittest
3 import os
4 import warnings
6 from test.test_support import check_warnings
7 from distutils.extension import read_setup_file, Extension
9 class ExtensionTestCase(unittest.TestCase):
11 def test_read_setup_file(self):
12 # trying to read a Setup file
13 # (sample extracted from the PyGame project)
14 setup = os.path.join(os.path.dirname(__file__), 'Setup.sample')
16 exts = read_setup_file(setup)
17 names = [ext.name for ext in exts]
18 names.sort()
20 # here are the extensions read_setup_file should have created
21 # out of the file
22 wanted = ['_arraysurfarray', '_camera', '_numericsndarray',
23 '_numericsurfarray', 'base', 'bufferproxy', 'cdrom',
24 'color', 'constants', 'display', 'draw', 'event',
25 'fastevent', 'font', 'gfxdraw', 'image', 'imageext',
26 'joystick', 'key', 'mask', 'mixer', 'mixer_music',
27 'mouse', 'movie', 'overlay', 'pixelarray', 'pypm',
28 'rect', 'rwobject', 'scrap', 'surface', 'surflock',
29 'time', 'transform']
31 self.assertEquals(names, wanted)
33 def test_extension_init(self):
34 # the first argument, which is the name, must be a string
35 self.assertRaises(AssertionError, Extension, 1, [])
36 ext = Extension('name', [])
37 self.assertEquals(ext.name, 'name')
39 # the second argument, which is the list of files, must
40 # be a list of strings
41 self.assertRaises(AssertionError, Extension, 'name', 'file')
42 self.assertRaises(AssertionError, Extension, 'name', ['file', 1])
43 ext = Extension('name', ['file1', 'file2'])
44 self.assertEquals(ext.sources, ['file1', 'file2'])
46 # others arguments have defaults
47 for attr in ('include_dirs', 'define_macros', 'undef_macros',
48 'library_dirs', 'libraries', 'runtime_library_dirs',
49 'extra_objects', 'extra_compile_args', 'extra_link_args',
50 'export_symbols', 'swig_opts', 'depends'):
51 self.assertEquals(getattr(ext, attr), [])
53 self.assertEquals(ext.language, None)
54 self.assertEquals(ext.optional, None)
56 # if there are unknown keyword options, warn about them
57 with check_warnings() as w:
58 warnings.simplefilter('always')
59 ext = Extension('name', ['file1', 'file2'], chic=True)
61 self.assertEquals(len(w.warnings), 1)
62 self.assertEquals(str(w.warnings[0].message),
63 "Unknown Extension options: 'chic'")
65 def test_suite():
66 return unittest.makeSuite(ExtensionTestCase)
68 if __name__ == "__main__":
69 unittest.main(defaultTest="test_suite")