/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: 2011-07-06 08:58:15 UTC
  • mfrom: (5609.48.2 2.3)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706085815-6leauod52jq2u43d
MergingĀ inĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
91
91
                delattr(plugin, submodule_name)
92
92
 
93
93
    def assertPluginUnknown(self, name):
94
 
        self.failIf(getattr(bzrlib.plugins, name, None) is not None)
95
 
        self.failIf('bzrlib.plugins.%s' % name in sys.modules)
 
94
        self.assertFalse(getattr(bzrlib.plugins, name, None) is not None)
 
95
        self.assertFalse('bzrlib.plugins.%s' % name in sys.modules)
96
96
 
97
97
    def assertPluginKnown(self, name):
98
 
        self.failUnless(getattr(bzrlib.plugins, name, None) is not None)
99
 
        self.failUnless('bzrlib.plugins.%s' % name in sys.modules)
 
98
        self.assertTrue(getattr(bzrlib.plugins, name, None) is not None)
 
99
        self.assertTrue('bzrlib.plugins.%s' % name in sys.modules)
100
100
 
101
101
 
102
102
class TestLoadingPlugins(tests.TestCaseInTempDir, TestPluginMixin):
109
109
        # file name we can use which is also a valid attribute for accessing in
110
110
        # activeattributes. - we cannot give import parameters.
111
111
        tempattribute = "0"
112
 
        self.failIf(tempattribute in self.activeattributes)
 
112
        self.assertFalse(tempattribute in self.activeattributes)
113
113
        # set a place for the plugins to record their loading, and at the same
114
114
        # time validate that the location the plugins should record to is
115
115
        # valid and correct.
116
116
        self.__class__.activeattributes [tempattribute] = []
117
 
        self.failUnless(tempattribute in self.activeattributes)
 
117
        self.assertTrue(tempattribute in self.activeattributes)
118
118
        # create two plugin directories
119
119
        os.mkdir('first')
120
120
        os.mkdir('second')
147
147
        self.assertPluginUnknown('plugin')
148
148
 
149
149
    def test_plugins_from_different_dirs_can_demand_load(self):
150
 
        self.failIf('bzrlib.plugins.pluginone' in sys.modules)
151
 
        self.failIf('bzrlib.plugins.plugintwo' in sys.modules)
 
150
        self.assertFalse('bzrlib.plugins.pluginone' in sys.modules)
 
151
        self.assertFalse('bzrlib.plugins.plugintwo' in sys.modules)
152
152
        # This test tests that having two plugins in different
153
153
        # directories with different names allows them both to be loaded, when
154
154
        # we do a direct import statement.
155
155
        # Determine a file name we can use which is also a valid attribute
156
156
        # for accessing in activeattributes. - we cannot give import parameters.
157
157
        tempattribute = "different-dirs"
158
 
        self.failIf(tempattribute in self.activeattributes)
 
158
        self.assertFalse(tempattribute in self.activeattributes)
159
159
        # set a place for the plugins to record their loading, and at the same
160
160
        # time validate that the location the plugins should record to is
161
161
        # valid and correct.
162
162
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
163
163
            [tempattribute] = []
164
 
        self.failUnless(tempattribute in self.activeattributes)
 
164
        self.assertTrue(tempattribute in self.activeattributes)
165
165
        # create two plugin directories
166
166
        os.mkdir('first')
167
167
        os.mkdir('second')
186
186
 
187
187
        oldpath = bzrlib.plugins.__path__
188
188
        try:
189
 
            self.failIf('bzrlib.plugins.pluginone' in sys.modules)
190
 
            self.failIf('bzrlib.plugins.plugintwo' in sys.modules)
 
189
            self.assertFalse('bzrlib.plugins.pluginone' in sys.modules)
 
190
            self.assertFalse('bzrlib.plugins.plugintwo' in sys.modules)
191
191
            bzrlib.plugins.__path__ = ['first', 'second']
192
192
            exec "import bzrlib.plugins.pluginone"
193
193
            self.assertEqual(['first'], self.activeattributes[tempattribute])
208
208
        # check the plugin is not loaded already
209
209
        self.assertPluginUnknown('ts_plugin')
210
210
        tempattribute = "trailing-slash"
211
 
        self.failIf(tempattribute in self.activeattributes)
 
211
        self.assertFalse(tempattribute in self.activeattributes)
212
212
        # set a place for the plugin to record its loading, and at the same
213
213
        # time validate that the location the plugin should record to is
214
214
        # valid and correct.
215
215
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
216
216
            [tempattribute] = []
217
 
        self.failUnless(tempattribute in self.activeattributes)
 
217
        self.assertTrue(tempattribute in self.activeattributes)
218
218
        # create a directory for the plugin
219
219
        os.mkdir('plugin_test')
220
220
        # write a plugin that will record when its loaded in the
656
656
                    self.fail('No path to global plugins')
657
657
 
658
658
    def test_get_standard_plugins_path_env(self):
659
 
        os.environ['BZR_PLUGIN_PATH'] = 'foo/'
 
659
        self.overrideEnv('BZR_PLUGIN_PATH', 'foo/')
660
660
        path = plugin.get_standard_plugins_path()
661
661
        for directory in path:
662
662
            self.assertNotContainsRe(directory, r'\\/$')
692
692
 
693
693
    def _set_path(self, *args):
694
694
        path = os.pathsep.join(self._list2paths(*args))
695
 
        osutils.set_or_unset_env('BZR_PLUGIN_PATH', path)
 
695
        self.overrideEnv('BZR_PLUGIN_PATH', path)
696
696
 
697
697
    def check_path(self, expected_dirs, setting_dirs):
698
698
        if setting_dirs:
779
779
        self.addCleanup(self._unregister_plugin, 'test_foo')
780
780
 
781
781
    def test_cannot_import(self):
782
 
        osutils.set_or_unset_env('BZR_DISABLE_PLUGINS', 'test_foo')
 
782
        self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
783
783
        plugin.set_plugins_path(['.'])
784
784
        try:
785
785
            import bzrlib.plugins.test_foo
801
801
        self.overrideAttr(trace, 'warning', captured_warning)
802
802
        # Reset the flag that protect against double loading
803
803
        self.overrideAttr(plugin, '_loaded', False)
804
 
        osutils.set_or_unset_env('BZR_DISABLE_PLUGINS', 'test_foo')
 
804
        self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
805
805
        plugin.load_plugins(['.'])
806
806
        self.assertPluginUnknown('test_foo')
807
807
        # Make sure we don't warn about the plugin ImportError since this has
859
859
        self.assertTestFooLoadedFrom('standard/test_foo')
860
860
 
861
861
    def test_import(self):
862
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
862
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
863
863
        plugin.set_plugins_path(['standard'])
864
864
        try:
865
865
            import bzrlib.plugins.test_foo
868
868
        self.assertTestFooLoadedFrom('non-standard-dir')
869
869
 
870
870
    def test_loading(self):
871
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
871
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
872
872
        plugin.load_plugins(['standard'])
873
873
        self.assertTestFooLoadedFrom('non-standard-dir')
874
874
 
875
875
    def test_compiled_loaded(self):
876
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
876
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
877
877
        plugin.load_plugins(['standard'])
878
878
        self.assertTestFooLoadedFrom('non-standard-dir')
879
879
        self.assertIsSameRealPath('non-standard-dir/__init__.py',
896
896
        self.create_plugin_package('test_bar', dir='non-standard-dir/test_bar')
897
897
        self.addCleanup(self._unregister_plugin_submodule,
898
898
                        'test_foo', 'test_bar')
899
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
899
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
900
900
        plugin.set_plugins_path(['standard'])
901
901
        import bzrlib.plugins.test_foo
902
902
        self.assertEqual('bzrlib.plugins.test_foo',
913
913
        self.create_plugin_package('test_bar', dir='another-dir/test_bar')
914
914
        self.addCleanup(self._unregister_plugin_submodule,
915
915
                        'test_foo', 'test_bar')
916
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@another-dir')
 
916
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@another-dir')
917
917
        plugin.set_plugins_path(['standard'])
918
918
        import bzrlib.plugins.test_foo
919
919
        self.assertEqual('bzrlib.plugins.test_foo',
928
928
        random = 'non-standard-dir/setup.py'
929
929
        os.rename(init, random)
930
930
        self.addCleanup(os.rename, random, init)
931
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
931
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
932
932
        plugin.load_plugins(['standard'])
933
933
        self.assertPluginUnknown('test_foo')
934
934
 
942
942
''' % ('test_foo', plugin_path)
943
943
        self.create_plugin('test_foo', source=source,
944
944
                           dir=plugin_dir, file_name=plugin_file_name)
945
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@%s' % plugin_path)
 
945
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@%s' % plugin_path)
946
946
        plugin.load_plugins(['standard'])
947
947
        self.assertTestFooLoadedFrom(plugin_path)