1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
| """Tests for distutils.extension."""
|
| import os
| import pathlib
| import warnings
| from distutils.extension import Extension, read_setup_file
|
| import pytest
| from test.support.warnings_helper import check_warnings
|
|
| class TestExtension:
| def test_read_setup_file(self):
| # trying to read a Setup file
| # (sample extracted from the PyGame project)
| setup = os.path.join(os.path.dirname(__file__), 'Setup.sample')
|
| exts = read_setup_file(setup)
| names = [ext.name for ext in exts]
| names.sort()
|
| # here are the extensions read_setup_file should have created
| # out of the file
| wanted = [
| '_arraysurfarray',
| '_camera',
| '_numericsndarray',
| '_numericsurfarray',
| 'base',
| 'bufferproxy',
| 'cdrom',
| 'color',
| 'constants',
| 'display',
| 'draw',
| 'event',
| 'fastevent',
| 'font',
| 'gfxdraw',
| 'image',
| 'imageext',
| 'joystick',
| 'key',
| 'mask',
| 'mixer',
| 'mixer_music',
| 'mouse',
| 'movie',
| 'overlay',
| 'pixelarray',
| 'pypm',
| 'rect',
| 'rwobject',
| 'scrap',
| 'surface',
| 'surflock',
| 'time',
| 'transform',
| ]
|
| assert names == wanted
|
| def test_extension_init(self):
| # the first argument, which is the name, must be a string
| with pytest.raises(TypeError):
| Extension(1, [])
| ext = Extension('name', [])
| assert ext.name == 'name'
|
| # the second argument, which is the list of files, must
| # be an iterable of strings or PathLike objects, and not a string
| with pytest.raises(TypeError):
| Extension('name', 'file')
| with pytest.raises(TypeError):
| Extension('name', ['file', 1])
| ext = Extension('name', ['file1', 'file2'])
| assert ext.sources == ['file1', 'file2']
| ext = Extension('name', [pathlib.Path('file1'), pathlib.Path('file2')])
| assert ext.sources == ['file1', 'file2']
|
| # any non-string iterable of strings or PathLike objects should work
| ext = Extension('name', ('file1', 'file2')) # tuple
| assert ext.sources == ['file1', 'file2']
| ext = Extension('name', {'file1', 'file2'}) # set
| assert sorted(ext.sources) == ['file1', 'file2']
| ext = Extension('name', iter(['file1', 'file2'])) # iterator
| assert ext.sources == ['file1', 'file2']
| ext = Extension('name', [pathlib.Path('file1'), 'file2']) # mixed types
| assert ext.sources == ['file1', 'file2']
|
| # others arguments have defaults
| for attr in (
| 'include_dirs',
| 'define_macros',
| 'undef_macros',
| 'library_dirs',
| 'libraries',
| 'runtime_library_dirs',
| 'extra_objects',
| 'extra_compile_args',
| 'extra_link_args',
| 'export_symbols',
| 'swig_opts',
| 'depends',
| ):
| assert getattr(ext, attr) == []
|
| assert ext.language is None
| assert ext.optional is None
|
| # if there are unknown keyword options, warn about them
| with check_warnings() as w:
| warnings.simplefilter('always')
| ext = Extension('name', ['file1', 'file2'], chic=True)
|
| assert len(w.warnings) == 1
| assert str(w.warnings[0].message) == "Unknown Extension options: 'chic'"
|
|