454
458
delattr(bzrlib.plugins, 'myplug')
457
class TestSetPluginsPath(TestCase):
459
def test_set_plugins_path(self):
460
"""set_plugins_path should set the module __path__ correctly."""
461
old_path = bzrlib.plugins.__path__
463
bzrlib.plugins.__path__ = []
464
expected_path = bzrlib.plugin.set_plugins_path()
465
self.assertEqual(expected_path, bzrlib.plugins.__path__)
467
bzrlib.plugins.__path__ = old_path
469
def test_set_plugins_path_with_trailing_slashes(self):
470
"""set_plugins_path should set the module __path__ based on
471
BZR_PLUGIN_PATH after removing all trailing slashes."""
472
old_path = bzrlib.plugins.__path__
473
old_env = os.environ.get('BZR_PLUGIN_PATH')
475
bzrlib.plugins.__path__ = []
476
os.environ['BZR_PLUGIN_PATH'] = "first\\//\\" + os.pathsep + \
478
bzrlib.plugin.set_plugins_path()
479
# We expect our nominated paths to have all path-seps removed,
480
# and this is testing only that.
481
expected_path = ['first', 'second']
482
self.assertEqual(expected_path,
483
bzrlib.plugins.__path__[:len(expected_path)])
485
bzrlib.plugins.__path__ = old_path
486
if old_env is not None:
487
os.environ['BZR_PLUGIN_PATH'] = old_env
489
del os.environ['BZR_PLUGIN_PATH']
492
461
class TestHelpIndex(tests.TestCase):
493
462
"""Tests for the PluginsHelpIndex class."""
683
653
self.site = plugin.get_site_plugin_path()
684
654
self.core = plugin.get_core_plugin_path()
686
def _list2path(self, *args):
656
def _list2paths(self, *args):
689
659
plugin._append_new_path(paths, p)
662
def _set_path(self, *args):
663
path = os.pathsep.join(self._list2paths(*args))
664
osutils.set_or_unset_env('BZR_PLUGIN_PATH', path)
666
def check_path(self, expected_dirs, setting_dirs):
668
self._set_path(*setting_dirs)
669
actual = plugin.get_standard_plugins_path()
670
self.assertEquals(self._list2paths(*expected_dirs), actual)
692
672
def test_default(self):
693
self.assertEquals(self._list2path(self.user, self.core, self.site),
694
plugin.get_standard_plugins_path())
673
self.check_path([self.user, self.core, self.site],
676
def test_adhoc_policy(self):
677
self.check_path([self.user, self.core, self.site],
678
['+user', '+core', '+site'])
680
def test_fallback_policy(self):
681
self.check_path([self.core, self.site, self.user],
682
['+core', '+site', '+user'])
684
def test_override_policy(self):
685
self.check_path([self.user, self.site, self.core],
686
['+user', '+site', '+core'])
688
def test_disable_user(self):
689
self.check_path([self.core, self.site], ['-user'])
691
def test_disable_user_twice(self):
692
# Ensures multiple removals don't left cruft
693
self.check_path([self.core, self.site], ['-user', '-user'])
695
def test_disable_overrides_disable(self):
696
self.check_path([self.core, self.site], ['-user', '+user'])
698
def test_disable_core(self):
699
self.check_path([self.user, self.site], ['-core'])
701
def test_disable_site(self):
702
self.check_path([self.user, self.core], ['-site'])
704
def test_override_site(self):
705
self.check_path([self.core, 'mysite', self.user],
706
['+core', 'mysite', '-site', '+user'])
707
self.check_path([self.user, self.core, 'mysite'],
710
def test_override_core(self):
711
self.check_path(['mycore', self.site, self.user],
712
['mycore', '-core', '+site', '+user'])
713
self.check_path([self.user, self.site, 'mycore'],
716
def test_my_plugin_only(self):
717
self.check_path(['myplugin'], ['myplugin', '-user', '-core', '-site'])
719
def test_my_plugin_first(self):
720
self.check_path(['myplugin', self.core, self.site, self.user],
721
['myplugin', '+core', '+site', '+user'])