~ubuntu-branches/ubuntu/wily/stsci.distutils/wily-proposed

« back to all changes in this revision

Viewing changes to stsci/distutils/tests/test_commands.py

  • Committer: Package Import Robot
  • Author(s): Aurelien Jarno
  • Date: 2012-06-04 00:57:50 UTC
  • Revision ID: package-import@ubuntu.com-20120604005750-cv84pzg8ij2mssim
Tags: upstream-0.3
ImportĀ upstreamĀ versionĀ 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import with_statement
 
2
 
 
3
import os
 
4
import sys
 
5
 
 
6
from . import StsciDistutilsTestCase
 
7
from .util import get_compiler_command, open_config
 
8
 
 
9
 
 
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
 
14
        # smoothly
 
15
        compiler_cmd = get_compiler_command()
 
16
 
 
17
        _, _, exit_code = self.run_setup('build')
 
18
 
 
19
        # Make sure the build went successfully; a zero exit code should be
 
20
        # good enough for our purposes
 
21
        assert exit_code == 0
 
22
 
 
23
        # Now let's try breaking the build
 
24
        with open(os.path.join('src', 'testext.c'), 'a') as f:
 
25
            f.write('1/0')
 
26
 
 
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')
 
35
        else:
 
36
            _, stderr, exit_code = self.run_setup('build', '--force')
 
37
        assert exit_code == 0
 
38
        assert stderr.splitlines()[-1].startswith(msg)
 
39
 
 
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.')
 
44
 
 
45
        if sys.version_info[:2] < (2, 7):
 
46
            stderr, _, exit_code = self.run_setup('build', '--force')
 
47
        else:
 
48
            _, stderr, exit_code = self.run_setup('build', '--force')
 
49
        assert exit_code == 0
 
50
        assert stderr.splitlines()[-1] == 'Custom fail message.'
 
51
 
 
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',
 
56
                              'optional')
 
57
 
 
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')
 
61
        assert exit_code != 0
 
62
        assert stderr.splitlines()[-1].startswith(msg)