~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import os
24
24
from StringIO import StringIO
 
25
import zipfile
25
26
 
26
27
import bzrlib.plugin
27
28
import bzrlib.plugins
196
197
            # remove the plugin 'myplug'
197
198
            if getattr(bzrlib.plugins, 'myplug', None):
198
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')