/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_setup.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
""" test for setup.py build process """
 
1
# Copyright (C) 2005, 2006, 2008, 2009, 2010 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Test for setup.py build process"""
2
18
 
3
19
import os
4
20
import sys
6
22
import shutil
7
23
from tempfile import TemporaryFile
8
24
 
9
 
from bzrlib.tests import TestCase
10
 
 
11
 
 
12
 
# TODO: ideally run this in a separate directory, so as not to clobber the
13
 
# real build directory
 
25
import bzrlib
 
26
from bzrlib.tests import TestCase, TestSkipped
 
27
import bzrlib.osutils as osutils
 
28
 
 
29
# XXX: This clobbers the build directory in the real source tree; it'd be nice
 
30
# to avoid that.
 
31
#
 
32
# TODO: Run bzr from the installed copy to see if it works.  Really we need to
 
33
# run something that exercises every module, just starting it may not detect
 
34
# some missing modules.
 
35
#
 
36
# TODO: Check that the version numbers are in sync.  (Or avoid this...)
14
37
 
15
38
class TestSetup(TestCase):
16
39
 
17
 
    def test_build(self):
 
40
    def test_build_and_install(self):
18
41
        """ test cmd `python setup.py build`
19
 
        
20
 
        This typically catches new subdirectories which weren't added to setup.py
 
42
 
 
43
        This tests that the build process and man generator run correctly.
 
44
        It also can catch new subdirectories that weren't added to setup.py.
21
45
        """
 
46
        # setup.py must be run from the root source directory, but the tests
 
47
        # are not necessarily invoked from there
 
48
        self.source_dir = os.path.dirname(os.path.dirname(bzrlib.__file__))
 
49
        if not os.path.isfile(os.path.join(self.source_dir, 'setup.py')):
 
50
            raise TestSkipped(
 
51
                'There is no setup.py file adjacent to the bzrlib directory')
 
52
        try:
 
53
            import distutils.sysconfig
 
54
            makefile_path = distutils.sysconfig.get_makefile_filename()
 
55
            if not os.path.exists(makefile_path):
 
56
                raise TestSkipped(
 
57
                    'You must have the python Makefile installed to run this'
 
58
                    ' test. Usually this can be found by installing'
 
59
                    ' "python-dev"')
 
60
        except ImportError:
 
61
            raise TestSkipped(
 
62
                'You must have distutils installed to run this test.'
 
63
                ' Usually this can be found by installing "python-dev"')
22
64
        self.log('test_build running in %s' % os.getcwd())
 
65
        root_dir = osutils.mkdtemp()
23
66
        try:
24
 
            # run setup.py build as subproces and catch return code
25
 
            out_file = TemporaryFile()
26
 
            err_file = TemporaryFile()
27
 
            p = subprocess.Popen([sys.executable, 'setup.py', 'build'],
28
 
                                 stdout=out_file, stderr=err_file)
29
 
            s = p.communicate()
30
 
            self.assertEqual(0, p.returncode, '`python setup.py build` fails')
 
67
            self.run_setup(['clean'])
 
68
            # build is implied by install
 
69
            ## self.run_setup(['build'])
 
70
            self.run_setup(['install', '--root', root_dir])
 
71
            self.run_setup(['clean'])
31
72
        finally:
32
 
            if os.path.exists('build'):
33
 
                shutil.rmtree(u'build')
 
73
            osutils.rmtree(root_dir)
 
74
 
 
75
    def run_setup(self, args):
 
76
        args = [sys.executable, './setup.py', ] + args
 
77
        self.log('source base directory: %s', self.source_dir)
 
78
        self.log('args: %r', args)
 
79
        p = subprocess.Popen(args,
 
80
                             cwd=self.source_dir,
 
81
                             stdout=subprocess.PIPE,
 
82
                             stderr=subprocess.PIPE,
 
83
                             )
 
84
        stdout, stderr = p.communicate()
 
85
        self.log('stdout: %r', stdout)
 
86
        self.log('stderr: %r', stderr)
 
87
        self.assertEqual(0, p.returncode,
 
88
                         'invocation of %r failed' % args)