~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_import_tariff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    """
37
37
 
38
38
    def run_command_check_imports(self, args, forbidden_imports):
39
 
        """Run bzr ARGS in a subprocess and check its imports.
40
 
 
41
 
        This is fairly expensive because we start a subprocess, so we aim to
42
 
        cover representative rather than exhaustive cases.
43
 
 
44
 
        :param forbidden_imports: List of fully-qualified Python module names
45
 
            that should not be loaded while running this command.
46
 
        """
47
39
        # We use PYTHON_VERBOSE rather than --profile-importts because in
48
40
        # experimentation the profile-imports output seems to not always show
49
41
        # the modules you'd expect; this can be debugged but python -v seems
55
47
        # explicitly do want to test against things installed there, therefore
56
48
        # we pass it through.
57
49
        env_changes = dict(PYTHONVERBOSE='1')
58
 
        for name in ['BZR_HOME', 'BZR_PLUGIN_PATH',
59
 
                     'BZR_DISABLE_PLUGINS', 'BZR_PLUGINS_AT',
60
 
                     'HOME',]:
 
50
        for name in ['BZR_HOME', 'BZR_PLUGIN_PATH', 'HOME',]:
61
51
            env_changes[name] = self._old_env.get(name)
62
52
        out, err = self.run_bzr_subprocess(args,
63
53
            allow_plugins=(not are_plugins_disabled()),
64
54
            env_changes=env_changes)
65
55
 
66
 
        self.addDetail('subprocess_stderr',
 
56
        self.addDetail('subprocess_stderr', 
67
57
            content.Content(content.ContentType("text", "plain"),
68
58
                lambda:[err]))
69
59
 
73
63
                bad_modules.append(module_name)
74
64
 
75
65
        if bad_modules:
76
 
            self.fail("command %r loaded forbidden modules %r"
 
66
            self.fail("command %r loaded forbidden modules %r" 
77
67
                % (args, bad_modules))
78
68
        return out, err
79
69
 
91
81
    def test_simple_local(self):
92
82
        # 'st' in a working tree shouldn't need many modules
93
83
        self.make_branch_and_tree('.')
94
 
        self.run_command_check_imports(['st'], [
95
 
            'bzrlib.bundle.commands',
96
 
            'bzrlib.cmd_version_info',
97
 
            'bzrlib.foreign',
98
 
            'bzrlib.merge3',
99
 
            'bzrlib.patiencediff',
100
 
            'bzrlib.remote',
101
 
            'bzrlib.sign_my_commits',
102
 
            'bzrlib.smart',
103
 
            'bzrlib.transform',
104
 
            'kerberos',
105
 
            'smtplib',
106
 
            'tarfile',
107
 
            ])
108
 
        # TODO: similar test for repository-only operations, checking we avoid
109
 
        # loading wt-specific stuff
110
 
        #
111
 
        # See https://bugs.launchpad.net/bzr/+bug/553017
 
84
        self.run_command_check_imports(['st'],
 
85
            ['smtplib'])