193
193
del bzrlib.plugins.ts_plugin
194
194
self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
196
def test_plugin_with_bad_name_does_not_load(self):
197
# Create badly-named plugin
198
file('bzr-bad plugin-name..py', 'w').close()
196
def load_and_capture(self, name):
197
"""Load plugins from '.' capturing the output.
199
:param name: The name of the plugin.
200
:return: A string with the log from the plugin loading call.
201
203
stream = StringIO()
202
handler = logging.StreamHandler(stream)
203
log = logging.getLogger('bzr')
204
log.addHandler(handler)
206
bzrlib.plugin.load_from_dir('.')
208
# Stop capturing output
211
log.removeHandler(handler)
213
self.assertContainsRe(stream.getvalue(),
205
handler = logging.StreamHandler(stream)
206
log = logging.getLogger('bzr')
207
log.addHandler(handler)
210
bzrlib.plugin.load_from_path(['.'])
212
if 'bzrlib.plugins.%s' % name in sys.modules:
213
del sys.modules['bzrlib.plugins.%s' % name]
214
if getattr(bzrlib.plugins, name, None):
215
delattr(bzrlib.plugins, name)
217
# Stop capturing output
220
log.removeHandler(handler)
221
return stream.getvalue()
225
def test_plugin_with_bad_api_version_reports(self):
226
# This plugin asks for bzrlib api version 1.0.0, which is not supported
231
f.write("import bzrlib.api\n"
232
"bzrlib.api.require_any_api(bzrlib, [(1, 0, 0)])\n")
236
log = self.load_and_capture(name)
237
self.assertContainsRe(log,
238
r"It requested API version")
240
def test_plugin_with_bad_name_does_not_load(self):
241
# The file name here invalid for a python module.
242
name = 'bzr-bad plugin-name..py'
243
file(name, 'w').close()
244
log = self.load_and_capture(name)
245
self.assertContainsRe(log,
214
246
r"Unable to load 'bzr-bad plugin-name\.' in '\.' as a plugin "
215
247
"because the file path isn't a valid module name; try renaming "
216
248
"it to 'bad_plugin_name_'\.")
221
251
class TestPlugins(TestCaseInTempDir):