diff options
author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-08-12 15:58:22 +0100 |
---|---|---|
committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-08-12 16:00:16 +0100 |
commit | 9498fea0319d52b86415a3025e236f8c2b667863 (patch) | |
tree | 64175d64ed565408b3f4fa6698848755ec5878a9 /setuptools/tests | |
parent | 4eff1adc04d2a91d60cd4e6d7ef36e3a79460cb5 (diff) | |
download | python-setuptools-git-9498fea0319d52b86415a3025e236f8c2b667863.tar.gz |
Add test for non-optional extensions
Diffstat (limited to 'setuptools/tests')
-rw-r--r-- | setuptools/tests/test_build_ext.py | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/setuptools/tests/test_build_ext.py b/setuptools/tests/test_build_ext.py index 1e3aea20..26e69f94 100644 --- a/setuptools/tests/test_build_ext.py +++ b/setuptools/tests/test_build_ext.py @@ -9,10 +9,13 @@ from jaraco import path from setuptools.command.build_ext import build_ext, get_abi3_suffix from setuptools.dist import Distribution from setuptools.extension import Extension +from setuptools.errors import CompileError from . import environment from .textwrap import DALS +import pytest + IS_PYPY = '__pypy__' in sys.builtin_module_names @@ -31,26 +34,6 @@ class TestBuildExt: wanted = orig.build_ext.get_ext_filename(cmd, 'foo') assert res == wanted - def test_optional_inplace(self, tmpdir_cwd, capsys): - # If optional extensions fail to build, setuptools should show the error - # in the logs but not fail to build - files = { - "eggs.c": "#include missingheader.h\n", - ".build": {"lib": {}, "tmp": {}}, - } - path.build(files) - extension = Extension('spam.eggs', ['eggs.c'], optional=True) - dist = Distribution(dict(ext_modules=[extension])) - dist.script_name = 'setup.py' - cmd = build_ext(dist) - vars(cmd).update(build_lib=".build/lib", build_temp=".build/tmp", inplace=True) - cmd.ensure_finalized() - cmd.run() - logs = capsys.readouterr() - messages = (logs.out + logs.err) - assert 'build_ext: building extension "spam.eggs" failed' in messages - # No exception should be raised - def test_abi3_filename(self): """ Filename needs to be loadable by several versions @@ -196,6 +179,39 @@ class TestBuildExt: assert example_stub.endswith(".pyc") +class TestBuildExtInplace: + def get_build_ext_cmd(self, optional: bool, **opts): + files = { + "eggs.c": "#include missingheader.h\n", + ".build": {"lib": {}, "tmp": {}}, + } + path.build(files) + extension = Extension('spam.eggs', ['eggs.c'], optional=optional) + dist = Distribution(dict(ext_modules=[extension])) + dist.script_name = 'setup.py' + cmd = build_ext(dist) + vars(cmd).update(build_lib=".build/lib", build_temp=".build/tmp", **opts) + cmd.ensure_finalized() + return cmd + + def test_optional(self, tmpdir_cwd, capsys): + """ + If optional extensions fail to build, setuptools should show the error + in the logs but not fail to build + """ + cmd = self.get_build_ext_cmd(optional=True, inplace=True) + cmd.run() + logs = capsys.readouterr() + messages = (logs.out + logs.err) + assert 'build_ext: building extension "spam.eggs" failed' in messages + # No compile error exception should be raised + + def test_non_optional(self, tmpdir_cwd): + # Non-optional extensions should raise an exception + cmd = self.get_build_ext_cmd(optional=False, inplace=True) + with pytest.raises(CompileError): + cmd.run() + def test_build_ext_config_handling(tmpdir_cwd): files = { 'setup.py': DALS( |