/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5086.1.2 by Vincent Ladeuil
Cosmetic changes.
1
# Copyright (C) 2005-2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
750 by Martin Pool
- stubbed-out tests for python plugins
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
750 by Martin Pool
- stubbed-out tests for python plugins
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
12
#
750 by Martin Pool
- stubbed-out tests for python plugins
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
750 by Martin Pool
- stubbed-out tests for python plugins
16
17
"""Tests for plugins"""
18
1185.16.83 by mbp at sourcefrog
- notes on testability of plugins
19
# XXX: There are no plugin tests at the moment because the plugin module
20
# affects the global state of the process.  See bzrlib/plugins.py for more
21
# comments.
22
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
23
from cStringIO import StringIO
2967.4.5 by Daniel Watkins
Added test for badly-named plugins.
24
import logging
1185.16.83 by mbp at sourcefrog
- notes on testability of plugins
25
import os
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
26
import sys
750 by Martin Pool
- stubbed-out tests for python plugins
27
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
28
import bzrlib
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
29
from bzrlib import (
30
    osutils,
31
    plugin,
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
32
    plugins,
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
33
    tests,
34
    )
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
35
1185.16.83 by mbp at sourcefrog
- notes on testability of plugins
36
1492 by Robert Collins
Support decoration of commands.
37
# TODO: Write a test for plugin decoration of commands.
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
38
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
39
class TestPluginMixin(object):
40
41
    def _unregister_plugin(self, name):
42
        """Remove the plugin from sys.modules and the bzrlib namespace."""
43
        py_name = 'bzrlib.plugins.%s' % name
44
        if py_name in sys.modules:
45
            del sys.modules[py_name]
46
        if getattr(bzrlib.plugins, name, None) is not None:
47
            delattr(bzrlib.plugins, name)
48
49
    def assertPluginUnknown(self, name):
50
        self.failIf(getattr(bzrlib.plugins, 'plugin', None) is not None)
51
        self.failIf('bzrlib.plugins.%s' % name in sys.modules)
52
53
    def assertPluginKnown(self, name):
54
        self.failUnless(getattr(bzrlib.plugins, 'plugin', None) is not None)
55
        self.failUnless('bzrlib.plugins.%s' % name in sys.modules)
56
57
58
class TestLoadingPlugins(tests.TestCaseInTempDir, TestPluginMixin):
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
59
60
    activeattributes = {}
61
62
    def test_plugins_with_the_same_name_are_not_loaded(self):
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
63
        # This test tests that having two plugins in different directories does
64
        # not result in both being loaded when they have the same name.  get a
65
        # file name we can use which is also a valid attribute for accessing in
66
        # activeattributes. - we cannot give import parameters.
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
67
        tempattribute = "0"
68
        self.failIf(tempattribute in self.activeattributes)
69
        # set a place for the plugins to record their loading, and at the same
70
        # time validate that the location the plugins should record to is
71
        # valid and correct.
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
72
        self.__class__.activeattributes [tempattribute] = []
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
73
        self.failUnless(tempattribute in self.activeattributes)
74
        # create two plugin directories
75
        os.mkdir('first')
76
        os.mkdir('second')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
77
        # write a plugin that will record when its loaded in the
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
78
        # tempattribute list.
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
79
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
80
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
81
82
        outfile = open(os.path.join('first', 'plugin.py'), 'w')
83
        try:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
84
            outfile.write(template % (tempattribute, 'first'))
85
            outfile.write('\n')
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
86
        finally:
87
            outfile.close()
88
89
        outfile = open(os.path.join('second', 'plugin.py'), 'w')
90
        try:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
91
            outfile.write(template % (tempattribute, 'second'))
92
            outfile.write('\n')
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
93
        finally:
94
            outfile.close()
95
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
96
        try:
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
97
            bzrlib.plugin.load_from_path(['first', 'second'])
98
            self.assertEqual(['first'], self.activeattributes[tempattribute])
99
        finally:
100
            # remove the plugin 'plugin'
101
            del self.activeattributes[tempattribute]
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
102
            self._unregister_plugin('plugin')
103
        self.assertPluginUnknown('plugin')
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
104
105
    def test_plugins_from_different_dirs_can_demand_load(self):
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
106
        self.failIf('bzrlib.plugins.pluginone' in sys.modules)
107
        self.failIf('bzrlib.plugins.plugintwo' in sys.modules)
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
108
        # This test tests that having two plugins in different
109
        # directories with different names allows them both to be loaded, when
110
        # we do a direct import statement.
111
        # Determine a file name we can use which is also a valid attribute
112
        # for accessing in activeattributes. - we cannot give import parameters.
113
        tempattribute = "different-dirs"
114
        self.failIf(tempattribute in self.activeattributes)
115
        # set a place for the plugins to record their loading, and at the same
116
        # time validate that the location the plugins should record to is
117
        # valid and correct.
118
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
119
            [tempattribute] = []
120
        self.failUnless(tempattribute in self.activeattributes)
121
        # create two plugin directories
122
        os.mkdir('first')
123
        os.mkdir('second')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
124
        # write plugins that will record when they are loaded in the
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
125
        # tempattribute list.
126
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
127
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
128
129
        outfile = open(os.path.join('first', 'pluginone.py'), 'w')
130
        try:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
131
            outfile.write(template % (tempattribute, 'first'))
132
            outfile.write('\n')
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
133
        finally:
134
            outfile.close()
135
136
        outfile = open(os.path.join('second', 'plugintwo.py'), 'w')
137
        try:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
138
            outfile.write(template % (tempattribute, 'second'))
139
            outfile.write('\n')
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
140
        finally:
141
            outfile.close()
142
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
143
        oldpath = bzrlib.plugins.__path__
144
        try:
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
145
            self.failIf('bzrlib.plugins.pluginone' in sys.modules)
146
            self.failIf('bzrlib.plugins.plugintwo' in sys.modules)
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
147
            bzrlib.plugins.__path__ = ['first', 'second']
148
            exec "import bzrlib.plugins.pluginone"
149
            self.assertEqual(['first'], self.activeattributes[tempattribute])
150
            exec "import bzrlib.plugins.plugintwo"
151
            self.assertEqual(['first', 'second'],
152
                self.activeattributes[tempattribute])
1515 by Robert Collins
* Plugins with the same name in different directories in the bzr plugin
153
        finally:
154
            # remove the plugin 'plugin'
155
            del self.activeattributes[tempattribute]
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
156
            self._unregister_plugin('pluginone')
157
            self._unregister_plugin('plugintwo')
158
        self.assertPluginUnknown('pluginone')
159
        self.assertPluginUnknown('plugintwo')
1516 by Robert Collins
* bzrlib.plugin.all_plugins has been changed from an attribute to a
160
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
161
    def test_plugins_can_load_from_directory_with_trailing_slash(self):
162
        # This test tests that a plugin can load from a directory when the
163
        # directory in the path has a trailing slash.
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
164
        # check the plugin is not loaded already
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
165
        self.assertPluginUnknown('ts_plugin')
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
166
        tempattribute = "trailing-slash"
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
167
        self.failIf(tempattribute in self.activeattributes)
2652.2.3 by Blake Winton
Understand the code and comments of the test, instead of just cargo-culting them.
168
        # set a place for the plugin to record its loading, and at the same
169
        # time validate that the location the plugin should record to is
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
170
        # valid and correct.
171
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
172
            [tempattribute] = []
173
        self.failUnless(tempattribute in self.activeattributes)
2652.2.3 by Blake Winton
Understand the code and comments of the test, instead of just cargo-culting them.
174
        # create a directory for the plugin
175
        os.mkdir('plugin_test')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
176
        # write a plugin that will record when its loaded in the
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
177
        # tempattribute list.
178
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
179
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
180
181
        outfile = open(os.path.join('plugin_test', 'ts_plugin.py'), 'w')
182
        try:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
183
            outfile.write(template % (tempattribute, 'plugin'))
2911.6.4 by Blake Winton
Fix test failures
184
            outfile.write('\n')
2652.2.7 by Blake Winton
fix lines which were wider than 79 chars. Also handle files a little more safely.
185
        finally:
186
            outfile.close()
187
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
188
        try:
2652.2.3 by Blake Winton
Understand the code and comments of the test, instead of just cargo-culting them.
189
            bzrlib.plugin.load_from_path(['plugin_test'+os.sep])
190
            self.assertEqual(['plugin'], self.activeattributes[tempattribute])
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
191
        finally:
192
            del self.activeattributes[tempattribute]
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
193
            self._unregister_plugin('ts_plugin')
194
        self.assertPluginUnknown('ts_plugin')
2652.2.1 by Blake Winton
Add a test for BZR_PLUGIN_PATH, and code and another test to allow BZR_PLUGIN_PATH to contain trailing slashes.
195
3766.3.2 by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451.
196
    def load_and_capture(self, name):
197
        """Load plugins from '.' capturing the output.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
198
3766.3.2 by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451.
199
        :param name: The name of the plugin.
200
        :return: A string with the log from the plugin loading call.
201
        """
2967.4.5 by Daniel Watkins
Added test for badly-named plugins.
202
        # Capture output
203
        stream = StringIO()
3766.3.2 by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451.
204
        try:
205
            handler = logging.StreamHandler(stream)
206
            log = logging.getLogger('bzr')
207
            log.addHandler(handler)
208
            try:
209
                try:
210
                    bzrlib.plugin.load_from_path(['.'])
211
                finally:
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)
216
            finally:
217
                # Stop capturing output
218
                handler.flush()
219
                handler.close()
220
                log.removeHandler(handler)
221
            return stream.getvalue()
222
        finally:
223
            stream.close()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
224
3766.3.2 by Robert Collins
Fix reporting of incompatible api plugin load errors, fixing bug 279451.
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
227
        # anymore.
228
        name = 'wants100.py'
229
        f = file(name, 'w')
230
        try:
231
            f.write("import bzrlib.api\n"
232
                "bzrlib.api.require_any_api(bzrlib, [(1, 0, 0)])\n")
233
        finally:
234
            f.close()
235
236
        log = self.load_and_capture(name)
237
        self.assertContainsRe(log,
238
            r"It requested API version")
239
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,
3290.1.1 by James Westby
Strip "bzr_" from the start of the suggested plugin name.
246
            r"Unable to load 'bzr-bad plugin-name\.' in '\.' as a plugin "
247
            "because the file path isn't a valid module name; try renaming "
248
            "it to 'bad_plugin_name_'\.")
2967.4.5 by Daniel Watkins
Added test for badly-named plugins.
249
1516 by Robert Collins
* bzrlib.plugin.all_plugins has been changed from an attribute to a
250
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
251
class TestPlugins(tests.TestCaseInTempDir, TestPluginMixin):
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
252
253
    def setup_plugin(self, source=""):
254
        # This test tests a new plugin appears in bzrlib.plugin.plugins().
255
        # check the plugin is not loaded already
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
256
        self.assertPluginUnknown('plugin')
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
257
        # write a plugin that _cannot_ fail to load.
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
258
        file('plugin.py', 'w').write(source + '\n')
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
259
        self.addCleanup(self.teardown_plugin)
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
260
        plugin.load_from_path(['.'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
261
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
262
    def teardown_plugin(self):
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
263
        self._unregister_plugin('plugin')
264
        self.assertPluginUnknown('plugin')
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
265
266
    def test_plugin_appears_in_plugins(self):
267
        self.setup_plugin()
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
268
        self.assertPluginKnown('plugin')
269
        p = plugin.plugins()['plugin']
270
        self.assertIsInstance(p, bzrlib.plugin.PlugIn)
271
        self.assertEqual(p.module, plugins.plugin)
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
272
273
    def test_trivial_plugin_get_path(self):
274
        self.setup_plugin()
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
275
        p = plugin.plugins()['plugin']
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
276
        plugin_path = self.test_dir + '/plugin.py'
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
277
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
278
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
279
    def test_plugin_get_path_py_not_pyc(self):
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
280
        # first import creates plugin.pyc
281
        self.setup_plugin()
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
282
        self.teardown_plugin()
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
283
        plugin.load_from_path(['.']) # import plugin.pyc
284
        p = plugin.plugins()['plugin']
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
285
        plugin_path = self.test_dir + '/plugin.py'
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
286
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
287
288
    def test_plugin_get_path_pyc_only(self):
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
289
        # first import creates plugin.pyc (or plugin.pyo depending on __debug__)
290
        self.setup_plugin()
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
291
        self.teardown_plugin()
292
        os.unlink(self.test_dir + '/plugin.py')
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
293
        plugin.load_from_path(['.']) # import plugin.pyc (or .pyo)
294
        p = plugin.plugins()['plugin']
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
295
        if __debug__:
296
            plugin_path = self.test_dir + '/plugin.pyc'
297
        else:
298
            plugin_path = self.test_dir + '/plugin.pyo'
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
299
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
3193.2.1 by Alexander Belchenko
show path to plugin module as *.py instead of *.pyc if python source available
300
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
301
    def test_no_test_suite_gives_None_for_test_suite(self):
302
        self.setup_plugin()
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
303
        p = plugin.plugins()['plugin']
304
        self.assertEqual(None, p.test_suite())
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
305
306
    def test_test_suite_gives_test_suite_result(self):
307
        source = """def test_suite(): return 'foo'"""
308
        self.setup_plugin(source)
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
309
        p = plugin.plugins()['plugin']
310
        self.assertEqual('foo', p.test_suite())
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
311
3302.8.21 by Vincent Ladeuil
Fixed as per Robert's review.
312
    def test_no_load_plugin_tests_gives_None_for_load_plugin_tests(self):
3302.8.10 by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader.
313
        self.setup_plugin()
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
314
        loader = tests.TestUtil.TestLoader()
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
315
        p = plugin.plugins()['plugin']
316
        self.assertEqual(None, p.load_plugin_tests(loader))
3302.8.10 by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader.
317
3302.8.21 by Vincent Ladeuil
Fixed as per Robert's review.
318
    def test_load_plugin_tests_gives_load_plugin_tests_result(self):
3302.8.10 by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader.
319
        source = """
320
def load_tests(standard_tests, module, loader):
321
    return 'foo'"""
322
        self.setup_plugin(source)
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
323
        loader = tests.TestUtil.TestLoader()
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
324
        p = plugin.plugins()['plugin']
325
        self.assertEqual('foo', p.load_plugin_tests(loader))
326
327
    def check_version_info(self, expected, source='', name='plugin'):
328
        self.setup_plugin(source)
329
        self.assertEqual(expected, plugin.plugins()[name].version_info())
3302.8.10 by Vincent Ladeuil
Prepare bzrlib.plugin to use the new test loader.
330
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
331
    def test_no_version_info(self):
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
332
        self.check_version_info(None)
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
333
334
    def test_with_version_info(self):
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
335
        self.check_version_info((1, 2, 3, 'dev', 4),
336
                                "version_info = (1, 2, 3, 'dev', 4)")
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
337
338
    def test_short_version_info_gets_padded(self):
339
        # the gtk plugin has version_info = (1,2,3) rather than the 5-tuple.
340
        # so we adapt it
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
341
        self.check_version_info((1, 2, 3, 'final', 0),
342
                                "version_info = (1, 2, 3)")
343
344
    def check_version(self, expected, source=None, name='plugin'):
345
        self.setup_plugin(source)
346
        self.assertEqual(expected, plugins[name].__version__)
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
347
348
    def test_no_version_info___version__(self):
349
        self.setup_plugin()
350
        plugin = bzrlib.plugin.plugins()['plugin']
351
        self.assertEqual("unknown", plugin.__version__)
352
3777.6.7 by Marius Kruger
* Can now also handle non-iteratable and string plugin versions.
353
    def test_str__version__with_version_info(self):
354
        self.setup_plugin("version_info = '1.2.3'")
355
        plugin = bzrlib.plugin.plugins()['plugin']
356
        self.assertEqual("1.2.3", plugin.__version__)
357
358
    def test_noniterable__version__with_version_info(self):
359
        self.setup_plugin("version_info = (1)")
360
        plugin = bzrlib.plugin.plugins()['plugin']
361
        self.assertEqual("1", plugin.__version__)
362
363
    def test_1__version__with_version_info(self):
364
        self.setup_plugin("version_info = (1,)")
365
        plugin = bzrlib.plugin.plugins()['plugin']
366
        self.assertEqual("1", plugin.__version__)
367
368
    def test_1_2__version__with_version_info(self):
3777.6.5 by Marius Kruger
add 2 more tests for plugin version numbers
369
        self.setup_plugin("version_info = (1, 2)")
370
        plugin = bzrlib.plugin.plugins()['plugin']
371
        self.assertEqual("1.2", plugin.__version__)
372
3777.6.7 by Marius Kruger
* Can now also handle non-iteratable and string plugin versions.
373
    def test_1_2_3__version__with_version_info(self):
3777.6.5 by Marius Kruger
add 2 more tests for plugin version numbers
374
        self.setup_plugin("version_info = (1, 2, 3)")
375
        plugin = bzrlib.plugin.plugins()['plugin']
376
        self.assertEqual("1.2.3", plugin.__version__)
377
378
    def test_candidate__version__with_version_info(self):
3777.6.4 by Marius Kruger
fix tests
379
        self.setup_plugin("version_info = (1, 2, 3, 'candidate', 1)")
380
        plugin = bzrlib.plugin.plugins()['plugin']
381
        self.assertEqual("1.2.3rc1", plugin.__version__)
382
383
    def test_dev__version__with_version_info(self):
384
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 0)")
385
        plugin = bzrlib.plugin.plugins()['plugin']
386
        self.assertEqual("1.2.3dev", plugin.__version__)
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
387
3777.6.7 by Marius Kruger
* Can now also handle non-iteratable and string plugin versions.
388
    def test_dev_fallback__version__with_version_info(self):
389
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)")
390
        plugin = bzrlib.plugin.plugins()['plugin']
4634.50.6 by John Arbash Meinel
Handle a plugin fallback versioning issue.
391
        self.assertEqual("1.2.3dev4", plugin.__version__)
3777.6.7 by Marius Kruger
* Can now also handle non-iteratable and string plugin versions.
392
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
393
    def test_final__version__with_version_info(self):
3777.6.4 by Marius Kruger
fix tests
394
        self.setup_plugin("version_info = (1, 2, 3, 'final', 0)")
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
395
        plugin = bzrlib.plugin.plugins()['plugin']
396
        self.assertEqual("1.2.3", plugin.__version__)
397
4634.50.6 by John Arbash Meinel
Handle a plugin fallback versioning issue.
398
    def test_final_fallback__version__with_version_info(self):
399
        self.setup_plugin("version_info = (1, 2, 3, 'final', 2)")
400
        plugin = bzrlib.plugin.plugins()['plugin']
401
        self.assertEqual("1.2.3.final.2", plugin.__version__)
402
2762.2.1 by Robert Collins
* ``bzr plugins`` now lists the version number for each plugin in square
403
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
404
class TestPluginHelp(tests.TestCaseInTempDir):
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
405
406
    def split_help_commands(self):
407
        help = {}
408
        current = None
3908.1.1 by Andrew Bennetts
Try harder to avoid loading plugins during the test suite.
409
        out, err = self.run_bzr('--no-plugins help commands')
410
        for line in out.splitlines():
2034.1.2 by Aaron Bentley
Fix testcase
411
            if not line.startswith(' '):
412
                current = line.split()[0]
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
413
            help[current] = help.get(current, '') + line
414
415
        return help
416
417
    def test_plugin_help_builtins_unaffected(self):
418
        # Check we don't get false positives
419
        help_commands = self.split_help_commands()
420
        for cmd_name in bzrlib.commands.builtin_command_names():
421
            if cmd_name in bzrlib.commands.plugin_command_names():
422
                continue
423
            try:
2432.1.12 by Robert Collins
Relocate command help onto Command.
424
                help = bzrlib.commands.get_cmd_object(cmd_name).get_help_text()
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
425
            except NotImplementedError:
426
                # some commands have no help
427
                pass
428
            else:
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
429
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
430
2432.1.12 by Robert Collins
Relocate command help onto Command.
431
            if cmd_name in help_commands.keys():
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
432
                # some commands are hidden
433
                help = help_commands[cmd_name]
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
434
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
435
436
    def test_plugin_help_shows_plugin(self):
437
        # Create a test plugin
438
        os.mkdir('plugin_test')
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
439
        f = open(osutils.pathjoin('plugin_test', 'myplug.py'), 'w')
5086.1.2 by Vincent Ladeuil
Cosmetic changes.
440
        f.write("""\
5086.1.3 by Vincent Ladeuil
Fix imports in test_plugins.
441
from bzrlib import commands
442
class cmd_myplug(commands.Command):
5086.1.2 by Vincent Ladeuil
Cosmetic changes.
443
    '''Just a simple test plugin.'''
444
    aliases = ['mplg']
445
    def run(self):
446
        print 'Hello from my plugin'
447
448
"""
449
)
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
450
        f.close()
451
452
        try:
453
            # Check its help
2256.2.2 by Robert Collins
Allow 'import bzrlib.plugins.NAME' to work when the plugin NAME has not
454
            bzrlib.plugin.load_from_path(['plugin_test'])
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
455
            bzrlib.commands.register_command( bzrlib.plugins.myplug.cmd_myplug)
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
456
            help = self.run_bzr('help myplug')[0]
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
457
            self.assertContainsRe(help, 'plugin "myplug"')
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
458
            help = self.split_help_commands()['myplug']
2034.1.4 by Aaron Bentley
Change angle brackets to square brackets
459
            self.assertContainsRe(help, '\[myplug\]')
1733.2.5 by Michael Ellerman
Show which plugin (if any) provides a command.
460
        finally:
2204.3.2 by Alexander Belchenko
cherrypicking: test_plugin_help_shows_plugin: fix cleanup after test
461
            # unregister command
3785.1.1 by Aaron Bentley
Switch from dict to Registry for plugin_cmds
462
            if 'myplug' in bzrlib.commands.plugin_cmds:
463
                bzrlib.commands.plugin_cmds.remove('myplug')
2204.3.2 by Alexander Belchenko
cherrypicking: test_plugin_help_shows_plugin: fix cleanup after test
464
            # remove the plugin 'myplug'
465
            if getattr(bzrlib.plugins, 'myplug', None):
466
                delattr(bzrlib.plugins, 'myplug')
2215.4.1 by Alexander Belchenko
Bugfix #68124: Allow plugins import from zip archives.
467
468
2432.1.25 by Robert Collins
Return plugin module docstrings for 'bzr help plugin'.
469
class TestHelpIndex(tests.TestCase):
470
    """Tests for the PluginsHelpIndex class."""
471
472
    def test_default_constructable(self):
473
        index = plugin.PluginsHelpIndex()
474
475
    def test_get_topics_None(self):
476
        """Searching for None returns an empty list."""
477
        index = plugin.PluginsHelpIndex()
478
        self.assertEqual([], index.get_topics(None))
479
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
480
    def test_get_topics_for_plugin(self):
481
        """Searching for plugin name gets its docstring."""
2432.1.25 by Robert Collins
Return plugin module docstrings for 'bzr help plugin'.
482
        index = plugin.PluginsHelpIndex()
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
483
        # make a new plugin here for this test, even if we're run with
484
        # --no-plugins
485
        self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
486
        demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
487
        sys.modules['bzrlib.plugins.demo_module'] = demo_module
2457.1.1 by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool)
488
        try:
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
489
            topics = index.get_topics('demo_module')
2457.1.1 by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool)
490
            self.assertEqual(1, len(topics))
491
            self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
492
            self.assertEqual(demo_module, topics[0].module)
493
        finally:
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
494
            del sys.modules['bzrlib.plugins.demo_module']
2432.1.25 by Robert Collins
Return plugin module docstrings for 'bzr help plugin'.
495
496
    def test_get_topics_no_topic(self):
497
        """Searching for something that is not a plugin returns []."""
498
        # test this by using a name that cannot be a plugin - its not
499
        # a valid python identifier.
500
        index = plugin.PluginsHelpIndex()
501
        self.assertEqual([], index.get_topics('nothing by this name'))
502
503
    def test_prefix(self):
504
        """PluginsHelpIndex has a prefix of 'plugins/'."""
505
        index = plugin.PluginsHelpIndex()
506
        self.assertEqual('plugins/', index.prefix)
507
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
508
    def test_get_plugin_topic_with_prefix(self):
509
        """Searching for plugins/demo_module returns help."""
2432.1.25 by Robert Collins
Return plugin module docstrings for 'bzr help plugin'.
510
        index = plugin.PluginsHelpIndex()
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
511
        self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
512
        demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
513
        sys.modules['bzrlib.plugins.demo_module'] = demo_module
2457.1.1 by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool)
514
        try:
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
515
            topics = index.get_topics('plugins/demo_module')
2457.1.1 by Robert Collins
(robertc) Fix bzr --no-plugins selftest which was broken by the help indices patch. (Robert Collins, Martin Pool)
516
            self.assertEqual(1, len(topics))
517
            self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
518
            self.assertEqual(demo_module, topics[0].module)
519
        finally:
2475.1.1 by Martin Pool
Rename test_plugin tests and the example module used there.
520
            del sys.modules['bzrlib.plugins.demo_module']
2432.1.25 by Robert Collins
Return plugin module docstrings for 'bzr help plugin'.
521
522
523
class FakeModule(object):
524
    """A fake module to test with."""
525
526
    def __init__(self, doc, name):
527
        self.__doc__ = doc
528
        self.__name__ = name
529
530
531
class TestModuleHelpTopic(tests.TestCase):
532
    """Tests for the ModuleHelpTopic class."""
533
534
    def test_contruct(self):
535
        """Construction takes the module to document."""
536
        mod = FakeModule('foo', 'foo')
537
        topic = plugin.ModuleHelpTopic(mod)
538
        self.assertEqual(mod, topic.module)
539
540
    def test_get_help_text_None(self):
541
        """A ModuleHelpTopic returns the docstring for get_help_text."""
542
        mod = FakeModule(None, 'demo')
543
        topic = plugin.ModuleHelpTopic(mod)
544
        self.assertEqual("Plugin 'demo' has no docstring.\n",
545
            topic.get_help_text())
546
547
    def test_get_help_text_no_carriage_return(self):
548
        """ModuleHelpTopic.get_help_text adds a \n if needed."""
549
        mod = FakeModule('one line of help', 'demo')
550
        topic = plugin.ModuleHelpTopic(mod)
551
        self.assertEqual("one line of help\n",
552
            topic.get_help_text())
553
554
    def test_get_help_text_carriage_return(self):
555
        """ModuleHelpTopic.get_help_text adds a \n if needed."""
556
        mod = FakeModule('two lines of help\nand more\n', 'demo')
557
        topic = plugin.ModuleHelpTopic(mod)
558
        self.assertEqual("two lines of help\nand more\n",
559
            topic.get_help_text())
560
561
    def test_get_help_text_with_additional_see_also(self):
562
        mod = FakeModule('two lines of help\nand more', 'demo')
563
        topic = plugin.ModuleHelpTopic(mod)
564
        self.assertEqual("two lines of help\nand more\nSee also: bar, foo\n",
565
            topic.get_help_text(['foo', 'bar']))
2432.1.29 by Robert Collins
Add get_help_topic to ModuleHelpTopic.
566
567
    def test_get_help_topic(self):
568
        """The help topic for a plugin is its module name."""
2432.1.30 by Robert Collins
Fix the ModuleHelpTopic get_help_topic to be tested with closer to real world data and strip the bzrlib.plugins. prefix from the name.
569
        mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.demo')
2432.1.29 by Robert Collins
Add get_help_topic to ModuleHelpTopic.
570
        topic = plugin.ModuleHelpTopic(mod)
571
        self.assertEqual('demo', topic.get_help_topic())
2432.1.30 by Robert Collins
Fix the ModuleHelpTopic get_help_topic to be tested with closer to real world data and strip the bzrlib.plugins. prefix from the name.
572
        mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.foo_bar')
2432.1.29 by Robert Collins
Add get_help_topic to ModuleHelpTopic.
573
        topic = plugin.ModuleHelpTopic(mod)
574
        self.assertEqual('foo_bar', topic.get_help_topic())
3835.2.7 by Aaron Bentley
Add tests for plugins
575
576
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
577
class TestLoadFromPath(tests.TestCaseInTempDir):
578
579
    def setUp(self):
580
        super(TestLoadFromPath, self).setUp()
581
        # Change bzrlib.plugin to think no plugins have been loaded yet.
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
582
        self.overrideAttr(bzrlib.plugins, '__path__', [])
583
        self.overrideAttr(plugin, '_loaded', False)
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
584
585
        # Monkey-patch load_from_path to stop it from actually loading anything.
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
586
        self.overrideAttr(plugin, 'load_from_path', lambda dirs: None)
3835.2.7 by Aaron Bentley
Add tests for plugins
587
588
    def test_set_plugins_path_with_args(self):
589
        plugin.set_plugins_path(['a', 'b'])
590
        self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
591
592
    def test_set_plugins_path_defaults(self):
593
        plugin.set_plugins_path()
594
        self.assertEqual(plugin.get_standard_plugins_path(),
595
                         bzrlib.plugins.__path__)
596
597
    def test_get_standard_plugins_path(self):
598
        path = plugin.get_standard_plugins_path()
599
        for directory in path:
4412.2.1 by Vincent Ladeuil
Fix some OSX test regressions (well actual test bugs indeed).
600
            self.assertNotContainsRe(directory, r'\\/$')
3835.2.7 by Aaron Bentley
Add tests for plugins
601
        try:
602
            from distutils.sysconfig import get_python_lib
603
        except ImportError:
604
            pass
605
        else:
606
            if sys.platform != 'win32':
607
                python_lib = get_python_lib()
608
                for directory in path:
609
                    if directory.startswith(python_lib):
610
                        break
611
                else:
612
                    self.fail('No path to global plugins')
613
614
    def test_get_standard_plugins_path_env(self):
615
        os.environ['BZR_PLUGIN_PATH'] = 'foo/'
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
616
        path = plugin.get_standard_plugins_path()
617
        for directory in path:
618
            self.assertNotContainsRe(directory, r'\\/$')
3835.2.7 by Aaron Bentley
Add tests for plugins
619
620
    def test_load_plugins(self):
621
        plugin.load_plugins(['.'])
622
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
623
        # subsequent loads are no-ops
624
        plugin.load_plugins(['foo'])
625
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
626
627
    def test_load_plugins_default(self):
628
        plugin.load_plugins()
629
        path = plugin.get_standard_plugins_path()
630
        self.assertEqual(path, bzrlib.plugins.__path__)
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
631
632
5086.1.2 by Vincent Ladeuil
Cosmetic changes.
633
class TestEnvPluginPath(tests.TestCase):
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
634
635
    def setUp(self):
636
        super(TestEnvPluginPath, self).setUp()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
637
        self.overrideAttr(plugin, 'DEFAULT_PLUGIN_PATH', None)
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
638
639
        self.user = plugin.get_user_plugin_path()
640
        self.site = plugin.get_site_plugin_path()
641
        self.core = plugin.get_core_plugin_path()
642
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
643
    def _list2paths(self, *args):
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
644
        paths = []
645
        for p in args:
646
            plugin._append_new_path(paths, p)
647
        return paths
648
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
649
    def _set_path(self, *args):
650
        path = os.pathsep.join(self._list2paths(*args))
651
        osutils.set_or_unset_env('BZR_PLUGIN_PATH', path)
652
653
    def check_path(self, expected_dirs, setting_dirs):
654
        if setting_dirs:
655
            self._set_path(*setting_dirs)
656
        actual = plugin.get_standard_plugins_path()
657
        self.assertEquals(self._list2paths(*expected_dirs), actual)
658
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
659
    def test_default(self):
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
660
        self.check_path([self.user, self.core, self.site],
661
                        None)
662
663
    def test_adhoc_policy(self):
664
        self.check_path([self.user, self.core, self.site],
665
                        ['+user', '+core', '+site'])
666
667
    def test_fallback_policy(self):
668
        self.check_path([self.core, self.site, self.user],
669
                        ['+core', '+site', '+user'])
670
671
    def test_override_policy(self):
672
        self.check_path([self.user, self.site, self.core],
673
                        ['+user', '+site', '+core'])
674
675
    def test_disable_user(self):
676
        self.check_path([self.core, self.site], ['-user'])
677
678
    def test_disable_user_twice(self):
679
        # Ensures multiple removals don't left cruft
680
        self.check_path([self.core, self.site], ['-user', '-user'])
681
4628.2.5 by Vincent Ladeuil
Fixes prompted by review.
682
    def test_duplicates_are_removed(self):
683
        self.check_path([self.user, self.core, self.site],
684
                        ['+user', '+user'])
685
        # And only the first reference is kept (since the later references will
5086.1.2 by Vincent Ladeuil
Cosmetic changes.
686
        # only produce '<plugin> already loaded' mutters)
4628.2.5 by Vincent Ladeuil
Fixes prompted by review.
687
        self.check_path([self.user, self.core, self.site],
688
                        ['+user', '+user', '+core',
689
                         '+user', '+site', '+site',
690
                         '+core'])
691
5086.1.5 by Vincent Ladeuil
Fix typo in test name.
692
    def test_disable_overrides_enable(self):
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
693
        self.check_path([self.core, self.site], ['-user', '+user'])
694
695
    def test_disable_core(self):
4628.2.3 by Vincent Ladeuil
Update doc and add NEWS entry.
696
        self.check_path([self.site], ['-core'])
697
        self.check_path([self.user, self.site], ['+user', '-core'])
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
698
699
    def test_disable_site(self):
4628.2.3 by Vincent Ladeuil
Update doc and add NEWS entry.
700
        self.check_path([self.core], ['-site'])
701
        self.check_path([self.user, self.core], ['-site', '+user'])
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
702
703
    def test_override_site(self):
4628.2.3 by Vincent Ladeuil
Update doc and add NEWS entry.
704
        self.check_path(['mysite', self.user, self.core],
705
                        ['mysite', '-site', '+user'])
706
        self.check_path(['mysite', self.core],
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
707
                        ['mysite', '-site'])
708
709
    def test_override_core(self):
4628.2.3 by Vincent Ladeuil
Update doc and add NEWS entry.
710
        self.check_path(['mycore', self.user, self.site],
711
                        ['mycore', '-core', '+user', '+site'])
712
        self.check_path(['mycore', self.site],
4628.2.2 by Vincent Ladeuil
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.
713
                        ['mycore', '-core'])
714
715
    def test_my_plugin_only(self):
716
        self.check_path(['myplugin'], ['myplugin', '-user', '-core', '-site'])
717
718
    def test_my_plugin_first(self):
719
        self.check_path(['myplugin', self.core, self.site, self.user],
720
                        ['myplugin', '+core', '+site', '+user'])
4628.2.1 by Vincent Ladeuil
Start introducing accessors for plugin paths.
721
4628.2.5 by Vincent Ladeuil
Fixes prompted by review.
722
    def test_bogus_references(self):
723
        self.check_path(['+foo', '-bar', self.core, self.site],
724
                        ['+foo', '-bar'])
5086.1.4 by Vincent Ladeuil
Slight plugin tests rewriting.
725