~lifeless/ubuntu/lucid/bzr/2.1.2-sru

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-06-27 15:23:34 UTC
  • mfrom: (1.3.1 upstream) (3.1.78 karmic)
  • Revision ID: james.westby@ubuntu.com-20090627152334-u3smexjpaolh96qd
* New upstream release.
* Bump standards version to 3.8.2.

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., 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
 
31
31
import bzrlib.plugins
32
32
import bzrlib.commands
33
33
import bzrlib.help
34
 
from bzrlib.symbol_versioning import one_three
35
34
from bzrlib.tests import (
36
35
    TestCase,
37
36
    TestCaseInTempDir,
455
454
                delattr(bzrlib.plugins, 'myplug')
456
455
 
457
456
 
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
 
 
492
457
class TestSetPluginsPath(TestCase):
493
458
 
494
459
    def test_set_plugins_path(self):
668
633
        path = plugin.get_standard_plugins_path()
669
634
        self.assertEqual(plugin.get_default_plugin_path(), path[0])
670
635
        for directory in path:
671
 
            self.assertNotContainsRe(r'\\/$', directory)
 
636
            self.assertNotContainsRe(directory, r'\\/$')
672
637
        try:
673
638
            from distutils.sysconfig import get_python_lib
674
639
        except ImportError: