/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_plugins.py

  • Committer: Vincent Ladeuil
  • Date: 2009-08-20 09:47:22 UTC
  • mto: (4672.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4673.
  • Revision ID: v.ladeuil+lp@free.fr-20090820094722-ng0j9r3re8tk52y7
Add [+-]{user|core|site} handling in BZR_PLUGIN_PATH.

* bzrlib/plugin.py:
(get_standard_plugins_path): Change the way the BZR_PLUGIN_PATH is
handled to give more control.

* bzrlib/tests/test_plugins.py:
(TestSetPluginsPath): Deleted, covered by other tests.
(TestLoadFromPath.test_get_standard_plugins_path,
TestLoadFromPath.test_get_standard_plugins_path_env): Fix the
failing parts covered elsewhere.
(TestEnvPluginPath): Add tests for the new behaviors. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import sys
27
27
import zipfile
28
28
 
29
 
from bzrlib import plugin, tests
 
29
from bzrlib import (
 
30
    osutils,
 
31
    plugin,
 
32
    tests,
 
33
    )
30
34
import bzrlib.plugin
31
35
import bzrlib.plugins
32
36
import bzrlib.commands
454
458
                delattr(bzrlib.plugins, 'myplug')
455
459
 
456
460
 
457
 
class TestSetPluginsPath(TestCase):
458
 
 
459
 
    def test_set_plugins_path(self):
460
 
        """set_plugins_path should set the module __path__ correctly."""
461
 
        old_path = bzrlib.plugins.__path__
462
 
        try:
463
 
            bzrlib.plugins.__path__ = []
464
 
            expected_path = bzrlib.plugin.set_plugins_path()
465
 
            self.assertEqual(expected_path, bzrlib.plugins.__path__)
466
 
        finally:
467
 
            bzrlib.plugins.__path__ = old_path
468
 
 
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')
474
 
        try:
475
 
            bzrlib.plugins.__path__ = []
476
 
            os.environ['BZR_PLUGIN_PATH'] = "first\\//\\" + os.pathsep + \
477
 
                "second/\\/\\/"
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)])
484
 
        finally:
485
 
            bzrlib.plugins.__path__ = old_path
486
 
            if old_env is not None:
487
 
                os.environ['BZR_PLUGIN_PATH'] = old_env
488
 
            else:
489
 
                del os.environ['BZR_PLUGIN_PATH']
490
 
 
491
 
 
492
461
class TestHelpIndex(tests.TestCase):
493
462
    """Tests for the PluginsHelpIndex class."""
494
463
 
633
602
 
634
603
    def test_get_standard_plugins_path(self):
635
604
        path = plugin.get_standard_plugins_path()
636
 
        self.assertEqual(plugin.get_default_plugin_path(), path[0])
637
605
        for directory in path:
638
606
            self.assertNotContainsRe(directory, r'\\/$')
639
607
        try:
651
619
 
652
620
    def test_get_standard_plugins_path_env(self):
653
621
        os.environ['BZR_PLUGIN_PATH'] = 'foo/'
654
 
        self.assertEqual('foo', plugin.get_standard_plugins_path()[0])
 
622
        path = plugin.get_standard_plugins_path()
 
623
        for directory in path:
 
624
            self.assertNotContainsRe(directory, r'\\/$')
655
625
 
656
626
    def test_load_plugins(self):
657
627
        plugin.load_plugins(['.'])
683
653
        self.site = plugin.get_site_plugin_path()
684
654
        self.core = plugin.get_core_plugin_path()
685
655
 
686
 
    def _list2path(self, *args):
 
656
    def _list2paths(self, *args):
687
657
        paths = []
688
658
        for p in args:
689
659
            plugin._append_new_path(paths, p)
690
660
        return paths
691
661
 
 
662
    def _set_path(self, *args):
 
663
        path = os.pathsep.join(self._list2paths(*args))
 
664
        osutils.set_or_unset_env('BZR_PLUGIN_PATH', path)
 
665
 
 
666
    def check_path(self, expected_dirs, setting_dirs):
 
667
        if setting_dirs:
 
668
            self._set_path(*setting_dirs)
 
669
        actual = plugin.get_standard_plugins_path()
 
670
        self.assertEquals(self._list2paths(*expected_dirs), actual)
 
671
 
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],
 
674
                        None)
 
675
 
 
676
    def test_adhoc_policy(self):
 
677
        self.check_path([self.user, self.core, self.site],
 
678
                        ['+user', '+core', '+site'])
 
679
 
 
680
    def test_fallback_policy(self):
 
681
        self.check_path([self.core, self.site, self.user],
 
682
                        ['+core', '+site', '+user'])
 
683
 
 
684
    def test_override_policy(self):
 
685
        self.check_path([self.user, self.site, self.core],
 
686
                        ['+user', '+site', '+core'])
 
687
 
 
688
    def test_disable_user(self):
 
689
        self.check_path([self.core, self.site], ['-user'])
 
690
 
 
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'])
 
694
 
 
695
    def test_disable_overrides_disable(self):
 
696
        self.check_path([self.core, self.site], ['-user', '+user'])
 
697
 
 
698
    def test_disable_core(self):
 
699
        self.check_path([self.user, self.site], ['-core'])
 
700
 
 
701
    def test_disable_site(self):
 
702
        self.check_path([self.user, self.core], ['-site'])
 
703
 
 
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'],
 
708
                        ['mysite', '-site'])
 
709
 
 
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'],
 
714
                        ['mycore', '-core'])
 
715
 
 
716
    def test_my_plugin_only(self):
 
717
        self.check_path(['myplugin'], ['myplugin', '-user', '-core', '-site'])
 
718
 
 
719
    def test_my_plugin_first(self):
 
720
        self.check_path(['myplugin', self.core, self.site, self.user],
 
721
                        ['myplugin', '+core', '+site', '+user'])
695
722