~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for plugins"""
18
18
 
31
31
import bzrlib.plugins
32
32
import bzrlib.commands
33
33
import bzrlib.help
 
34
from bzrlib.symbol_versioning import one_three
34
35
from bzrlib.tests import (
35
36
    TestCase,
36
37
    TestCaseInTempDir,
454
455
                delattr(bzrlib.plugins, 'myplug')
455
456
 
456
457
 
 
458
class TestPluginFromZip(TestCaseInTempDir):
 
459
 
 
460
    def make_zipped_plugin(self, zip_name, filename):
 
461
        z = zipfile.ZipFile(zip_name, 'w')
 
462
        z.writestr(filename, PLUGIN_TEXT)
 
463
        z.close()
 
464
 
 
465
    def check_plugin_load(self, zip_name, plugin_name):
 
466
        self.assertFalse(plugin_name in dir(bzrlib.plugins),
 
467
                         'Plugin already loaded')
 
468
        old_path = bzrlib.plugins.__path__
 
469
        try:
 
470
            # this is normally done by load_plugins -> set_plugins_path
 
471
            bzrlib.plugins.__path__ = [zip_name]
 
472
            self.applyDeprecated(one_three,
 
473
                bzrlib.plugin.load_from_zip, zip_name)
 
474
            self.assertTrue(plugin_name in dir(bzrlib.plugins),
 
475
                            'Plugin is not loaded')
 
476
        finally:
 
477
            # unregister plugin
 
478
            if getattr(bzrlib.plugins, plugin_name, None):
 
479
                delattr(bzrlib.plugins, plugin_name)
 
480
                del sys.modules['bzrlib.plugins.' + plugin_name]
 
481
            bzrlib.plugins.__path__ = old_path
 
482
 
 
483
    def test_load_module(self):
 
484
        self.make_zipped_plugin('./test.zip', 'ziplug.py')
 
485
        self.check_plugin_load('./test.zip', 'ziplug')
 
486
 
 
487
    def test_load_package(self):
 
488
        self.make_zipped_plugin('./test.zip', 'ziplug/__init__.py')
 
489
        self.check_plugin_load('./test.zip', 'ziplug')
 
490
 
 
491
 
457
492
class TestSetPluginsPath(TestCase):
458
493
 
459
494
    def test_set_plugins_path(self):