~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

[merge] bzr.dev 2255, resolve conflicts, update copyrights

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 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
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
 
18
17
"""Tests for plugins"""
19
18
 
20
19
# XXX: There are no plugin tests at the moment because the plugin module
23
22
 
24
23
import os
25
24
from StringIO import StringIO
 
25
import zipfile
26
26
 
27
27
import bzrlib.plugin
28
28
import bzrlib.plugins
191
191
            help = self.split_help_commands()['myplug']
192
192
            self.assertContainsRe(help, '\[myplug\]')
193
193
        finally:
194
 
            # remove the plugin 'plugin'
195
 
            if getattr(bzrlib.plugins, 'plugin', None):
196
 
                del bzrlib.plugins.plugin
 
194
            # unregister command
 
195
            if bzrlib.commands.plugin_cmds.get('myplug', None):
 
196
                del bzrlib.commands.plugin_cmds['myplug']
 
197
            # remove the plugin 'myplug'
 
198
            if getattr(bzrlib.plugins, 'myplug', None):
 
199
                delattr(bzrlib.plugins, 'myplug')
 
200
 
 
201
 
 
202
class TestPluginFromZip(TestCaseInTempDir):
 
203
 
 
204
    def make_zipped_plugin(self, zip_name, filename):
 
205
        z = zipfile.ZipFile(zip_name, 'w')
 
206
        z.writestr(filename, PLUGIN_TEXT)
 
207
        z.close()
 
208
 
 
209
    def check_plugin_load(self, zip_name, plugin_name):
 
210
        self.assertFalse(plugin_name in dir(bzrlib.plugins),
 
211
                         'Plugin already loaded')
 
212
        try:
 
213
            bzrlib.plugin.load_from_zips([zip_name])
 
214
            self.assertTrue(plugin_name in dir(bzrlib.plugins),
 
215
                            'Plugin is not loaded')
 
216
        finally:
 
217
            # unregister plugin
 
218
            if getattr(bzrlib.plugins, plugin_name, None):
 
219
                delattr(bzrlib.plugins, plugin_name)
 
220
 
 
221
    def test_load_module(self):
 
222
        self.make_zipped_plugin('./test.zip', 'ziplug.py')
 
223
        self.check_plugin_load('./test.zip', 'ziplug')
 
224
 
 
225
    def test_load_package(self):
 
226
        self.make_zipped_plugin('./test.zip', 'ziplug/__init__.py')
 
227
        self.check_plugin_load('./test.zip', 'ziplug')