51
class TestImportTariffs(TestCaseWithTransport):
56
class ImportTariffTestCase(TestCaseWithTransport):
52
57
"""Check how many modules are loaded for some representative scenarios.
54
59
See the Testing Guide in the developer documentation for more explanation.
62
We must respect the setup used by the selftest command regarding
63
plugins. This allows the user to control which plugins are in effect while
64
running these tests and respect the import policies defined here.
66
When failures are encountered for a given plugin, they can generally be
67
addressed by using lazy import or lazy hook registration.
58
# Preserve some env vars as we want to escape the isolation for them
59
71
self.preserved_env_vars = {}
60
for name in ('BZR_HOME', 'BZR_PLUGIN_PATH', 'BZR_DISABLE_PLUGINS',
61
'BZR_PLUGINS_AT', 'HOME'):
72
for name in ('BZR_PLUGIN_PATH', 'BZR_DISABLE_PLUGINS', 'BZR_PLUGINS_AT'
62
74
self.preserved_env_vars[name] = os.environ.get(name)
63
super(TestImportTariffs, self).setUp()
75
super(ImportTariffTestCase, self).setUp()
65
def start_bzr_subprocess_with_import_check(self, args):
77
def start_bzr_subprocess_with_import_check(self, args, stderr_file=None):
66
78
"""Run a bzr process and capture the imports.
68
80
This is fairly expensive because we start a subprocess, so we aim to
69
81
cover representative rather than exhaustive cases.
71
# We use PYTHON_VERBOSE rather than --profile-importts because in
83
# We use PYTHON_VERBOSE rather than --profile-imports because in
72
84
# experimentation the profile-imports output seems to not always show
73
85
# the modules you'd expect; this can be debugged but python -v seems
74
86
# more likely to always show everything. And we use the environment
75
87
# variable rather than 'python -v' in the hope it will work even if
76
88
# bzr is frozen and python is not explicitly specified. -- mbp 20100208
78
# Normally we want test isolation from the real $HOME but here we
79
# explicitly do want to test against things installed there, therefore
81
89
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()))
90
trace.mutter('Setting env for bzr subprocess: %r', env_changes)
91
kwargs = dict(env_changes=env_changes,
92
allow_plugins=(not are_plugins_disabled()))
94
# We don't want to update the whole call chain so we insert stderr
96
kwargs['stderr'] = stderr_file
97
return self.start_bzr_subprocess(args, **kwargs)
85
99
def check_forbidden_modules(self, err, forbidden_imports):
86
100
"""Check for forbidden modules in stderr.
187
205
def test_simple_serve(self):
188
206
# 'serve' in a default format working tree shouldn't need many modules
189
207
tree = self.make_branch_and_tree('.')
208
# Capture the bzr serve process' stderr in a file to avoid deadlocks
209
# while the smart client interacts with it.
210
stderr_file = open('bzr-serve.stderr', 'w')
190
211
process = self.start_bzr_subprocess_with_import_check(['serve',
191
'--inet', '-d', tree.basedir])
212
'--inet', '-d', tree.basedir], stderr_file=stderr_file)
192
213
url = 'bzr://localhost/'
193
214
self.permit_url(url)
194
215
client_medium = medium.SmartSimplePipesClientMedium(