/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_import_tariff.py

  • Committer: Vincent Ladeuil
  • Date: 2011-05-31 21:08:52 UTC
  • mfrom: (5743.12.19 config-options)
  • mto: This revision was merged to the branch mainline in revision 5945.
  • Revision ID: v.ladeuil+lp@free.fr-20110531210852-0uyfsjkws5zbfs8m
Merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
from testtools import content
22
22
 
 
23
from bzrlib import (
 
24
    osutils,
 
25
    trace,
 
26
    )
23
27
from bzrlib.bzrdir import BzrDir
24
28
from bzrlib.smart import medium
25
29
from bzrlib.transport import remote
52
56
    """Check how many modules are loaded for some representative scenarios.
53
57
 
54
58
    See the Testing Guide in the developer documentation for more explanation.
 
59
 
 
60
 
 
61
    We must respect the setup used by the selftest command regarding
 
62
    plugins. This allows the user to control which plugins are in effect while
 
63
    running these tests and respect the import policies defined here.
 
64
 
 
65
    When failures are encountered for a given plugin, they can generally be
 
66
    addressed by using lazy import or lazy hook registration.
55
67
    """
56
68
 
57
69
    def setUp(self):
61
73
                     'BZR_PLUGINS_AT', 'HOME'):
62
74
            self.preserved_env_vars[name] = os.environ.get(name)
63
75
        super(TestImportTariffs, self).setUp()
64
 
 
65
 
    def start_bzr_subprocess_with_import_check(self, args):
 
76
        # We don't want to pollute the user's .bzr.log so we define our own.
 
77
        self.log_path = osutils.pathjoin(self.test_home_dir, '.bzr.log')
 
78
        self.overrideEnv('BZR_LOG', self.log_path)
 
79
 
 
80
    def test_log_path_overriden(self):
 
81
        # ensure we get the log file in the right place
 
82
        actual_log_path = trace._get_bzr_log_filename()
 
83
        self.assertStartsWith(actual_log_path, self.test_home_dir)
 
84
        self.assertEquals(self.log_path, actual_log_path)
 
85
 
 
86
 
 
87
    def start_bzr_subprocess_with_import_check(self, args, stderr_file=None):
66
88
        """Run a bzr process and capture the imports.
67
89
 
68
90
        This is fairly expensive because we start a subprocess, so we aim to
79
101
        # explicitly do want to test against things installed there, therefore
80
102
        # we pass it through.
81
103
        env_changes = dict(PYTHONVERBOSE='1', **self.preserved_env_vars)
82
 
        return self.start_bzr_subprocess(args, env_changes=env_changes,
83
 
            allow_plugins=(not are_plugins_disabled()))
 
104
        kwargs = dict(env_changes=env_changes,
 
105
                      allow_plugins=(not are_plugins_disabled()))
 
106
        if stderr_file:
 
107
            # We don't want to update the whole call chain so we insert stderr
 
108
            # *iff* we need to
 
109
            kwargs['stderr'] = stderr_file
 
110
        return self.start_bzr_subprocess(args, **kwargs)
84
111
 
85
112
    def check_forbidden_modules(self, err, forbidden_imports):
86
113
        """Check for forbidden modules in stderr.
187
214
    def test_simple_serve(self):
188
215
        # 'serve' in a default format working tree shouldn't need many modules
189
216
        tree = self.make_branch_and_tree('.')
 
217
        # Capture the bzr serve process' stderr in a file to avoid deadlocks
 
218
        # while the smart client interacts with it.
 
219
        stderr_file = open('bzr-serve.stderr', 'w')
190
220
        process = self.start_bzr_subprocess_with_import_check(['serve',
191
 
            '--inet', '-d', tree.basedir])
 
221
            '--inet', '-d', tree.basedir], stderr_file=stderr_file)
192
222
        url = 'bzr://localhost/'
193
223
        self.permit_url(url)
194
224
        client_medium = medium.SmartSimplePipesClientMedium(
200
230
        process.stdin = None
201
231
        (out, err) = self.finish_bzr_subprocess(process,
202
232
            universal_newlines=False)
 
233
        stderr_file.close()
 
234
        with open('bzr-serve.stderr', 'r') as stderr_file:
 
235
            err = stderr_file.read()
203
236
        self.check_forbidden_modules(err,
204
237
            ['bzrlib.annotate',
205
238
            'bzrlib.atomicfile',