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