|
8 | 8 | from setuptools.dist import Distribution
|
9 | 9 | from setuptools.extension import Extension
|
10 | 10 |
|
| 11 | +from . import environment |
| 12 | +from .files import build_files |
| 13 | +from .textwrap import DALS |
| 14 | + |
11 | 15 |
|
12 | 16 | class TestBuildExt:
|
13 | 17 | def test_get_ext_filename(self):
|
@@ -43,3 +47,69 @@ def test_abi3_filename(self):
|
43 | 47 | assert res.endswith('eggs.pyd')
|
44 | 48 | else:
|
45 | 49 | assert 'abi3' in res
|
| 50 | + |
| 51 | + |
| 52 | +def test_build_ext_config_handling(tmpdir_cwd): |
| 53 | + files = { |
| 54 | + 'setup.py': DALS( |
| 55 | + """ |
| 56 | + from setuptools import Extension, setup |
| 57 | + setup( |
| 58 | + name='foo', |
| 59 | + version='0.0.0', |
| 60 | + ext_modules=[Extension('foo', ['foo.c'])], |
| 61 | + ) |
| 62 | + """), |
| 63 | + 'foo.c': DALS( |
| 64 | + """ |
| 65 | + #include "Python.h" |
| 66 | +
|
| 67 | + #if PY_MAJOR_VERSION >= 3 |
| 68 | +
|
| 69 | + static struct PyModuleDef moduledef = { |
| 70 | + PyModuleDef_HEAD_INIT, |
| 71 | + "foo", |
| 72 | + NULL, |
| 73 | + 0, |
| 74 | + NULL, |
| 75 | + NULL, |
| 76 | + NULL, |
| 77 | + NULL, |
| 78 | + NULL |
| 79 | + }; |
| 80 | +
|
| 81 | + #define INITERROR return NULL |
| 82 | +
|
| 83 | + PyMODINIT_FUNC PyInit_foo(void) |
| 84 | +
|
| 85 | + #else |
| 86 | +
|
| 87 | + #define INITERROR return |
| 88 | +
|
| 89 | + void initfoo(void) |
| 90 | +
|
| 91 | + #endif |
| 92 | + { |
| 93 | + #if PY_MAJOR_VERSION >= 3 |
| 94 | + PyObject *module = PyModule_Create(&moduledef); |
| 95 | + #else |
| 96 | + PyObject *module = Py_InitModule("extension", NULL); |
| 97 | + #endif |
| 98 | + if (module == NULL) |
| 99 | + INITERROR; |
| 100 | + #if PY_MAJOR_VERSION >= 3 |
| 101 | + return module; |
| 102 | + #endif |
| 103 | + } |
| 104 | + """), |
| 105 | + 'setup.cfg': DALS( |
| 106 | + """ |
| 107 | + [build] |
| 108 | + build-base = foo_build |
| 109 | + """), |
| 110 | + } |
| 111 | + build_files(files) |
| 112 | + code, output = environment.run_setup_py( |
| 113 | + cmd=['build'], data_stream=(0, 2), |
| 114 | + ) |
| 115 | + assert code == 0, '\nSTDOUT:\n%s\nSTDERR:\n%s' % output |
0 commit comments