Skip to content

Commit d703350

Browse files
committed
test: add a simple regression test for build_ext
1 parent d46a9c2 commit d703350

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

setuptools/tests/environment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def run_setup_py(cmd, pypath=None, path=None,
4646
cmd, stdout=_PIPE, stderr=_PIPE, shell=shell, env=env,
4747
)
4848

49+
if isinstance(data_stream, tuple):
50+
data_stream = slice(*data_stream)
4951
data = proc.communicate()[data_stream]
5052
except OSError:
5153
return 1, ''

setuptools/tests/test_build_ext.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from setuptools.dist import Distribution
99
from setuptools.extension import Extension
1010

11+
from . import environment
12+
from .files import build_files
13+
from .textwrap import DALS
14+
1115

1216
class TestBuildExt:
1317
def test_get_ext_filename(self):
@@ -43,3 +47,69 @@ def test_abi3_filename(self):
4347
assert res.endswith('eggs.pyd')
4448
else:
4549
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

Comments
 (0)