~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

(jelmer) Support upgrading between the 2a and development-colo formats.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for plugins"""
18
18
 
20
20
# affects the global state of the process.  See bzrlib/plugins.py for more
21
21
# comments.
22
22
 
 
23
from cStringIO import StringIO
23
24
import logging
24
25
import os
25
 
from StringIO import StringIO
26
26
import sys
27
 
import zipfile
28
 
 
29
 
from bzrlib import plugin, tests
30
 
import bzrlib.plugin
31
 
import bzrlib.plugins
32
 
import bzrlib.commands
33
 
import bzrlib.help
34
 
from bzrlib.symbol_versioning import one_three
35
 
from bzrlib.tests import TestCase, TestCaseInTempDir
36
 
from bzrlib.osutils import pathjoin, abspath, normpath
37
 
 
38
 
 
39
 
PLUGIN_TEXT = """\
40
 
import bzrlib.commands
41
 
class cmd_myplug(bzrlib.commands.Command):
42
 
    '''Just a simple test plugin.'''
43
 
    aliases = ['mplg']
44
 
    def run(self):
45
 
        print 'Hello from my plugin'
46
 
"""
 
27
 
 
28
import bzrlib
 
29
from bzrlib import (
 
30
    errors,
 
31
    osutils,
 
32
    plugin,
 
33
    plugins,
 
34
    tests,
 
35
    trace,
 
36
    )
 
37
 
47
38
 
48
39
# TODO: Write a test for plugin decoration of commands.
49
40
 
50
 
class TestLoadingPlugins(TestCaseInTempDir):
 
41
class BaseTestPlugins(tests.TestCaseInTempDir):
 
42
 
 
43
    def create_plugin(self, name, source=None, dir='.', file_name=None):
 
44
        if source is None:
 
45
            source = '''\
 
46
"""This is the doc for %s"""
 
47
''' % (name)
 
48
        if file_name is None:
 
49
            file_name = name + '.py'
 
50
        # 'source' must not fail to load
 
51
        path = osutils.pathjoin(dir, file_name)
 
52
        f = open(path, 'w')
 
53
        self.addCleanup(os.unlink, path)
 
54
        try:
 
55
            f.write(source + '\n')
 
56
        finally:
 
57
            f.close()
 
58
 
 
59
    def create_plugin_package(self, name, dir=None, source=None):
 
60
        if dir is None:
 
61
            dir = name
 
62
        if source is None:
 
63
            source = '''\
 
64
"""This is the doc for %s"""
 
65
dir_source = '%s'
 
66
''' % (name, dir)
 
67
        os.makedirs(dir)
 
68
        def cleanup():
 
69
            # Workaround lazy import random? madness
 
70
            osutils.rmtree(dir)
 
71
        self.addCleanup(cleanup)
 
72
        self.create_plugin(name, source, dir,
 
73
                           file_name='__init__.py')
 
74
 
 
75
    def _unregister_plugin(self, name):
 
76
        """Remove the plugin from sys.modules and the bzrlib namespace."""
 
77
        py_name = 'bzrlib.plugins.%s' % name
 
78
        if py_name in sys.modules:
 
79
            del sys.modules[py_name]
 
80
        if getattr(bzrlib.plugins, name, None) is not None:
 
81
            delattr(bzrlib.plugins, name)
 
82
 
 
83
    def _unregister_plugin_submodule(self, plugin_name, submodule_name):
 
84
        """Remove the submodule from sys.modules and the bzrlib namespace."""
 
85
        py_name = 'bzrlib.plugins.%s.%s' % (plugin_name, submodule_name)
 
86
        if py_name in sys.modules:
 
87
            del sys.modules[py_name]
 
88
        plugin = getattr(bzrlib.plugins, plugin_name, None)
 
89
        if plugin is not None:
 
90
            if getattr(plugin, submodule_name, None) is not None:
 
91
                delattr(plugin, submodule_name)
 
92
 
 
93
    def assertPluginUnknown(self, name):
 
94
        self.assertFalse(getattr(bzrlib.plugins, name, None) is not None)
 
95
        self.assertFalse('bzrlib.plugins.%s' % name in sys.modules)
 
96
 
 
97
    def assertPluginKnown(self, name):
 
98
        self.assertTrue(getattr(bzrlib.plugins, name, None) is not None)
 
99
        self.assertTrue('bzrlib.plugins.%s' % name in sys.modules)
 
100
 
 
101
 
 
102
class TestLoadingPlugins(BaseTestPlugins):
51
103
 
52
104
    activeattributes = {}
53
105
 
57
109
        # file name we can use which is also a valid attribute for accessing in
58
110
        # activeattributes. - we cannot give import parameters.
59
111
        tempattribute = "0"
60
 
        self.failIf(tempattribute in self.activeattributes)
 
112
        self.assertFalse(tempattribute in self.activeattributes)
61
113
        # set a place for the plugins to record their loading, and at the same
62
114
        # time validate that the location the plugins should record to is
63
115
        # valid and correct.
64
 
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
65
 
            [tempattribute] = []
66
 
        self.failUnless(tempattribute in self.activeattributes)
 
116
        self.__class__.activeattributes [tempattribute] = []
 
117
        self.assertTrue(tempattribute in self.activeattributes)
67
118
        # create two plugin directories
68
119
        os.mkdir('first')
69
120
        os.mkdir('second')
70
 
        # write a plugin that will record when its loaded in the 
 
121
        # write a plugin that will record when its loaded in the
71
122
        # tempattribute list.
72
123
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
73
124
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
92
143
        finally:
93
144
            # remove the plugin 'plugin'
94
145
            del self.activeattributes[tempattribute]
95
 
            if 'bzrlib.plugins.plugin' in sys.modules:
96
 
                del sys.modules['bzrlib.plugins.plugin']
97
 
            if getattr(bzrlib.plugins, 'plugin', None):
98
 
                del bzrlib.plugins.plugin
99
 
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
 
146
            self._unregister_plugin('plugin')
 
147
        self.assertPluginUnknown('plugin')
100
148
 
101
149
    def test_plugins_from_different_dirs_can_demand_load(self):
 
150
        self.assertFalse('bzrlib.plugins.pluginone' in sys.modules)
 
151
        self.assertFalse('bzrlib.plugins.plugintwo' in sys.modules)
102
152
        # This test tests that having two plugins in different
103
153
        # directories with different names allows them both to be loaded, when
104
154
        # we do a direct import statement.
105
155
        # Determine a file name we can use which is also a valid attribute
106
156
        # for accessing in activeattributes. - we cannot give import parameters.
107
157
        tempattribute = "different-dirs"
108
 
        self.failIf(tempattribute in self.activeattributes)
 
158
        self.assertFalse(tempattribute in self.activeattributes)
109
159
        # set a place for the plugins to record their loading, and at the same
110
160
        # time validate that the location the plugins should record to is
111
161
        # valid and correct.
112
162
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
113
163
            [tempattribute] = []
114
 
        self.failUnless(tempattribute in self.activeattributes)
 
164
        self.assertTrue(tempattribute in self.activeattributes)
115
165
        # create two plugin directories
116
166
        os.mkdir('first')
117
167
        os.mkdir('second')
118
 
        # write plugins that will record when they are loaded in the 
 
168
        # write plugins that will record when they are loaded in the
119
169
        # tempattribute list.
120
170
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
121
171
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
136
186
 
137
187
        oldpath = bzrlib.plugins.__path__
138
188
        try:
 
189
            self.assertFalse('bzrlib.plugins.pluginone' in sys.modules)
 
190
            self.assertFalse('bzrlib.plugins.plugintwo' in sys.modules)
139
191
            bzrlib.plugins.__path__ = ['first', 'second']
140
192
            exec "import bzrlib.plugins.pluginone"
141
193
            self.assertEqual(['first'], self.activeattributes[tempattribute])
145
197
        finally:
146
198
            # remove the plugin 'plugin'
147
199
            del self.activeattributes[tempattribute]
148
 
            if getattr(bzrlib.plugins, 'pluginone', None):
149
 
                del bzrlib.plugins.pluginone
150
 
            if getattr(bzrlib.plugins, 'plugintwo', None):
151
 
                del bzrlib.plugins.plugintwo
152
 
        self.failIf(getattr(bzrlib.plugins, 'pluginone', None))
153
 
        self.failIf(getattr(bzrlib.plugins, 'plugintwo', None))
 
200
            self._unregister_plugin('pluginone')
 
201
            self._unregister_plugin('plugintwo')
 
202
        self.assertPluginUnknown('pluginone')
 
203
        self.assertPluginUnknown('plugintwo')
154
204
 
155
205
    def test_plugins_can_load_from_directory_with_trailing_slash(self):
156
206
        # This test tests that a plugin can load from a directory when the
157
207
        # directory in the path has a trailing slash.
158
208
        # check the plugin is not loaded already
159
 
        self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
 
209
        self.assertPluginUnknown('ts_plugin')
160
210
        tempattribute = "trailing-slash"
161
 
        self.failIf(tempattribute in self.activeattributes)
 
211
        self.assertFalse(tempattribute in self.activeattributes)
162
212
        # set a place for the plugin to record its loading, and at the same
163
213
        # time validate that the location the plugin should record to is
164
214
        # valid and correct.
165
215
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
166
216
            [tempattribute] = []
167
 
        self.failUnless(tempattribute in self.activeattributes)
 
217
        self.assertTrue(tempattribute in self.activeattributes)
168
218
        # create a directory for the plugin
169
219
        os.mkdir('plugin_test')
170
 
        # write a plugin that will record when its loaded in the 
 
220
        # write a plugin that will record when its loaded in the
171
221
        # tempattribute list.
172
222
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
173
223
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
183
233
            bzrlib.plugin.load_from_path(['plugin_test'+os.sep])
184
234
            self.assertEqual(['plugin'], self.activeattributes[tempattribute])
185
235
        finally:
186
 
            # remove the plugin 'plugin'
187
236
            del self.activeattributes[tempattribute]
188
 
            if getattr(bzrlib.plugins, 'ts_plugin', None):
189
 
                del bzrlib.plugins.ts_plugin
190
 
        self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
191
 
 
192
 
    def test_plugin_with_bad_name_does_not_load(self):
193
 
        # Create badly-named plugin
194
 
        file('bad plugin-name..py', 'w').close()
195
 
 
 
237
            self._unregister_plugin('ts_plugin')
 
238
        self.assertPluginUnknown('ts_plugin')
 
239
 
 
240
    def load_and_capture(self, name):
 
241
        """Load plugins from '.' capturing the output.
 
242
 
 
243
        :param name: The name of the plugin.
 
244
        :return: A string with the log from the plugin loading call.
 
245
        """
196
246
        # Capture output
197
247
        stream = StringIO()
198
 
        handler = logging.StreamHandler(stream)
199
 
        log = logging.getLogger('bzr')
200
 
        log.addHandler(handler)
201
 
 
202
 
        bzrlib.plugin.load_from_dir('.')
203
 
 
204
 
        # Stop capturing output
205
 
        handler.flush()
206
 
        handler.close()
207
 
        log.removeHandler(handler)
208
 
 
209
 
        self.assertContainsRe(stream.getvalue(),
210
 
            r"Unable to load 'bad plugin-name\.' in '\.' as a plugin because"
211
 
            " file path isn't a valid module name; try renaming it to"
212
 
            " 'bad_plugin_name_'\.")
213
 
 
214
 
        stream.close()
215
 
 
216
 
 
217
 
class TestPlugins(TestCaseInTempDir):
 
248
        try:
 
249
            handler = logging.StreamHandler(stream)
 
250
            log = logging.getLogger('bzr')
 
251
            log.addHandler(handler)
 
252
            try:
 
253
                try:
 
254
                    bzrlib.plugin.load_from_path(['.'])
 
255
                finally:
 
256
                    if 'bzrlib.plugins.%s' % name in sys.modules:
 
257
                        del sys.modules['bzrlib.plugins.%s' % name]
 
258
                    if getattr(bzrlib.plugins, name, None):
 
259
                        delattr(bzrlib.plugins, name)
 
260
            finally:
 
261
                # Stop capturing output
 
262
                handler.flush()
 
263
                handler.close()
 
264
                log.removeHandler(handler)
 
265
            return stream.getvalue()
 
266
        finally:
 
267
            stream.close()
 
268
 
 
269
    def test_plugin_with_bad_api_version_reports(self):
 
270
        """Try loading a plugin that requests an unsupported api.
 
271
        
 
272
        Observe that it records the problem but doesn't complain on stderr.
 
273
 
 
274
        See https://bugs.launchpad.net/bzr/+bug/704195
 
275
        """
 
276
        self.overrideAttr(plugin, 'plugin_warnings', {})
 
277
        name = 'wants100.py'
 
278
        f = file(name, 'w')
 
279
        try:
 
280
            f.write("import bzrlib.api\n"
 
281
                "bzrlib.api.require_any_api(bzrlib, [(1, 0, 0)])\n")
 
282
        finally:
 
283
            f.close()
 
284
        log = self.load_and_capture(name)
 
285
        self.assertNotContainsRe(log,
 
286
            r"It requested API version")
 
287
        self.assertEquals(
 
288
            ['wants100'],
 
289
            plugin.plugin_warnings.keys())
 
290
        self.assertContainsRe(
 
291
            plugin.plugin_warnings['wants100'][0],
 
292
            r"It requested API version")
 
293
 
 
294
    def test_plugin_with_bad_name_does_not_load(self):
 
295
        # The file name here invalid for a python module.
 
296
        name = 'bzr-bad plugin-name..py'
 
297
        file(name, 'w').close()
 
298
        log = self.load_and_capture(name)
 
299
        self.assertContainsRe(log,
 
300
            r"Unable to load 'bzr-bad plugin-name\.' in '\.' as a plugin "
 
301
            "because the file path isn't a valid module name; try renaming "
 
302
            "it to 'bad_plugin_name_'\.")
 
303
 
 
304
 
 
305
class TestPlugins(BaseTestPlugins):
218
306
 
219
307
    def setup_plugin(self, source=""):
220
308
        # This test tests a new plugin appears in bzrlib.plugin.plugins().
221
309
        # check the plugin is not loaded already
222
 
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
 
310
        self.assertPluginUnknown('plugin')
223
311
        # write a plugin that _cannot_ fail to load.
224
312
        file('plugin.py', 'w').write(source + '\n')
225
313
        self.addCleanup(self.teardown_plugin)
226
 
        bzrlib.plugin.load_from_path(['.'])
227
 
    
 
314
        plugin.load_from_path(['.'])
 
315
 
228
316
    def teardown_plugin(self):
229
 
        # remove the plugin 'plugin'
230
 
        if 'bzrlib.plugins.plugin' in sys.modules:
231
 
            del sys.modules['bzrlib.plugins.plugin']
232
 
        if getattr(bzrlib.plugins, 'plugin', None):
233
 
            del bzrlib.plugins.plugin
234
 
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
 
317
        self._unregister_plugin('plugin')
 
318
        self.assertPluginUnknown('plugin')
235
319
 
236
320
    def test_plugin_appears_in_plugins(self):
237
321
        self.setup_plugin()
238
 
        self.failUnless('plugin' in bzrlib.plugin.plugins())
239
 
        self.failUnless(getattr(bzrlib.plugins, 'plugin', None))
240
 
        plugins = bzrlib.plugin.plugins()
241
 
        plugin = plugins['plugin']
242
 
        self.assertIsInstance(plugin, bzrlib.plugin.PlugIn)
243
 
        self.assertEqual(bzrlib.plugins.plugin, plugin.module)
 
322
        self.assertPluginKnown('plugin')
 
323
        p = plugin.plugins()['plugin']
 
324
        self.assertIsInstance(p, bzrlib.plugin.PlugIn)
 
325
        self.assertEqual(p.module, plugins.plugin)
244
326
 
245
327
    def test_trivial_plugin_get_path(self):
246
328
        self.setup_plugin()
247
 
        plugins = bzrlib.plugin.plugins()
248
 
        plugin = plugins['plugin']
 
329
        p = plugin.plugins()['plugin']
249
330
        plugin_path = self.test_dir + '/plugin.py'
250
 
        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
 
331
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
251
332
 
252
333
    def test_plugin_get_path_py_not_pyc(self):
253
 
        self.setup_plugin()         # after first import there will be plugin.pyc
 
334
        # first import creates plugin.pyc
 
335
        self.setup_plugin()
254
336
        self.teardown_plugin()
255
 
        bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
256
 
        plugins = bzrlib.plugin.plugins()
257
 
        plugin = plugins['plugin']
 
337
        plugin.load_from_path(['.']) # import plugin.pyc
 
338
        p = plugin.plugins()['plugin']
258
339
        plugin_path = self.test_dir + '/plugin.py'
259
 
        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
 
340
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
260
341
 
261
342
    def test_plugin_get_path_pyc_only(self):
262
 
        self.setup_plugin()         # after first import there will be plugin.pyc
 
343
        # first import creates plugin.pyc (or plugin.pyo depending on __debug__)
 
344
        self.setup_plugin()
263
345
        self.teardown_plugin()
264
346
        os.unlink(self.test_dir + '/plugin.py')
265
 
        bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
266
 
        plugins = bzrlib.plugin.plugins()
267
 
        plugin = plugins['plugin']
 
347
        plugin.load_from_path(['.']) # import plugin.pyc (or .pyo)
 
348
        p = plugin.plugins()['plugin']
268
349
        if __debug__:
269
350
            plugin_path = self.test_dir + '/plugin.pyc'
270
351
        else:
271
352
            plugin_path = self.test_dir + '/plugin.pyo'
272
 
        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
 
353
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
273
354
 
274
355
    def test_no_test_suite_gives_None_for_test_suite(self):
275
356
        self.setup_plugin()
276
 
        plugin = bzrlib.plugin.plugins()['plugin']
277
 
        self.assertEqual(None, plugin.test_suite())
 
357
        p = plugin.plugins()['plugin']
 
358
        self.assertEqual(None, p.test_suite())
278
359
 
279
360
    def test_test_suite_gives_test_suite_result(self):
280
361
        source = """def test_suite(): return 'foo'"""
281
362
        self.setup_plugin(source)
282
 
        plugin = bzrlib.plugin.plugins()['plugin']
283
 
        self.assertEqual('foo', plugin.test_suite())
 
363
        p = plugin.plugins()['plugin']
 
364
        self.assertEqual('foo', p.test_suite())
 
365
 
 
366
    def test_no_load_plugin_tests_gives_None_for_load_plugin_tests(self):
 
367
        self.setup_plugin()
 
368
        loader = tests.TestUtil.TestLoader()
 
369
        p = plugin.plugins()['plugin']
 
370
        self.assertEqual(None, p.load_plugin_tests(loader))
 
371
 
 
372
    def test_load_plugin_tests_gives_load_plugin_tests_result(self):
 
373
        source = """
 
374
def load_tests(standard_tests, module, loader):
 
375
    return 'foo'"""
 
376
        self.setup_plugin(source)
 
377
        loader = tests.TestUtil.TestLoader()
 
378
        p = plugin.plugins()['plugin']
 
379
        self.assertEqual('foo', p.load_plugin_tests(loader))
 
380
 
 
381
    def check_version_info(self, expected, source='', name='plugin'):
 
382
        self.setup_plugin(source)
 
383
        self.assertEqual(expected, plugin.plugins()[name].version_info())
284
384
 
285
385
    def test_no_version_info(self):
286
 
        self.setup_plugin()
287
 
        plugin = bzrlib.plugin.plugins()['plugin']
288
 
        self.assertEqual(None, plugin.version_info())
 
386
        self.check_version_info(None)
289
387
 
290
388
    def test_with_version_info(self):
291
 
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)")
292
 
        plugin = bzrlib.plugin.plugins()['plugin']
293
 
        self.assertEqual((1, 2, 3, 'dev', 4), plugin.version_info())
 
389
        self.check_version_info((1, 2, 3, 'dev', 4),
 
390
                                "version_info = (1, 2, 3, 'dev', 4)")
294
391
 
295
392
    def test_short_version_info_gets_padded(self):
296
393
        # the gtk plugin has version_info = (1,2,3) rather than the 5-tuple.
297
394
        # so we adapt it
298
 
        self.setup_plugin("version_info = (1, 2, 3)")
299
 
        plugin = bzrlib.plugin.plugins()['plugin']
300
 
        self.assertEqual((1, 2, 3, 'final', 0), plugin.version_info())
 
395
        self.check_version_info((1, 2, 3, 'final', 0),
 
396
                                "version_info = (1, 2, 3)")
 
397
 
 
398
    def check_version(self, expected, source=None, name='plugin'):
 
399
        self.setup_plugin(source)
 
400
        self.assertEqual(expected, plugins[name].__version__)
301
401
 
302
402
    def test_no_version_info___version__(self):
303
403
        self.setup_plugin()
304
404
        plugin = bzrlib.plugin.plugins()['plugin']
305
405
        self.assertEqual("unknown", plugin.__version__)
306
406
 
307
 
    def test___version__with_version_info(self):
 
407
    def test_str__version__with_version_info(self):
 
408
        self.setup_plugin("version_info = '1.2.3'")
 
409
        plugin = bzrlib.plugin.plugins()['plugin']
 
410
        self.assertEqual("1.2.3", plugin.__version__)
 
411
 
 
412
    def test_noniterable__version__with_version_info(self):
 
413
        self.setup_plugin("version_info = (1)")
 
414
        plugin = bzrlib.plugin.plugins()['plugin']
 
415
        self.assertEqual("1", plugin.__version__)
 
416
 
 
417
    def test_1__version__with_version_info(self):
 
418
        self.setup_plugin("version_info = (1,)")
 
419
        plugin = bzrlib.plugin.plugins()['plugin']
 
420
        self.assertEqual("1", plugin.__version__)
 
421
 
 
422
    def test_1_2__version__with_version_info(self):
 
423
        self.setup_plugin("version_info = (1, 2)")
 
424
        plugin = bzrlib.plugin.plugins()['plugin']
 
425
        self.assertEqual("1.2", plugin.__version__)
 
426
 
 
427
    def test_1_2_3__version__with_version_info(self):
 
428
        self.setup_plugin("version_info = (1, 2, 3)")
 
429
        plugin = bzrlib.plugin.plugins()['plugin']
 
430
        self.assertEqual("1.2.3", plugin.__version__)
 
431
 
 
432
    def test_candidate__version__with_version_info(self):
 
433
        self.setup_plugin("version_info = (1, 2, 3, 'candidate', 1)")
 
434
        plugin = bzrlib.plugin.plugins()['plugin']
 
435
        self.assertEqual("1.2.3rc1", plugin.__version__)
 
436
 
 
437
    def test_dev__version__with_version_info(self):
 
438
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 0)")
 
439
        plugin = bzrlib.plugin.plugins()['plugin']
 
440
        self.assertEqual("1.2.3dev", plugin.__version__)
 
441
 
 
442
    def test_dev_fallback__version__with_version_info(self):
308
443
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)")
309
444
        plugin = bzrlib.plugin.plugins()['plugin']
310
445
        self.assertEqual("1.2.3dev4", plugin.__version__)
311
446
 
312
447
    def test_final__version__with_version_info(self):
313
 
        self.setup_plugin("version_info = (1, 2, 3, 'final', 4)")
 
448
        self.setup_plugin("version_info = (1, 2, 3, 'final', 0)")
314
449
        plugin = bzrlib.plugin.plugins()['plugin']
315
450
        self.assertEqual("1.2.3", plugin.__version__)
316
451
 
317
 
 
318
 
class TestPluginHelp(TestCaseInTempDir):
 
452
    def test_final_fallback__version__with_version_info(self):
 
453
        self.setup_plugin("version_info = (1, 2, 3, 'final', 2)")
 
454
        plugin = bzrlib.plugin.plugins()['plugin']
 
455
        self.assertEqual("1.2.3.2", plugin.__version__)
 
456
 
 
457
 
 
458
class TestPluginHelp(tests.TestCaseInTempDir):
319
459
 
320
460
    def split_help_commands(self):
321
461
        help = {}
322
462
        current = None
323
 
        for line in self.run_bzr('help commands')[0].splitlines():
 
463
        out, err = self.run_bzr('--no-plugins help commands')
 
464
        for line in out.splitlines():
324
465
            if not line.startswith(' '):
325
466
                current = line.split()[0]
326
467
            help[current] = help.get(current, '') + line
349
490
    def test_plugin_help_shows_plugin(self):
350
491
        # Create a test plugin
351
492
        os.mkdir('plugin_test')
352
 
        f = open(pathjoin('plugin_test', 'myplug.py'), 'w')
353
 
        f.write(PLUGIN_TEXT)
 
493
        f = open(osutils.pathjoin('plugin_test', 'myplug.py'), 'w')
 
494
        f.write("""\
 
495
from bzrlib import commands
 
496
class cmd_myplug(commands.Command):
 
497
    __doc__ = '''Just a simple test plugin.'''
 
498
    aliases = ['mplg']
 
499
    def run(self):
 
500
        print 'Hello from my plugin'
 
501
 
 
502
"""
 
503
)
354
504
        f.close()
355
505
 
356
506
        try:
363
513
            self.assertContainsRe(help, '\[myplug\]')
364
514
        finally:
365
515
            # unregister command
366
 
            if bzrlib.commands.plugin_cmds.get('myplug', None):
367
 
                del bzrlib.commands.plugin_cmds['myplug']
 
516
            if 'myplug' in bzrlib.commands.plugin_cmds:
 
517
                bzrlib.commands.plugin_cmds.remove('myplug')
368
518
            # remove the plugin 'myplug'
369
519
            if getattr(bzrlib.plugins, 'myplug', None):
370
520
                delattr(bzrlib.plugins, 'myplug')
371
521
 
372
522
 
373
 
class TestPluginFromZip(TestCaseInTempDir):
374
 
 
375
 
    def make_zipped_plugin(self, zip_name, filename):
376
 
        z = zipfile.ZipFile(zip_name, 'w')
377
 
        z.writestr(filename, PLUGIN_TEXT)
378
 
        z.close()
379
 
 
380
 
    def check_plugin_load(self, zip_name, plugin_name):
381
 
        self.assertFalse(plugin_name in dir(bzrlib.plugins),
382
 
                         'Plugin already loaded')
383
 
        old_path = bzrlib.plugins.__path__
384
 
        try:
385
 
            # this is normally done by load_plugins -> set_plugins_path
386
 
            bzrlib.plugins.__path__ = [zip_name]
387
 
            self.applyDeprecated(one_three,
388
 
                bzrlib.plugin.load_from_zip, zip_name)
389
 
            self.assertTrue(plugin_name in dir(bzrlib.plugins),
390
 
                            'Plugin is not loaded')
391
 
        finally:
392
 
            # unregister plugin
393
 
            if getattr(bzrlib.plugins, plugin_name, None):
394
 
                delattr(bzrlib.plugins, plugin_name)
395
 
                del sys.modules['bzrlib.plugins.' + plugin_name]
396
 
            bzrlib.plugins.__path__ = old_path
397
 
 
398
 
    def test_load_module(self):
399
 
        self.make_zipped_plugin('./test.zip', 'ziplug.py')
400
 
        self.check_plugin_load('./test.zip', 'ziplug')
401
 
 
402
 
    def test_load_package(self):
403
 
        self.make_zipped_plugin('./test.zip', 'ziplug/__init__.py')
404
 
        self.check_plugin_load('./test.zip', 'ziplug')
405
 
 
406
 
 
407
 
class TestSetPluginsPath(TestCase):
408
 
    
409
 
    def test_set_plugins_path(self):
410
 
        """set_plugins_path should set the module __path__ correctly."""
411
 
        old_path = bzrlib.plugins.__path__
412
 
        try:
413
 
            bzrlib.plugins.__path__ = []
414
 
            expected_path = bzrlib.plugin.set_plugins_path()
415
 
            self.assertEqual(expected_path, bzrlib.plugins.__path__)
416
 
        finally:
417
 
            bzrlib.plugins.__path__ = old_path
418
 
 
419
 
    def test_set_plugins_path_with_trailing_slashes(self):
420
 
        """set_plugins_path should set the module __path__ based on
421
 
        BZR_PLUGIN_PATH."""
422
 
        old_path = bzrlib.plugins.__path__
423
 
        old_env = os.environ.get('BZR_PLUGIN_PATH')
424
 
        try:
425
 
            bzrlib.plugins.__path__ = []
426
 
            os.environ['BZR_PLUGIN_PATH'] = "first\\//\\" + os.pathsep + \
427
 
                "second/\\/\\/"
428
 
            bzrlib.plugin.set_plugins_path()
429
 
            expected_path = ['first', 'second',
430
 
                os.path.dirname(bzrlib.plugins.__file__)]
431
 
            self.assertEqual(expected_path, bzrlib.plugins.__path__)
432
 
        finally:
433
 
            bzrlib.plugins.__path__ = old_path
434
 
            if old_env != None:
435
 
                os.environ['BZR_PLUGIN_PATH'] = old_env
436
 
            else:
437
 
                del os.environ['BZR_PLUGIN_PATH']
438
 
 
439
523
class TestHelpIndex(tests.TestCase):
440
524
    """Tests for the PluginsHelpIndex class."""
441
525
 
531
615
    def test_get_help_text_with_additional_see_also(self):
532
616
        mod = FakeModule('two lines of help\nand more', 'demo')
533
617
        topic = plugin.ModuleHelpTopic(mod)
534
 
        self.assertEqual("two lines of help\nand more\nSee also: bar, foo\n",
535
 
            topic.get_help_text(['foo', 'bar']))
 
618
        self.assertEqual("two lines of help\nand more\n\n:See also: bar, foo\n",
 
619
                         topic.get_help_text(['foo', 'bar']))
536
620
 
537
621
    def test_get_help_topic(self):
538
622
        """The help topic for a plugin is its module name."""
539
623
        mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.demo')
540
624
        topic = plugin.ModuleHelpTopic(mod)
541
625
        self.assertEqual('demo', topic.get_help_topic())
542
 
        mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.foo_bar')
 
626
        mod = FakeModule('two lines of help\nand more',
 
627
                         'bzrlib.plugins.foo_bar')
543
628
        topic = plugin.ModuleHelpTopic(mod)
544
629
        self.assertEqual('foo_bar', topic.get_help_topic())
 
630
 
 
631
 
 
632
class TestLoadFromPath(tests.TestCaseInTempDir):
 
633
 
 
634
    def setUp(self):
 
635
        super(TestLoadFromPath, self).setUp()
 
636
        # Change bzrlib.plugin to think no plugins have been loaded yet.
 
637
        self.overrideAttr(bzrlib.plugins, '__path__', [])
 
638
        self.overrideAttr(plugin, '_loaded', False)
 
639
 
 
640
        # Monkey-patch load_from_path to stop it from actually loading anything.
 
641
        self.overrideAttr(plugin, 'load_from_path', lambda dirs: None)
 
642
 
 
643
    def test_set_plugins_path_with_args(self):
 
644
        plugin.set_plugins_path(['a', 'b'])
 
645
        self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
 
646
 
 
647
    def test_set_plugins_path_defaults(self):
 
648
        plugin.set_plugins_path()
 
649
        self.assertEqual(plugin.get_standard_plugins_path(),
 
650
                         bzrlib.plugins.__path__)
 
651
 
 
652
    def test_get_standard_plugins_path(self):
 
653
        path = plugin.get_standard_plugins_path()
 
654
        for directory in path:
 
655
            self.assertNotContainsRe(directory, r'\\/$')
 
656
        try:
 
657
            from distutils.sysconfig import get_python_lib
 
658
        except ImportError:
 
659
            pass
 
660
        else:
 
661
            if sys.platform != 'win32':
 
662
                python_lib = get_python_lib()
 
663
                for directory in path:
 
664
                    if directory.startswith(python_lib):
 
665
                        break
 
666
                else:
 
667
                    self.fail('No path to global plugins')
 
668
 
 
669
    def test_get_standard_plugins_path_env(self):
 
670
        self.overrideEnv('BZR_PLUGIN_PATH', 'foo/')
 
671
        path = plugin.get_standard_plugins_path()
 
672
        for directory in path:
 
673
            self.assertNotContainsRe(directory, r'\\/$')
 
674
 
 
675
    def test_load_plugins(self):
 
676
        plugin.load_plugins(['.'])
 
677
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
 
678
        # subsequent loads are no-ops
 
679
        plugin.load_plugins(['foo'])
 
680
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
 
681
 
 
682
    def test_load_plugins_default(self):
 
683
        plugin.load_plugins()
 
684
        path = plugin.get_standard_plugins_path()
 
685
        self.assertEqual(path, bzrlib.plugins.__path__)
 
686
 
 
687
 
 
688
class TestEnvPluginPath(tests.TestCase):
 
689
 
 
690
    def setUp(self):
 
691
        super(TestEnvPluginPath, self).setUp()
 
692
        self.overrideAttr(plugin, 'DEFAULT_PLUGIN_PATH', None)
 
693
 
 
694
        self.user = plugin.get_user_plugin_path()
 
695
        self.site = plugin.get_site_plugin_path()
 
696
        self.core = plugin.get_core_plugin_path()
 
697
 
 
698
    def _list2paths(self, *args):
 
699
        paths = []
 
700
        for p in args:
 
701
            plugin._append_new_path(paths, p)
 
702
        return paths
 
703
 
 
704
    def _set_path(self, *args):
 
705
        path = os.pathsep.join(self._list2paths(*args))
 
706
        self.overrideEnv('BZR_PLUGIN_PATH', path)
 
707
 
 
708
    def check_path(self, expected_dirs, setting_dirs):
 
709
        if setting_dirs:
 
710
            self._set_path(*setting_dirs)
 
711
        actual = plugin.get_standard_plugins_path()
 
712
        self.assertEquals(self._list2paths(*expected_dirs), actual)
 
713
 
 
714
    def test_default(self):
 
715
        self.check_path([self.user, self.core, self.site],
 
716
                        None)
 
717
 
 
718
    def test_adhoc_policy(self):
 
719
        self.check_path([self.user, self.core, self.site],
 
720
                        ['+user', '+core', '+site'])
 
721
 
 
722
    def test_fallback_policy(self):
 
723
        self.check_path([self.core, self.site, self.user],
 
724
                        ['+core', '+site', '+user'])
 
725
 
 
726
    def test_override_policy(self):
 
727
        self.check_path([self.user, self.site, self.core],
 
728
                        ['+user', '+site', '+core'])
 
729
 
 
730
    def test_disable_user(self):
 
731
        self.check_path([self.core, self.site], ['-user'])
 
732
 
 
733
    def test_disable_user_twice(self):
 
734
        # Ensures multiple removals don't left cruft
 
735
        self.check_path([self.core, self.site], ['-user', '-user'])
 
736
 
 
737
    def test_duplicates_are_removed(self):
 
738
        self.check_path([self.user, self.core, self.site],
 
739
                        ['+user', '+user'])
 
740
        # And only the first reference is kept (since the later references will
 
741
        # only produce '<plugin> already loaded' mutters)
 
742
        self.check_path([self.user, self.core, self.site],
 
743
                        ['+user', '+user', '+core',
 
744
                         '+user', '+site', '+site',
 
745
                         '+core'])
 
746
 
 
747
    def test_disable_overrides_enable(self):
 
748
        self.check_path([self.core, self.site], ['-user', '+user'])
 
749
 
 
750
    def test_disable_core(self):
 
751
        self.check_path([self.site], ['-core'])
 
752
        self.check_path([self.user, self.site], ['+user', '-core'])
 
753
 
 
754
    def test_disable_site(self):
 
755
        self.check_path([self.core], ['-site'])
 
756
        self.check_path([self.user, self.core], ['-site', '+user'])
 
757
 
 
758
    def test_override_site(self):
 
759
        self.check_path(['mysite', self.user, self.core],
 
760
                        ['mysite', '-site', '+user'])
 
761
        self.check_path(['mysite', self.core],
 
762
                        ['mysite', '-site'])
 
763
 
 
764
    def test_override_core(self):
 
765
        self.check_path(['mycore', self.user, self.site],
 
766
                        ['mycore', '-core', '+user', '+site'])
 
767
        self.check_path(['mycore', self.site],
 
768
                        ['mycore', '-core'])
 
769
 
 
770
    def test_my_plugin_only(self):
 
771
        self.check_path(['myplugin'], ['myplugin', '-user', '-core', '-site'])
 
772
 
 
773
    def test_my_plugin_first(self):
 
774
        self.check_path(['myplugin', self.core, self.site, self.user],
 
775
                        ['myplugin', '+core', '+site', '+user'])
 
776
 
 
777
    def test_bogus_references(self):
 
778
        self.check_path(['+foo', '-bar', self.core, self.site],
 
779
                        ['+foo', '-bar'])
 
780
 
 
781
 
 
782
class TestDisablePlugin(BaseTestPlugins):
 
783
 
 
784
    def setUp(self):
 
785
        super(TestDisablePlugin, self).setUp()
 
786
        self.create_plugin_package('test_foo')
 
787
        # Make sure we don't pollute the plugins namespace
 
788
        self.overrideAttr(plugins, '__path__')
 
789
        # Be paranoid in case a test fail
 
790
        self.addCleanup(self._unregister_plugin, 'test_foo')
 
791
 
 
792
    def test_cannot_import(self):
 
793
        self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
 
794
        plugin.set_plugins_path(['.'])
 
795
        try:
 
796
            import bzrlib.plugins.test_foo
 
797
        except ImportError:
 
798
            pass
 
799
        self.assertPluginUnknown('test_foo')
 
800
 
 
801
    def test_regular_load(self):
 
802
        self.overrideAttr(plugin, '_loaded', False)
 
803
        plugin.load_plugins(['.'])
 
804
        self.assertPluginKnown('test_foo')
 
805
        self.assertDocstring("This is the doc for test_foo",
 
806
                             bzrlib.plugins.test_foo)
 
807
 
 
808
    def test_not_loaded(self):
 
809
        self.warnings = []
 
810
        def captured_warning(*args, **kwargs):
 
811
            self.warnings.append((args, kwargs))
 
812
        self.overrideAttr(trace, 'warning', captured_warning)
 
813
        # Reset the flag that protect against double loading
 
814
        self.overrideAttr(plugin, '_loaded', False)
 
815
        self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
 
816
        plugin.load_plugins(['.'])
 
817
        self.assertPluginUnknown('test_foo')
 
818
        # Make sure we don't warn about the plugin ImportError since this has
 
819
        # been *requested* by the user.
 
820
        self.assertLength(0, self.warnings)
 
821
 
 
822
 
 
823
 
 
824
class TestLoadPluginAtSyntax(tests.TestCase):
 
825
 
 
826
    def _get_paths(self, paths):
 
827
        return plugin._get_specific_plugin_paths(paths)
 
828
 
 
829
    def test_empty(self):
 
830
        self.assertEquals([], self._get_paths(None))
 
831
        self.assertEquals([], self._get_paths(''))
 
832
 
 
833
    def test_one_path(self):
 
834
        self.assertEquals([('b', 'man')], self._get_paths('b@man'))
 
835
 
 
836
    def test_bogus_path(self):
 
837
        # We need a '@'
 
838
        self.assertRaises(errors.BzrCommandError, self._get_paths, 'batman')
 
839
        # Too much '@' isn't good either
 
840
        self.assertRaises(errors.BzrCommandError, self._get_paths,
 
841
                          'batman@mobile@cave')
 
842
        # An empty description probably indicates a problem
 
843
        self.assertRaises(errors.BzrCommandError, self._get_paths,
 
844
                          os.pathsep.join(['batman@cave', '', 'robin@mobile']))
 
845
 
 
846
 
 
847
class TestLoadPluginAt(BaseTestPlugins):
 
848
 
 
849
    def setUp(self):
 
850
        super(TestLoadPluginAt, self).setUp()
 
851
        # Make sure we don't pollute the plugins namespace
 
852
        self.overrideAttr(plugins, '__path__')
 
853
        # Reset the flag that protect against double loading
 
854
        self.overrideAttr(plugin, '_loaded', False)
 
855
        # Create the same plugin in two directories
 
856
        self.create_plugin_package('test_foo', dir='non-standard-dir')
 
857
        # The "normal" directory, we use 'standard' instead of 'plugins' to
 
858
        # avoid depending on the precise naming.
 
859
        self.create_plugin_package('test_foo', dir='standard/test_foo')
 
860
        # All the tests will load the 'test_foo' plugin from various locations
 
861
        self.addCleanup(self._unregister_plugin, 'test_foo')
 
862
        # Unfortunately there's global cached state for the specific
 
863
        # registered paths.
 
864
        self.addCleanup(plugin.PluginImporter.reset)
 
865
 
 
866
    def assertTestFooLoadedFrom(self, path):
 
867
        self.assertPluginKnown('test_foo')
 
868
        self.assertDocstring('This is the doc for test_foo',
 
869
                             bzrlib.plugins.test_foo)
 
870
        self.assertEqual(path, bzrlib.plugins.test_foo.dir_source)
 
871
 
 
872
    def test_regular_load(self):
 
873
        plugin.load_plugins(['standard'])
 
874
        self.assertTestFooLoadedFrom('standard/test_foo')
 
875
 
 
876
    def test_import(self):
 
877
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
878
        plugin.set_plugins_path(['standard'])
 
879
        try:
 
880
            import bzrlib.plugins.test_foo
 
881
        except ImportError:
 
882
            pass
 
883
        self.assertTestFooLoadedFrom('non-standard-dir')
 
884
 
 
885
    def test_loading(self):
 
886
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
887
        plugin.load_plugins(['standard'])
 
888
        self.assertTestFooLoadedFrom('non-standard-dir')
 
889
 
 
890
    def test_compiled_loaded(self):
 
891
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
892
        plugin.load_plugins(['standard'])
 
893
        self.assertTestFooLoadedFrom('non-standard-dir')
 
894
        self.assertIsSameRealPath('non-standard-dir/__init__.py',
 
895
                                  bzrlib.plugins.test_foo.__file__)
 
896
 
 
897
        # Try importing again now that the source has been compiled
 
898
        self._unregister_plugin('test_foo')
 
899
        plugin._loaded = False
 
900
        plugin.load_plugins(['standard'])
 
901
        self.assertTestFooLoadedFrom('non-standard-dir')
 
902
        if __debug__:
 
903
            suffix = 'pyc'
 
904
        else:
 
905
            suffix = 'pyo'
 
906
        self.assertIsSameRealPath('non-standard-dir/__init__.%s' % suffix,
 
907
                                  bzrlib.plugins.test_foo.__file__)
 
908
 
 
909
    def test_submodule_loading(self):
 
910
        # We create an additional directory under the one for test_foo
 
911
        self.create_plugin_package('test_bar', dir='non-standard-dir/test_bar')
 
912
        self.addCleanup(self._unregister_plugin_submodule,
 
913
                        'test_foo', 'test_bar')
 
914
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
915
        plugin.set_plugins_path(['standard'])
 
916
        import bzrlib.plugins.test_foo
 
917
        self.assertEqual('bzrlib.plugins.test_foo',
 
918
                         bzrlib.plugins.test_foo.__package__)
 
919
        import bzrlib.plugins.test_foo.test_bar
 
920
        self.assertIsSameRealPath('non-standard-dir/test_bar/__init__.py',
 
921
                                  bzrlib.plugins.test_foo.test_bar.__file__)
 
922
 
 
923
    def test_relative_submodule_loading(self):
 
924
        self.create_plugin_package('test_foo', dir='another-dir', source='''
 
925
import test_bar
 
926
''')
 
927
        # We create an additional directory under the one for test_foo
 
928
        self.create_plugin_package('test_bar', dir='another-dir/test_bar')
 
929
        self.addCleanup(self._unregister_plugin_submodule,
 
930
                        'test_foo', 'test_bar')
 
931
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@another-dir')
 
932
        plugin.set_plugins_path(['standard'])
 
933
        import bzrlib.plugins.test_foo
 
934
        self.assertEqual('bzrlib.plugins.test_foo',
 
935
                         bzrlib.plugins.test_foo.__package__)
 
936
        self.assertIsSameRealPath('another-dir/test_bar/__init__.py',
 
937
                                  bzrlib.plugins.test_foo.test_bar.__file__)
 
938
 
 
939
    def test_loading_from___init__only(self):
 
940
        # We rename the existing __init__.py file to ensure that we don't load
 
941
        # a random file
 
942
        init = 'non-standard-dir/__init__.py'
 
943
        random = 'non-standard-dir/setup.py'
 
944
        os.rename(init, random)
 
945
        self.addCleanup(os.rename, random, init)
 
946
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
947
        plugin.load_plugins(['standard'])
 
948
        self.assertPluginUnknown('test_foo')
 
949
 
 
950
    def test_loading_from_specific_file(self):
 
951
        plugin_dir = 'non-standard-dir'
 
952
        plugin_file_name = 'iamtestfoo.py'
 
953
        plugin_path = osutils.pathjoin(plugin_dir, plugin_file_name)
 
954
        source = '''\
 
955
"""This is the doc for %s"""
 
956
dir_source = '%s'
 
957
''' % ('test_foo', plugin_path)
 
958
        self.create_plugin('test_foo', source=source,
 
959
                           dir=plugin_dir, file_name=plugin_file_name)
 
960
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@%s' % plugin_path)
 
961
        plugin.load_plugins(['standard'])
 
962
        self.assertTestFooLoadedFrom(plugin_path)
 
963
 
 
964
 
 
965
class TestDescribePlugins(BaseTestPlugins):
 
966
 
 
967
    def test_describe_plugins(self):
 
968
        class DummyModule(object):
 
969
            __doc__ = 'Hi there'
 
970
        class DummyPlugin(object):
 
971
            __version__ = '0.1.0'
 
972
            module = DummyModule()
 
973
        def dummy_plugins():
 
974
            return { 'good': DummyPlugin() }
 
975
        self.overrideAttr(plugin, 'plugin_warnings',
 
976
            {'bad': ['Failed to load (just testing)']})
 
977
        self.overrideAttr(plugin, 'plugins', dummy_plugins)
 
978
        self.assertEquals("""\
 
979
bad (failed to load)
 
980
  ** Failed to load (just testing)
 
981
 
 
982
good 0.1.0
 
983
  Hi there
 
984
 
 
985
""", ''.join(plugin.describe_plugins()))