ยปCore Development>Code coverage>Lib/distutils/tests/test_extension.py

Python code coverage for Lib/distutils/tests/test_extension.py

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