~ubuntu-branches/debian/experimental/bzr/experimental

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_import_tariff.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-03-31 12:03:48 UTC
  • mfrom: (1.1.65 upstream) (9.1.19 sid)
  • Revision ID: james.westby@ubuntu.com-20110331120348-udzyazjjzx8ywahr
Tags: 2.4.0~beta1-1
* New upstream release.
 + Drop patches merged upstream: 01_test_locale, 04_cpu_count,
 05_kfreebsd_tests, 06_format_gc_chk_sha1_record
 + Fixes directory modes in zip files. LP: #207253

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
"""Tests for how many modules are loaded in executing various commands."""
19
19
 
 
20
import os
20
21
from testtools import content
21
22
 
22
23
from bzrlib.plugin import (
29
30
 
30
31
 
31
32
class TestImportTariffs(TestCaseWithTransport):
32
 
 
33
33
    """Check how many modules are loaded for some representative scenarios.
34
34
 
35
35
    See the Testing Guide in the developer documentation for more explanation.
36
36
    """
37
37
 
 
38
    def setUp(self):
 
39
        # Preserve some env vars as we want to escape the isolation for them
 
40
        self.preserved_env_vars = {}
 
41
        for name in ('BZR_HOME', 'BZR_PLUGIN_PATH', 'BZR_DISABLE_PLUGINS',
 
42
                     'BZR_PLUGINS_AT', 'HOME'):
 
43
            self.preserved_env_vars[name] = os.environ.get(name)
 
44
        super(TestImportTariffs, self).setUp()
 
45
 
38
46
    def run_command_check_imports(self, args, forbidden_imports):
39
47
        """Run bzr ARGS in a subprocess and check its imports.
40
48
 
50
58
        # more likely to always show everything.  And we use the environment
51
59
        # variable rather than 'python -v' in the hope it will work even if
52
60
        # bzr is frozen and python is not explicitly specified. -- mbp 20100208
53
 
        #
 
61
 
54
62
        # Normally we want test isolation from the real $HOME but here we
55
63
        # explicitly do want to test against things installed there, therefore
56
64
        # we pass it through.
57
 
        env_changes = dict(PYTHONVERBOSE='1')
58
 
        for name in ['BZR_HOME', 'BZR_PLUGIN_PATH',
59
 
                     'BZR_DISABLE_PLUGINS', 'BZR_PLUGINS_AT',
60
 
                     'HOME',]:
61
 
            env_changes[name] = self._old_env.get(name)
 
65
        env_changes = dict(PYTHONVERBOSE='1', **self.preserved_env_vars)
62
66
        out, err = self.run_bzr_subprocess(args,
63
67
            allow_plugins=(not are_plugins_disabled()),
64
68
            env_changes=env_changes)
89
93
            ['bzrlib.tree'])
90
94
 
91
95
    def test_simple_local(self):
92
 
        # 'st' in a working tree shouldn't need many modules
 
96
        # 'st' in a default format working tree shouldn't need many modules
93
97
        self.make_branch_and_tree('.')
94
98
        self.run_command_check_imports(['st'], [
 
99
            'bzrlib.bugtracker',
95
100
            'bzrlib.bundle.commands',
96
101
            'bzrlib.cmd_version_info',
 
102
            'bzrlib.externalcommand',
97
103
            'bzrlib.foreign',
 
104
            'bzrlib.gpg',
 
105
            'bzrlib.info',
98
106
            'bzrlib.merge3',
 
107
            'bzrlib.merge_directive',
 
108
            'bzrlib.msgeditor',
99
109
            'bzrlib.patiencediff',
100
110
            'bzrlib.remote',
101
111
            'bzrlib.sign_my_commits',
102
112
            'bzrlib.smart',
 
113
            'bzrlib.smart.client',
103
114
            'bzrlib.transform',
 
115
            'bzrlib.version_info_formats.format_rio',
 
116
            'bzrlib.plugins.weave_fmt.branch',
 
117
            'bzrlib.plugins.weave_fmt.bzrdir',
 
118
            'bzrlib.plugins.weave_fmt.repository',
 
119
            'bzrlib.plugins.weave_fmt.workingtree',
 
120
            'bzrlib.weave',
 
121
            'bzrlib.weavefile',
 
122
            'bzrlib.xml4',
 
123
            'bzrlib.xml5',
 
124
            'bzrlib.xml6',
 
125
            'bzrlib.xml7',
104
126
            'kerberos',
105
127
            'smtplib',
106
128
            'tarfile',
109
131
        # loading wt-specific stuff
110
132
        #
111
133
        # See https://bugs.launchpad.net/bzr/+bug/553017
 
134
 
 
135
    def test_help_commands(self):
 
136
        # See https://bugs.launchpad.net/bzr/+bug/663773
 
137
        self.run_command_check_imports(['help', 'commands'], [
 
138
            'testtools',
 
139
            ])