1
from __future__ import with_statement
6
from . import StsciDistutilsTestCase
7
from .util import get_compiler_command, open_config
10
class TestCommands(StsciDistutilsTestCase):
11
def test_build_optional_ext(self):
12
# The test extension in the test package is already configured to be
13
# "optional" by default--we'll do one test build to make sure that goes
15
compiler_cmd = get_compiler_command()
17
_, _, exit_code = self.run_setup('build')
19
# Make sure the build went successfully; a zero exit code should be
20
# good enough for our purposes
23
# Now let's try breaking the build
24
with open(os.path.join('src', 'testext.c'), 'a') as f:
27
# We leave off the exit status from the compiler--in most cases it will
28
# say "exit status 1" but that can't be guaranteed for all compilers
29
msg = ('building optional extension "stsci.testpackage.testext" '
30
'failed: command \'%s\' failed with exit status' % compiler_cmd)
31
# Prior to Python 2.7, distutils.log output everything to stdout; now
32
# warnings and errors are output to stderr
33
if sys.version_info[:2] < (2, 7):
34
stderr, _, exit_code = self.run_setup('build', '--force')
36
_, stderr, exit_code = self.run_setup('build', '--force')
38
assert stderr.splitlines()[-1].startswith(msg)
40
# Test a custom fail message
41
with open_config('setup.cfg') as cfg:
42
cfg.set('extension=stsci.testpackage.testext', 'fail_message',
43
'Custom fail message.')
45
if sys.version_info[:2] < (2, 7):
46
stderr, _, exit_code = self.run_setup('build', '--force')
48
_, stderr, exit_code = self.run_setup('build', '--force')
50
assert stderr.splitlines()[-1] == 'Custom fail message.'
52
# Finally, make sure the extension is *not* treated as optional if not
53
# marked as such in the config
54
with open_config('setup.cfg') as cfg:
55
cfg.remove_option('extension=stsci.testpackage.testext',
58
# This error message comes out on stderr for all Python versions AFAICT
59
msg = "error: command '%s' failed with exit status" % compiler_cmd
60
_, stderr, exit_code = self.run_setup('build', '--force')
62
assert stderr.splitlines()[-1].startswith(msg)