~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: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2007 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
20
20
# affects the global state of the process.  See bzrlib/plugins.py for more
21
21
# comments.
22
22
 
23
 
from cStringIO import StringIO
24
23
import logging
25
24
import os
 
25
from StringIO import StringIO
26
26
import sys
 
27
import zipfile
27
28
 
28
 
import bzrlib
29
29
from bzrlib import (
30
30
    osutils,
31
31
    plugin,
32
 
    plugins,
33
32
    tests,
34
 
    trace,
35
 
    )
36
 
 
 
33
    )
 
34
import bzrlib.plugin
 
35
import bzrlib.plugins
 
36
import bzrlib.commands
 
37
import bzrlib.help
 
38
from bzrlib.tests import (
 
39
    TestCase,
 
40
    TestCaseInTempDir,
 
41
    TestUtil,
 
42
    )
 
43
from bzrlib.osutils import pathjoin, abspath, normpath
 
44
 
 
45
 
 
46
PLUGIN_TEXT = """\
 
47
import bzrlib.commands
 
48
class cmd_myplug(bzrlib.commands.Command):
 
49
    '''Just a simple test plugin.'''
 
50
    aliases = ['mplg']
 
51
    def run(self):
 
52
        print 'Hello from my plugin'
 
53
"""
37
54
 
38
55
# TODO: Write a test for plugin decoration of commands.
39
56
 
40
 
class TestPluginMixin(object):
41
 
 
42
 
    def create_plugin(self, name, source=None, dir='.', file_name=None):
43
 
        if source is None:
44
 
            source = '''\
45
 
"""This is the doc for %s"""
46
 
''' % (name)
47
 
        if file_name is None:
48
 
            file_name = name + '.py'
49
 
        # 'source' must not fail to load
50
 
        path = osutils.pathjoin(dir, file_name)
51
 
        f = open(path, 'w')
52
 
        self.addCleanup(os.unlink, path)
53
 
        try:
54
 
            f.write(source + '\n')
55
 
        finally:
56
 
            f.close()
57
 
 
58
 
    def create_plugin_package(self, name, dir=None, source=None):
59
 
        if dir is None:
60
 
            dir = name
61
 
        if source is None:
62
 
            source = '''\
63
 
"""This is the doc for %s"""
64
 
dir_source = '%s'
65
 
''' % (name, dir)
66
 
        os.makedirs(dir)
67
 
        def cleanup():
68
 
            # Workaround lazy import random? madness
69
 
            osutils.rmtree(dir)
70
 
        self.addCleanup(cleanup)
71
 
        self.create_plugin(name, source, dir,
72
 
                           file_name='__init__.py')
73
 
 
74
 
    def _unregister_plugin(self, name):
75
 
        """Remove the plugin from sys.modules and the bzrlib namespace."""
76
 
        py_name = 'bzrlib.plugins.%s' % name
77
 
        if py_name in sys.modules:
78
 
            del sys.modules[py_name]
79
 
        if getattr(bzrlib.plugins, name, None) is not None:
80
 
            delattr(bzrlib.plugins, name)
81
 
 
82
 
    def assertPluginUnknown(self, name):
83
 
        self.failIf(getattr(bzrlib.plugins, name, None) is not None)
84
 
        self.failIf('bzrlib.plugins.%s' % name in sys.modules)
85
 
 
86
 
    def assertPluginKnown(self, name):
87
 
        self.failUnless(getattr(bzrlib.plugins, name, None) is not None)
88
 
        self.failUnless('bzrlib.plugins.%s' % name in sys.modules)
89
 
 
90
 
 
91
 
class TestLoadingPlugins(tests.TestCaseInTempDir, TestPluginMixin):
 
57
class TestLoadingPlugins(TestCaseInTempDir):
92
58
 
93
59
    activeattributes = {}
94
60
 
102
68
        # set a place for the plugins to record their loading, and at the same
103
69
        # time validate that the location the plugins should record to is
104
70
        # valid and correct.
105
 
        self.__class__.activeattributes [tempattribute] = []
 
71
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
 
72
            [tempattribute] = []
106
73
        self.failUnless(tempattribute in self.activeattributes)
107
74
        # create two plugin directories
108
75
        os.mkdir('first')
132
99
        finally:
133
100
            # remove the plugin 'plugin'
134
101
            del self.activeattributes[tempattribute]
135
 
            self._unregister_plugin('plugin')
136
 
        self.assertPluginUnknown('plugin')
 
102
            if 'bzrlib.plugins.plugin' in sys.modules:
 
103
                del sys.modules['bzrlib.plugins.plugin']
 
104
            if getattr(bzrlib.plugins, 'plugin', None):
 
105
                del bzrlib.plugins.plugin
 
106
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
137
107
 
138
108
    def test_plugins_from_different_dirs_can_demand_load(self):
139
 
        self.failIf('bzrlib.plugins.pluginone' in sys.modules)
140
 
        self.failIf('bzrlib.plugins.plugintwo' in sys.modules)
141
109
        # This test tests that having two plugins in different
142
110
        # directories with different names allows them both to be loaded, when
143
111
        # we do a direct import statement.
175
143
 
176
144
        oldpath = bzrlib.plugins.__path__
177
145
        try:
178
 
            self.failIf('bzrlib.plugins.pluginone' in sys.modules)
179
 
            self.failIf('bzrlib.plugins.plugintwo' in sys.modules)
180
146
            bzrlib.plugins.__path__ = ['first', 'second']
181
147
            exec "import bzrlib.plugins.pluginone"
182
148
            self.assertEqual(['first'], self.activeattributes[tempattribute])
186
152
        finally:
187
153
            # remove the plugin 'plugin'
188
154
            del self.activeattributes[tempattribute]
189
 
            self._unregister_plugin('pluginone')
190
 
            self._unregister_plugin('plugintwo')
191
 
        self.assertPluginUnknown('pluginone')
192
 
        self.assertPluginUnknown('plugintwo')
 
155
            if getattr(bzrlib.plugins, 'pluginone', None):
 
156
                del bzrlib.plugins.pluginone
 
157
            if getattr(bzrlib.plugins, 'plugintwo', None):
 
158
                del bzrlib.plugins.plugintwo
 
159
        self.failIf(getattr(bzrlib.plugins, 'pluginone', None))
 
160
        self.failIf(getattr(bzrlib.plugins, 'plugintwo', None))
193
161
 
194
162
    def test_plugins_can_load_from_directory_with_trailing_slash(self):
195
163
        # This test tests that a plugin can load from a directory when the
196
164
        # directory in the path has a trailing slash.
197
165
        # check the plugin is not loaded already
198
 
        self.assertPluginUnknown('ts_plugin')
 
166
        self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
199
167
        tempattribute = "trailing-slash"
200
168
        self.failIf(tempattribute in self.activeattributes)
201
169
        # set a place for the plugin to record its loading, and at the same
222
190
            bzrlib.plugin.load_from_path(['plugin_test'+os.sep])
223
191
            self.assertEqual(['plugin'], self.activeattributes[tempattribute])
224
192
        finally:
 
193
            # remove the plugin 'plugin'
225
194
            del self.activeattributes[tempattribute]
226
 
            self._unregister_plugin('ts_plugin')
227
 
        self.assertPluginUnknown('ts_plugin')
 
195
            if getattr(bzrlib.plugins, 'ts_plugin', None):
 
196
                del bzrlib.plugins.ts_plugin
 
197
        self.failIf(getattr(bzrlib.plugins, 'ts_plugin', None))
228
198
 
229
199
    def load_and_capture(self, name):
230
200
        """Load plugins from '.' capturing the output.
281
251
            "it to 'bad_plugin_name_'\.")
282
252
 
283
253
 
284
 
class TestPlugins(tests.TestCaseInTempDir, TestPluginMixin):
 
254
class TestPlugins(TestCaseInTempDir):
285
255
 
286
256
    def setup_plugin(self, source=""):
287
257
        # This test tests a new plugin appears in bzrlib.plugin.plugins().
288
258
        # check the plugin is not loaded already
289
 
        self.assertPluginUnknown('plugin')
 
259
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
290
260
        # write a plugin that _cannot_ fail to load.
291
261
        file('plugin.py', 'w').write(source + '\n')
292
262
        self.addCleanup(self.teardown_plugin)
293
 
        plugin.load_from_path(['.'])
 
263
        bzrlib.plugin.load_from_path(['.'])
294
264
 
295
265
    def teardown_plugin(self):
296
 
        self._unregister_plugin('plugin')
297
 
        self.assertPluginUnknown('plugin')
 
266
        # remove the plugin 'plugin'
 
267
        if 'bzrlib.plugins.plugin' in sys.modules:
 
268
            del sys.modules['bzrlib.plugins.plugin']
 
269
        if getattr(bzrlib.plugins, 'plugin', None):
 
270
            del bzrlib.plugins.plugin
 
271
        self.failIf(getattr(bzrlib.plugins, 'plugin', None))
298
272
 
299
273
    def test_plugin_appears_in_plugins(self):
300
274
        self.setup_plugin()
301
 
        self.assertPluginKnown('plugin')
302
 
        p = plugin.plugins()['plugin']
303
 
        self.assertIsInstance(p, bzrlib.plugin.PlugIn)
304
 
        self.assertEqual(p.module, plugins.plugin)
 
275
        self.failUnless('plugin' in bzrlib.plugin.plugins())
 
276
        self.failUnless(getattr(bzrlib.plugins, 'plugin', None))
 
277
        plugins = bzrlib.plugin.plugins()
 
278
        plugin = plugins['plugin']
 
279
        self.assertIsInstance(plugin, bzrlib.plugin.PlugIn)
 
280
        self.assertEqual(bzrlib.plugins.plugin, plugin.module)
305
281
 
306
282
    def test_trivial_plugin_get_path(self):
307
283
        self.setup_plugin()
308
 
        p = plugin.plugins()['plugin']
 
284
        plugins = bzrlib.plugin.plugins()
 
285
        plugin = plugins['plugin']
309
286
        plugin_path = self.test_dir + '/plugin.py'
310
 
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
 
287
        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
311
288
 
312
289
    def test_plugin_get_path_py_not_pyc(self):
313
 
        # first import creates plugin.pyc
314
 
        self.setup_plugin()
 
290
        self.setup_plugin()         # after first import there will be plugin.pyc
315
291
        self.teardown_plugin()
316
 
        plugin.load_from_path(['.']) # import plugin.pyc
317
 
        p = plugin.plugins()['plugin']
 
292
        bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
 
293
        plugins = bzrlib.plugin.plugins()
 
294
        plugin = plugins['plugin']
318
295
        plugin_path = self.test_dir + '/plugin.py'
319
 
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
 
296
        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
320
297
 
321
298
    def test_plugin_get_path_pyc_only(self):
322
 
        # first import creates plugin.pyc (or plugin.pyo depending on __debug__)
323
 
        self.setup_plugin()
 
299
        self.setup_plugin()         # after first import there will be plugin.pyc
324
300
        self.teardown_plugin()
325
301
        os.unlink(self.test_dir + '/plugin.py')
326
 
        plugin.load_from_path(['.']) # import plugin.pyc (or .pyo)
327
 
        p = plugin.plugins()['plugin']
 
302
        bzrlib.plugin.load_from_path(['.']) # import plugin.pyc
 
303
        plugins = bzrlib.plugin.plugins()
 
304
        plugin = plugins['plugin']
328
305
        if __debug__:
329
306
            plugin_path = self.test_dir + '/plugin.pyc'
330
307
        else:
331
308
            plugin_path = self.test_dir + '/plugin.pyo'
332
 
        self.assertIsSameRealPath(plugin_path, osutils.normpath(p.path()))
 
309
        self.assertIsSameRealPath(plugin_path, normpath(plugin.path()))
333
310
 
334
311
    def test_no_test_suite_gives_None_for_test_suite(self):
335
312
        self.setup_plugin()
336
 
        p = plugin.plugins()['plugin']
337
 
        self.assertEqual(None, p.test_suite())
 
313
        plugin = bzrlib.plugin.plugins()['plugin']
 
314
        self.assertEqual(None, plugin.test_suite())
338
315
 
339
316
    def test_test_suite_gives_test_suite_result(self):
340
317
        source = """def test_suite(): return 'foo'"""
341
318
        self.setup_plugin(source)
342
 
        p = plugin.plugins()['plugin']
343
 
        self.assertEqual('foo', p.test_suite())
 
319
        plugin = bzrlib.plugin.plugins()['plugin']
 
320
        self.assertEqual('foo', plugin.test_suite())
344
321
 
345
322
    def test_no_load_plugin_tests_gives_None_for_load_plugin_tests(self):
346
323
        self.setup_plugin()
347
 
        loader = tests.TestUtil.TestLoader()
348
 
        p = plugin.plugins()['plugin']
349
 
        self.assertEqual(None, p.load_plugin_tests(loader))
 
324
        loader = TestUtil.TestLoader()
 
325
        plugin = bzrlib.plugin.plugins()['plugin']
 
326
        self.assertEqual(None, plugin.load_plugin_tests(loader))
350
327
 
351
328
    def test_load_plugin_tests_gives_load_plugin_tests_result(self):
352
329
        source = """
353
330
def load_tests(standard_tests, module, loader):
354
331
    return 'foo'"""
355
332
        self.setup_plugin(source)
356
 
        loader = tests.TestUtil.TestLoader()
357
 
        p = plugin.plugins()['plugin']
358
 
        self.assertEqual('foo', p.load_plugin_tests(loader))
359
 
 
360
 
    def check_version_info(self, expected, source='', name='plugin'):
361
 
        self.setup_plugin(source)
362
 
        self.assertEqual(expected, plugin.plugins()[name].version_info())
 
333
        loader = TestUtil.TestLoader()
 
334
        plugin = bzrlib.plugin.plugins()['plugin']
 
335
        self.assertEqual('foo', plugin.load_plugin_tests(loader))
363
336
 
364
337
    def test_no_version_info(self):
365
 
        self.check_version_info(None)
 
338
        self.setup_plugin()
 
339
        plugin = bzrlib.plugin.plugins()['plugin']
 
340
        self.assertEqual(None, plugin.version_info())
366
341
 
367
342
    def test_with_version_info(self):
368
 
        self.check_version_info((1, 2, 3, 'dev', 4),
369
 
                                "version_info = (1, 2, 3, 'dev', 4)")
 
343
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)")
 
344
        plugin = bzrlib.plugin.plugins()['plugin']
 
345
        self.assertEqual((1, 2, 3, 'dev', 4), plugin.version_info())
370
346
 
371
347
    def test_short_version_info_gets_padded(self):
372
348
        # the gtk plugin has version_info = (1,2,3) rather than the 5-tuple.
373
349
        # so we adapt it
374
 
        self.check_version_info((1, 2, 3, 'final', 0),
375
 
                                "version_info = (1, 2, 3)")
376
 
 
377
 
    def check_version(self, expected, source=None, name='plugin'):
378
 
        self.setup_plugin(source)
379
 
        self.assertEqual(expected, plugins[name].__version__)
 
350
        self.setup_plugin("version_info = (1, 2, 3)")
 
351
        plugin = bzrlib.plugin.plugins()['plugin']
 
352
        self.assertEqual((1, 2, 3, 'final', 0), plugin.version_info())
380
353
 
381
354
    def test_no_version_info___version__(self):
382
355
        self.setup_plugin()
434
407
        self.assertEqual("1.2.3.final.2", plugin.__version__)
435
408
 
436
409
 
437
 
class TestPluginHelp(tests.TestCaseInTempDir):
 
410
class TestPluginHelp(TestCaseInTempDir):
438
411
 
439
412
    def split_help_commands(self):
440
413
        help = {}
469
442
    def test_plugin_help_shows_plugin(self):
470
443
        # Create a test plugin
471
444
        os.mkdir('plugin_test')
472
 
        f = open(osutils.pathjoin('plugin_test', 'myplug.py'), 'w')
473
 
        f.write("""\
474
 
from bzrlib import commands
475
 
class cmd_myplug(commands.Command):
476
 
    __doc__ = '''Just a simple test plugin.'''
477
 
    aliases = ['mplg']
478
 
    def run(self):
479
 
        print 'Hello from my plugin'
480
 
 
481
 
"""
482
 
)
 
445
        f = open(pathjoin('plugin_test', 'myplug.py'), 'w')
 
446
        f.write(PLUGIN_TEXT)
483
447
        f.close()
484
448
 
485
449
        try:
663
627
        self.assertEqual(path, bzrlib.plugins.__path__)
664
628
 
665
629
 
666
 
class TestEnvPluginPath(tests.TestCase):
 
630
class TestEnvPluginPath(tests.TestCaseInTempDir):
667
631
 
668
632
    def setUp(self):
669
633
        super(TestEnvPluginPath, self).setUp()
716
680
        self.check_path([self.user, self.core, self.site],
717
681
                        ['+user', '+user'])
718
682
        # And only the first reference is kept (since the later references will
719
 
        # only produce '<plugin> already loaded' mutters)
 
683
        # onnly produce <plugin> already loaded mutters)
720
684
        self.check_path([self.user, self.core, self.site],
721
685
                        ['+user', '+user', '+core',
722
686
                         '+user', '+site', '+site',
723
687
                         '+core'])
724
688
 
725
 
    def test_disable_overrides_enable(self):
 
689
    def test_disable_overrides_disable(self):
726
690
        self.check_path([self.core, self.site], ['-user', '+user'])
727
691
 
728
692
    def test_disable_core(self):
755
719
    def test_bogus_references(self):
756
720
        self.check_path(['+foo', '-bar', self.core, self.site],
757
721
                        ['+foo', '-bar'])
758
 
 
759
 
 
760
 
class TestDisablePlugin(tests.TestCaseInTempDir, TestPluginMixin):
761
 
 
762
 
    def setUp(self):
763
 
        super(TestDisablePlugin, self).setUp()
764
 
        self.create_plugin_package('test_foo')
765
 
        # Make sure we don't pollute the plugins namespace
766
 
        self.overrideAttr(plugins, '__path__')
767
 
        # Be paranoid in case a test fail
768
 
        self.addCleanup(self._unregister_plugin, 'test_foo')
769
 
 
770
 
    def test_cannot_import(self):
771
 
        osutils.set_or_unset_env('BZR_DISABLE_PLUGINS', 'test_foo')
772
 
        plugin.set_plugins_path(['.'])
773
 
        try:
774
 
            import bzrlib.plugins.test_foo
775
 
        except ImportError:
776
 
            pass
777
 
        self.assertPluginUnknown('test_foo')
778
 
 
779
 
    def test_regular_load(self):
780
 
        self.overrideAttr(plugin, '_loaded', False)
781
 
        plugin.load_plugins(['.'])
782
 
        self.assertPluginKnown('test_foo')
783
 
        self.assertDocstring("This is the doc for test_foo",
784
 
                             bzrlib.plugins.test_foo)
785
 
 
786
 
    def test_not_loaded(self):
787
 
        self.warnings = []
788
 
        def captured_warning(*args, **kwargs):
789
 
            self.warnings.append((args, kwargs))
790
 
        self.overrideAttr(trace, 'warning', captured_warning)
791
 
        # Reset the flag that protect against double loading
792
 
        self.overrideAttr(plugin, '_loaded', False)
793
 
        osutils.set_or_unset_env('BZR_DISABLE_PLUGINS', 'test_foo')
794
 
        plugin.load_plugins(['.'])
795
 
        self.assertPluginUnknown('test_foo')
796
 
        # Make sure we don't warn about the plugin ImportError since this has
797
 
        # been *requested* by the user.
798
 
        self.assertLength(0, self.warnings)
799
 
 
800
 
 
801
 
class TestLoadPluginAt(tests.TestCaseInTempDir, TestPluginMixin):
802
 
 
803
 
    def setUp(self):
804
 
        super(TestLoadPluginAt, self).setUp()
805
 
        # Make sure we don't pollute the plugins namespace
806
 
        self.overrideAttr(plugins, '__path__')
807
 
        # Be paranoid in case a test fail
808
 
        self.addCleanup(self._unregister_plugin, 'test_foo')
809
 
        # Reset the flag that protect against double loading
810
 
        self.overrideAttr(plugin, '_loaded', False)
811
 
        # Create the same plugin in two directories
812
 
        self.create_plugin_package('test_foo', dir='non-standard-dir')
813
 
        # The "normal" directory, we use 'standard' instead of 'plugins' to
814
 
        # avoid depending on the precise naming.
815
 
        self.create_plugin_package('test_foo', dir='standard/test_foo')
816
 
 
817
 
    def assertTestFooLoadedFrom(self, path):
818
 
        self.assertPluginKnown('test_foo')
819
 
        self.assertDocstring('This is the doc for test_foo',
820
 
                             bzrlib.plugins.test_foo)
821
 
        self.assertEqual(path, bzrlib.plugins.test_foo.dir_source)
822
 
 
823
 
    def test_regular_load(self):
824
 
        plugin.load_plugins(['standard'])
825
 
        self.assertTestFooLoadedFrom('standard/test_foo')
826
 
 
827
 
    def test_import(self):
828
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
829
 
        plugin.set_plugins_path(['standard'])
830
 
        try:
831
 
            import bzrlib.plugins.test_foo
832
 
        except ImportError:
833
 
            pass
834
 
        self.assertTestFooLoadedFrom('non-standard-dir')
835
 
 
836
 
    def test_loading(self):
837
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
838
 
        plugin.load_plugins(['standard'])
839
 
        self.assertTestFooLoadedFrom('non-standard-dir')
840
 
 
841
 
    def test_compiled_loaded(self):
842
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
843
 
        plugin.load_plugins(['standard'])
844
 
        self.assertTestFooLoadedFrom('non-standard-dir')
845
 
        self.assertEqual('non-standard-dir/__init__.py',
846
 
                         bzrlib.plugins.test_foo.__file__)
847
 
 
848
 
        # Try importing again now that the source has been compiled
849
 
        self._unregister_plugin('test_foo')
850
 
        plugin._loaded = False
851
 
        plugin.load_plugins(['standard'])
852
 
        self.assertTestFooLoadedFrom('non-standard-dir')
853
 
        if __debug__:
854
 
            suffix = 'pyc'
855
 
        else:
856
 
            suffix = 'pyo'
857
 
        self.assertEqual('non-standard-dir/__init__.%s' % suffix,
858
 
                         bzrlib.plugins.test_foo.__file__)
859
 
 
860
 
    def test_submodule_loading(self):
861
 
        # We create an additional directory under the one for test_foo
862
 
        self.create_plugin_package('test_bar', dir='non-standard-dir/test_bar')
863
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
864
 
        plugin.set_plugins_path(['standard'])
865
 
        import bzrlib.plugins.test_foo
866
 
        self.assertEqual('bzrlib.plugins.test_foo',
867
 
                         bzrlib.plugins.test_foo.__package__)
868
 
        import bzrlib.plugins.test_foo.test_bar
869
 
        self.assertEqual('non-standard-dir/test_bar/__init__.py',
870
 
                         bzrlib.plugins.test_foo.test_bar.__file__)
871
 
 
872
 
    def test_loading_from___init__only(self):
873
 
        # We rename the existing __init__.py file to ensure that we don't load
874
 
        # a random file
875
 
        init = 'non-standard-dir/__init__.py'
876
 
        random = 'non-standard-dir/setup.py'
877
 
        os.rename(init, random)
878
 
        self.addCleanup(os.rename, random, init)
879
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
880
 
        plugin.load_plugins(['standard'])
881
 
        self.assertPluginUnknown('test_foo')
882
 
 
883
 
    def test_loading_from_specific_file(self):
884
 
        plugin_dir = 'non-standard-dir'
885
 
        plugin_file_name = 'iamtestfoo.py'
886
 
        plugin_path = osutils.pathjoin(plugin_dir, plugin_file_name)
887
 
        source = '''\
888
 
"""This is the doc for %s"""
889
 
dir_source = '%s'
890
 
''' % ('test_foo', plugin_path)
891
 
        self.create_plugin('test_foo', source=source,
892
 
                           dir=plugin_dir, file_name=plugin_file_name)
893
 
        osutils.set_or_unset_env('BZR_PLUGINS_AT', 'test_foo@%s' % plugin_path)
894
 
        plugin.load_plugins(['standard'])
895
 
        self.assertTestFooLoadedFrom(plugin_path)