/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test_plugins.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for plugins"""
18
18
 
19
19
# XXX: There are no plugin tests at the moment because the plugin module
20
 
# affects the global state of the process.  See bzrlib/plugins.py for more
 
20
# affects the global state of the process.  See breezy/plugins.py for more
21
21
# comments.
22
22
 
23
 
from cStringIO import StringIO
24
23
import logging
25
24
import os
26
25
import sys
27
26
 
28
 
import bzrlib
29
 
from bzrlib import (
 
27
import breezy
 
28
from .. import (
30
29
    errors,
31
30
    osutils,
32
31
    plugin,
34
33
    tests,
35
34
    trace,
36
35
    )
 
36
from ..sixish import (
 
37
    BytesIO,
 
38
    )
37
39
 
38
40
 
39
41
# TODO: Write a test for plugin decoration of commands.
73
75
                           file_name='__init__.py')
74
76
 
75
77
    def _unregister_plugin(self, name):
76
 
        """Remove the plugin from sys.modules and the bzrlib namespace."""
77
 
        py_name = 'bzrlib.plugins.%s' % name
 
78
        """Remove the plugin from sys.modules and the breezy namespace."""
 
79
        py_name = 'breezy.plugins.%s' % name
78
80
        if py_name in sys.modules:
79
81
            del sys.modules[py_name]
80
 
        if getattr(bzrlib.plugins, name, None) is not None:
81
 
            delattr(bzrlib.plugins, name)
 
82
        if getattr(breezy.plugins, name, None) is not None:
 
83
            delattr(breezy.plugins, name)
82
84
 
83
85
    def _unregister_plugin_submodule(self, plugin_name, submodule_name):
84
 
        """Remove the submodule from sys.modules and the bzrlib namespace."""
85
 
        py_name = 'bzrlib.plugins.%s.%s' % (plugin_name, submodule_name)
 
86
        """Remove the submodule from sys.modules and the breezy namespace."""
 
87
        py_name = 'breezy.plugins.%s.%s' % (plugin_name, submodule_name)
86
88
        if py_name in sys.modules:
87
89
            del sys.modules[py_name]
88
 
        plugin = getattr(bzrlib.plugins, plugin_name, None)
 
90
        plugin = getattr(breezy.plugins, plugin_name, None)
89
91
        if plugin is not None:
90
92
            if getattr(plugin, submodule_name, None) is not None:
91
93
                delattr(plugin, submodule_name)
92
94
 
93
95
    def assertPluginUnknown(self, name):
94
 
        self.assertFalse(getattr(bzrlib.plugins, name, None) is not None)
95
 
        self.assertFalse('bzrlib.plugins.%s' % name in sys.modules)
 
96
        self.assertFalse(getattr(breezy.plugins, name, None) is not None)
 
97
        self.assertFalse('breezy.plugins.%s' % name in sys.modules)
96
98
 
97
99
    def assertPluginKnown(self, name):
98
 
        self.assertTrue(getattr(bzrlib.plugins, name, None) is not None)
99
 
        self.assertTrue('bzrlib.plugins.%s' % name in sys.modules)
 
100
        self.assertTrue(getattr(breezy.plugins, name, None) is not None)
 
101
        self.assertTrue('breezy.plugins.%s' % name in sys.modules)
100
102
 
101
103
 
102
104
class TestLoadingPlugins(BaseTestPlugins):
120
122
        os.mkdir('second')
121
123
        # write a plugin that will record when its loaded in the
122
124
        # tempattribute list.
123
 
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
 
125
        template = ("from breezy.tests.test_plugins import TestLoadingPlugins\n"
124
126
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
125
127
 
126
128
        outfile = open(os.path.join('first', 'plugin.py'), 'w')
138
140
            outfile.close()
139
141
 
140
142
        try:
141
 
            bzrlib.plugin.load_from_path(['first', 'second'])
 
143
            breezy.plugin.load_from_path(['first', 'second'])
142
144
            self.assertEqual(['first'], self.activeattributes[tempattribute])
143
145
        finally:
144
146
            # remove the plugin 'plugin'
147
149
        self.assertPluginUnknown('plugin')
148
150
 
149
151
    def test_plugins_from_different_dirs_can_demand_load(self):
150
 
        self.assertFalse('bzrlib.plugins.pluginone' in sys.modules)
151
 
        self.assertFalse('bzrlib.plugins.plugintwo' in sys.modules)
 
152
        self.assertFalse('breezy.plugins.pluginone' in sys.modules)
 
153
        self.assertFalse('breezy.plugins.plugintwo' in sys.modules)
152
154
        # This test tests that having two plugins in different
153
155
        # directories with different names allows them both to be loaded, when
154
156
        # we do a direct import statement.
159
161
        # set a place for the plugins to record their loading, and at the same
160
162
        # time validate that the location the plugins should record to is
161
163
        # valid and correct.
162
 
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
 
164
        breezy.tests.test_plugins.TestLoadingPlugins.activeattributes \
163
165
            [tempattribute] = []
164
166
        self.assertTrue(tempattribute in self.activeattributes)
165
167
        # create two plugin directories
167
169
        os.mkdir('second')
168
170
        # write plugins that will record when they are loaded in the
169
171
        # tempattribute list.
170
 
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
 
172
        template = ("from breezy.tests.test_plugins import TestLoadingPlugins\n"
171
173
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
172
174
 
173
175
        outfile = open(os.path.join('first', 'pluginone.py'), 'w')
184
186
        finally:
185
187
            outfile.close()
186
188
 
187
 
        oldpath = bzrlib.plugins.__path__
 
189
        oldpath = breezy.plugins.__path__
188
190
        try:
189
 
            self.assertFalse('bzrlib.plugins.pluginone' in sys.modules)
190
 
            self.assertFalse('bzrlib.plugins.plugintwo' in sys.modules)
191
 
            bzrlib.plugins.__path__ = ['first', 'second']
192
 
            exec "import bzrlib.plugins.pluginone"
 
191
            self.assertFalse('breezy.plugins.pluginone' in sys.modules)
 
192
            self.assertFalse('breezy.plugins.plugintwo' in sys.modules)
 
193
            breezy.plugins.__path__ = ['first', 'second']
 
194
            exec("import breezy.plugins.pluginone")
193
195
            self.assertEqual(['first'], self.activeattributes[tempattribute])
194
 
            exec "import bzrlib.plugins.plugintwo"
 
196
            exec("import breezy.plugins.plugintwo")
195
197
            self.assertEqual(['first', 'second'],
196
198
                self.activeattributes[tempattribute])
197
199
        finally:
212
214
        # set a place for the plugin to record its loading, and at the same
213
215
        # time validate that the location the plugin should record to is
214
216
        # valid and correct.
215
 
        bzrlib.tests.test_plugins.TestLoadingPlugins.activeattributes \
 
217
        breezy.tests.test_plugins.TestLoadingPlugins.activeattributes \
216
218
            [tempattribute] = []
217
219
        self.assertTrue(tempattribute in self.activeattributes)
218
220
        # create a directory for the plugin
219
221
        os.mkdir('plugin_test')
220
222
        # write a plugin that will record when its loaded in the
221
223
        # tempattribute list.
222
 
        template = ("from bzrlib.tests.test_plugins import TestLoadingPlugins\n"
 
224
        template = ("from breezy.tests.test_plugins import TestLoadingPlugins\n"
223
225
                    "TestLoadingPlugins.activeattributes[%r].append('%s')\n")
224
226
 
225
227
        outfile = open(os.path.join('plugin_test', 'ts_plugin.py'), 'w')
230
232
            outfile.close()
231
233
 
232
234
        try:
233
 
            bzrlib.plugin.load_from_path(['plugin_test'+os.sep])
 
235
            breezy.plugin.load_from_path(['plugin_test'+os.sep])
234
236
            self.assertEqual(['plugin'], self.activeattributes[tempattribute])
235
237
        finally:
236
238
            del self.activeattributes[tempattribute]
244
246
        :return: A string with the log from the plugin loading call.
245
247
        """
246
248
        # Capture output
247
 
        stream = StringIO()
 
249
        stream = BytesIO()
248
250
        try:
249
251
            handler = logging.StreamHandler(stream)
250
 
            log = logging.getLogger('bzr')
 
252
            log = logging.getLogger('brz')
251
253
            log.addHandler(handler)
252
254
            try:
253
255
                try:
254
 
                    bzrlib.plugin.load_from_path(['.'])
 
256
                    breezy.plugin.load_from_path(['.'])
255
257
                finally:
256
 
                    if 'bzrlib.plugins.%s' % name in sys.modules:
257
 
                        del sys.modules['bzrlib.plugins.%s' % name]
258
 
                    if getattr(bzrlib.plugins, name, None):
259
 
                        delattr(bzrlib.plugins, name)
 
258
                    if 'breezy.plugins.%s' % name in sys.modules:
 
259
                        del sys.modules['breezy.plugins.%s' % name]
 
260
                    if getattr(breezy.plugins, name, None):
 
261
                        delattr(breezy.plugins, name)
260
262
            finally:
261
263
                # Stop capturing output
262
264
                handler.flush()
277
279
        name = 'wants100.py'
278
280
        f = file(name, 'w')
279
281
        try:
280
 
            f.write("import bzrlib.api\n"
281
 
                "bzrlib.api.require_any_api(bzrlib, [(1, 0, 0)])\n")
 
282
            f.write("import breezy.api\n"
 
283
                "breezy.api.require_any_api(breezy, [(1, 0, 0)])\n")
282
284
        finally:
283
285
            f.close()
284
286
        log = self.load_and_capture(name)
293
295
 
294
296
    def test_plugin_with_bad_name_does_not_load(self):
295
297
        # The file name here invalid for a python module.
296
 
        name = 'bzr-bad plugin-name..py'
 
298
        name = 'brz-bad plugin-name..py'
297
299
        file(name, 'w').close()
298
300
        log = self.load_and_capture(name)
299
301
        self.assertContainsRe(log,
300
 
            r"Unable to load 'bzr-bad plugin-name\.' in '\.' as a plugin "
 
302
            r"Unable to load 'brz-bad plugin-name\.' in '\.' as a plugin "
301
303
            "because the file path isn't a valid module name; try renaming "
302
304
            "it to 'bad_plugin_name_'\.")
303
305
 
305
307
class TestPlugins(BaseTestPlugins):
306
308
 
307
309
    def setup_plugin(self, source=""):
308
 
        # This test tests a new plugin appears in bzrlib.plugin.plugins().
 
310
        # This test tests a new plugin appears in breezy.plugin.plugins().
309
311
        # check the plugin is not loaded already
310
312
        self.assertPluginUnknown('plugin')
311
313
        # write a plugin that _cannot_ fail to load.
321
323
        self.setup_plugin()
322
324
        self.assertPluginKnown('plugin')
323
325
        p = plugin.plugins()['plugin']
324
 
        self.assertIsInstance(p, bzrlib.plugin.PlugIn)
 
326
        self.assertIsInstance(p, breezy.plugin.PlugIn)
325
327
        self.assertEqual(p.module, plugins.plugin)
326
328
 
327
329
    def test_trivial_plugin_get_path(self):
371
373
 
372
374
    def test_load_plugin_tests_gives_load_plugin_tests_result(self):
373
375
        source = """
374
 
def load_tests(standard_tests, module, loader):
 
376
def load_tests(loader, standard_tests, pattern):
375
377
    return 'foo'"""
376
378
        self.setup_plugin(source)
377
379
        loader = tests.TestUtil.TestLoader()
401
403
 
402
404
    def test_no_version_info___version__(self):
403
405
        self.setup_plugin()
404
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
406
        plugin = breezy.plugin.plugins()['plugin']
405
407
        self.assertEqual("unknown", plugin.__version__)
406
408
 
407
409
    def test_str__version__with_version_info(self):
408
410
        self.setup_plugin("version_info = '1.2.3'")
409
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
411
        plugin = breezy.plugin.plugins()['plugin']
410
412
        self.assertEqual("1.2.3", plugin.__version__)
411
413
 
412
414
    def test_noniterable__version__with_version_info(self):
413
415
        self.setup_plugin("version_info = (1)")
414
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
416
        plugin = breezy.plugin.plugins()['plugin']
415
417
        self.assertEqual("1", plugin.__version__)
416
418
 
417
419
    def test_1__version__with_version_info(self):
418
420
        self.setup_plugin("version_info = (1,)")
419
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
421
        plugin = breezy.plugin.plugins()['plugin']
420
422
        self.assertEqual("1", plugin.__version__)
421
423
 
422
424
    def test_1_2__version__with_version_info(self):
423
425
        self.setup_plugin("version_info = (1, 2)")
424
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
426
        plugin = breezy.plugin.plugins()['plugin']
425
427
        self.assertEqual("1.2", plugin.__version__)
426
428
 
427
429
    def test_1_2_3__version__with_version_info(self):
428
430
        self.setup_plugin("version_info = (1, 2, 3)")
429
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
431
        plugin = breezy.plugin.plugins()['plugin']
430
432
        self.assertEqual("1.2.3", plugin.__version__)
431
433
 
432
434
    def test_candidate__version__with_version_info(self):
433
435
        self.setup_plugin("version_info = (1, 2, 3, 'candidate', 1)")
434
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
436
        plugin = breezy.plugin.plugins()['plugin']
435
437
        self.assertEqual("1.2.3rc1", plugin.__version__)
436
438
 
437
439
    def test_dev__version__with_version_info(self):
438
440
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 0)")
439
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
441
        plugin = breezy.plugin.plugins()['plugin']
440
442
        self.assertEqual("1.2.3dev", plugin.__version__)
441
443
 
442
444
    def test_dev_fallback__version__with_version_info(self):
443
445
        self.setup_plugin("version_info = (1, 2, 3, 'dev', 4)")
444
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
446
        plugin = breezy.plugin.plugins()['plugin']
445
447
        self.assertEqual("1.2.3dev4", plugin.__version__)
446
448
 
447
449
    def test_final__version__with_version_info(self):
448
450
        self.setup_plugin("version_info = (1, 2, 3, 'final', 0)")
449
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
451
        plugin = breezy.plugin.plugins()['plugin']
450
452
        self.assertEqual("1.2.3", plugin.__version__)
451
453
 
452
454
    def test_final_fallback__version__with_version_info(self):
453
455
        self.setup_plugin("version_info = (1, 2, 3, 'final', 2)")
454
 
        plugin = bzrlib.plugin.plugins()['plugin']
 
456
        plugin = breezy.plugin.plugins()['plugin']
455
457
        self.assertEqual("1.2.3.2", plugin.__version__)
456
458
 
457
459
 
471
473
    def test_plugin_help_builtins_unaffected(self):
472
474
        # Check we don't get false positives
473
475
        help_commands = self.split_help_commands()
474
 
        for cmd_name in bzrlib.commands.builtin_command_names():
475
 
            if cmd_name in bzrlib.commands.plugin_command_names():
 
476
        for cmd_name in breezy.commands.builtin_command_names():
 
477
            if cmd_name in breezy.commands.plugin_command_names():
476
478
                continue
477
479
            try:
478
 
                help = bzrlib.commands.get_cmd_object(cmd_name).get_help_text()
 
480
                help = breezy.commands.get_cmd_object(cmd_name).get_help_text()
479
481
            except NotImplementedError:
480
482
                # some commands have no help
481
483
                pass
492
494
        os.mkdir('plugin_test')
493
495
        f = open(osutils.pathjoin('plugin_test', 'myplug.py'), 'w')
494
496
        f.write("""\
495
 
from bzrlib import commands
 
497
from breezy import commands
496
498
class cmd_myplug(commands.Command):
497
499
    __doc__ = '''Just a simple test plugin.'''
498
500
    aliases = ['mplg']
505
507
 
506
508
        try:
507
509
            # Check its help
508
 
            bzrlib.plugin.load_from_path(['plugin_test'])
509
 
            bzrlib.commands.register_command( bzrlib.plugins.myplug.cmd_myplug)
 
510
            breezy.plugin.load_from_path(['plugin_test'])
 
511
            breezy.commands.register_command( breezy.plugins.myplug.cmd_myplug)
510
512
            help = self.run_bzr('help myplug')[0]
511
513
            self.assertContainsRe(help, 'plugin "myplug"')
512
514
            help = self.split_help_commands()['myplug']
513
515
            self.assertContainsRe(help, '\[myplug\]')
514
516
        finally:
515
517
            # unregister command
516
 
            if 'myplug' in bzrlib.commands.plugin_cmds:
517
 
                bzrlib.commands.plugin_cmds.remove('myplug')
 
518
            if 'myplug' in breezy.commands.plugin_cmds:
 
519
                breezy.commands.plugin_cmds.remove('myplug')
518
520
            # remove the plugin 'myplug'
519
 
            if getattr(bzrlib.plugins, 'myplug', None):
520
 
                delattr(bzrlib.plugins, 'myplug')
 
521
            if getattr(breezy.plugins, 'myplug', None):
 
522
                delattr(breezy.plugins, 'myplug')
521
523
 
522
524
 
523
525
class TestHelpIndex(tests.TestCase):
536
538
        index = plugin.PluginsHelpIndex()
537
539
        # make a new plugin here for this test, even if we're run with
538
540
        # --no-plugins
539
 
        self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
540
 
        demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
541
 
        sys.modules['bzrlib.plugins.demo_module'] = demo_module
 
541
        self.assertFalse('breezy.plugins.demo_module' in sys.modules)
 
542
        demo_module = FakeModule('', 'breezy.plugins.demo_module')
 
543
        sys.modules['breezy.plugins.demo_module'] = demo_module
542
544
        try:
543
545
            topics = index.get_topics('demo_module')
544
546
            self.assertEqual(1, len(topics))
545
547
            self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
546
548
            self.assertEqual(demo_module, topics[0].module)
547
549
        finally:
548
 
            del sys.modules['bzrlib.plugins.demo_module']
 
550
            del sys.modules['breezy.plugins.demo_module']
549
551
 
550
552
    def test_get_topics_no_topic(self):
551
553
        """Searching for something that is not a plugin returns []."""
562
564
    def test_get_plugin_topic_with_prefix(self):
563
565
        """Searching for plugins/demo_module returns help."""
564
566
        index = plugin.PluginsHelpIndex()
565
 
        self.assertFalse(sys.modules.has_key('bzrlib.plugins.demo_module'))
566
 
        demo_module = FakeModule('', 'bzrlib.plugins.demo_module')
567
 
        sys.modules['bzrlib.plugins.demo_module'] = demo_module
 
567
        self.assertFalse('breezy.plugins.demo_module' in sys.modules)
 
568
        demo_module = FakeModule('', 'breezy.plugins.demo_module')
 
569
        sys.modules['breezy.plugins.demo_module'] = demo_module
568
570
        try:
569
571
            topics = index.get_topics('plugins/demo_module')
570
572
            self.assertEqual(1, len(topics))
571
573
            self.assertIsInstance(topics[0], plugin.ModuleHelpTopic)
572
574
            self.assertEqual(demo_module, topics[0].module)
573
575
        finally:
574
 
            del sys.modules['bzrlib.plugins.demo_module']
 
576
            del sys.modules['breezy.plugins.demo_module']
575
577
 
576
578
 
577
579
class FakeModule(object):
620
622
 
621
623
    def test_get_help_topic(self):
622
624
        """The help topic for a plugin is its module name."""
623
 
        mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.demo')
 
625
        mod = FakeModule('two lines of help\nand more', 'breezy.plugins.demo')
624
626
        topic = plugin.ModuleHelpTopic(mod)
625
627
        self.assertEqual('demo', topic.get_help_topic())
626
628
        mod = FakeModule('two lines of help\nand more',
627
 
                         'bzrlib.plugins.foo_bar')
 
629
                         'breezy.plugins.foo_bar')
628
630
        topic = plugin.ModuleHelpTopic(mod)
629
631
        self.assertEqual('foo_bar', topic.get_help_topic())
630
632
 
633
635
 
634
636
    def setUp(self):
635
637
        super(TestLoadFromPath, self).setUp()
636
 
        # Change bzrlib.plugin to think no plugins have been loaded yet.
637
 
        self.overrideAttr(bzrlib.plugins, '__path__', [])
 
638
        # Change breezy.plugin to think no plugins have been loaded yet.
 
639
        self.overrideAttr(breezy.plugins, '__path__', [])
638
640
        self.overrideAttr(plugin, '_loaded', False)
639
641
 
640
642
        # Monkey-patch load_from_path to stop it from actually loading anything.
642
644
 
643
645
    def test_set_plugins_path_with_args(self):
644
646
        plugin.set_plugins_path(['a', 'b'])
645
 
        self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
 
647
        self.assertEqual(['a', 'b'], breezy.plugins.__path__)
646
648
 
647
649
    def test_set_plugins_path_defaults(self):
648
650
        plugin.set_plugins_path()
649
651
        self.assertEqual(plugin.get_standard_plugins_path(),
650
 
                         bzrlib.plugins.__path__)
 
652
                         breezy.plugins.__path__)
651
653
 
652
654
    def test_get_standard_plugins_path(self):
653
655
        path = plugin.get_standard_plugins_path()
667
669
                    self.fail('No path to global plugins')
668
670
 
669
671
    def test_get_standard_plugins_path_env(self):
670
 
        self.overrideEnv('BZR_PLUGIN_PATH', 'foo/')
 
672
        self.overrideEnv('BRZ_PLUGIN_PATH', 'foo/')
671
673
        path = plugin.get_standard_plugins_path()
672
674
        for directory in path:
673
675
            self.assertNotContainsRe(directory, r'\\/$')
674
676
 
675
677
    def test_load_plugins(self):
676
678
        plugin.load_plugins(['.'])
677
 
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
 
679
        self.assertEqual(breezy.plugins.__path__, ['.'])
678
680
        # subsequent loads are no-ops
679
681
        plugin.load_plugins(['foo'])
680
 
        self.assertEqual(bzrlib.plugins.__path__, ['.'])
 
682
        self.assertEqual(breezy.plugins.__path__, ['.'])
681
683
 
682
684
    def test_load_plugins_default(self):
683
685
        plugin.load_plugins()
684
686
        path = plugin.get_standard_plugins_path()
685
 
        self.assertEqual(path, bzrlib.plugins.__path__)
 
687
        self.assertEqual(path, breezy.plugins.__path__)
686
688
 
687
689
 
688
690
class TestEnvPluginPath(tests.TestCase):
703
705
 
704
706
    def _set_path(self, *args):
705
707
        path = os.pathsep.join(self._list2paths(*args))
706
 
        self.overrideEnv('BZR_PLUGIN_PATH', path)
 
708
        self.overrideEnv('BRZ_PLUGIN_PATH', path)
707
709
 
708
710
    def check_path(self, expected_dirs, setting_dirs):
709
711
        if setting_dirs:
790
792
        self.addCleanup(self._unregister_plugin, 'test_foo')
791
793
 
792
794
    def test_cannot_import(self):
793
 
        self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
 
795
        self.overrideEnv('BRZ_DISABLE_PLUGINS', 'test_foo')
794
796
        plugin.set_plugins_path(['.'])
795
797
        try:
796
 
            import bzrlib.plugins.test_foo
 
798
            import breezy.plugins.test_foo
797
799
        except ImportError:
798
800
            pass
799
801
        self.assertPluginUnknown('test_foo')
803
805
        plugin.load_plugins(['.'])
804
806
        self.assertPluginKnown('test_foo')
805
807
        self.assertDocstring("This is the doc for test_foo",
806
 
                             bzrlib.plugins.test_foo)
 
808
                             breezy.plugins.test_foo)
807
809
 
808
810
    def test_not_loaded(self):
809
811
        self.warnings = []
812
814
        self.overrideAttr(trace, 'warning', captured_warning)
813
815
        # Reset the flag that protect against double loading
814
816
        self.overrideAttr(plugin, '_loaded', False)
815
 
        self.overrideEnv('BZR_DISABLE_PLUGINS', 'test_foo')
 
817
        self.overrideEnv('BRZ_DISABLE_PLUGINS', 'test_foo')
816
818
        plugin.load_plugins(['.'])
817
819
        self.assertPluginUnknown('test_foo')
818
820
        # Make sure we don't warn about the plugin ImportError since this has
866
868
    def assertTestFooLoadedFrom(self, path):
867
869
        self.assertPluginKnown('test_foo')
868
870
        self.assertDocstring('This is the doc for test_foo',
869
 
                             bzrlib.plugins.test_foo)
870
 
        self.assertEqual(path, bzrlib.plugins.test_foo.dir_source)
 
871
                             breezy.plugins.test_foo)
 
872
        self.assertEqual(path, breezy.plugins.test_foo.dir_source)
871
873
 
872
874
    def test_regular_load(self):
873
875
        plugin.load_plugins(['standard'])
874
876
        self.assertTestFooLoadedFrom('standard/test_foo')
875
877
 
876
878
    def test_import(self):
877
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
879
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
878
880
        plugin.set_plugins_path(['standard'])
879
881
        try:
880
 
            import bzrlib.plugins.test_foo
 
882
            import breezy.plugins.test_foo
881
883
        except ImportError:
882
884
            pass
883
885
        self.assertTestFooLoadedFrom('non-standard-dir')
884
886
 
885
887
    def test_loading(self):
886
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
888
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
887
889
        plugin.load_plugins(['standard'])
888
890
        self.assertTestFooLoadedFrom('non-standard-dir')
889
891
 
890
892
    def test_compiled_loaded(self):
891
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
893
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
892
894
        plugin.load_plugins(['standard'])
893
895
        self.assertTestFooLoadedFrom('non-standard-dir')
894
896
        self.assertIsSameRealPath('non-standard-dir/__init__.py',
895
 
                                  bzrlib.plugins.test_foo.__file__)
 
897
                                  breezy.plugins.test_foo.__file__)
896
898
 
897
899
        # Try importing again now that the source has been compiled
898
900
        self._unregister_plugin('test_foo')
904
906
        else:
905
907
            suffix = 'pyo'
906
908
        self.assertIsSameRealPath('non-standard-dir/__init__.%s' % suffix,
907
 
                                  bzrlib.plugins.test_foo.__file__)
 
909
                                  breezy.plugins.test_foo.__file__)
908
910
 
909
911
    def test_submodule_loading(self):
910
912
        # We create an additional directory under the one for test_foo
911
913
        self.create_plugin_package('test_bar', dir='non-standard-dir/test_bar')
912
914
        self.addCleanup(self._unregister_plugin_submodule,
913
915
                        'test_foo', 'test_bar')
914
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
916
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
915
917
        plugin.set_plugins_path(['standard'])
916
 
        import bzrlib.plugins.test_foo
917
 
        self.assertEqual('bzrlib.plugins.test_foo',
918
 
                         bzrlib.plugins.test_foo.__package__)
919
 
        import bzrlib.plugins.test_foo.test_bar
 
918
        import breezy.plugins.test_foo
 
919
        self.assertEqual('breezy.plugins.test_foo',
 
920
                         breezy.plugins.test_foo.__package__)
 
921
        import breezy.plugins.test_foo.test_bar
920
922
        self.assertIsSameRealPath('non-standard-dir/test_bar/__init__.py',
921
 
                                  bzrlib.plugins.test_foo.test_bar.__file__)
 
923
                                  breezy.plugins.test_foo.test_bar.__file__)
922
924
 
923
925
    def test_relative_submodule_loading(self):
924
926
        self.create_plugin_package('test_foo', dir='another-dir', source='''
928
930
        self.create_plugin_package('test_bar', dir='another-dir/test_bar')
929
931
        self.addCleanup(self._unregister_plugin_submodule,
930
932
                        'test_foo', 'test_bar')
931
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@another-dir')
 
933
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@another-dir')
932
934
        plugin.set_plugins_path(['standard'])
933
 
        import bzrlib.plugins.test_foo
934
 
        self.assertEqual('bzrlib.plugins.test_foo',
935
 
                         bzrlib.plugins.test_foo.__package__)
 
935
        import breezy.plugins.test_foo
 
936
        self.assertEqual('breezy.plugins.test_foo',
 
937
                         breezy.plugins.test_foo.__package__)
936
938
        self.assertIsSameRealPath('another-dir/test_bar/__init__.py',
937
 
                                  bzrlib.plugins.test_foo.test_bar.__file__)
 
939
                                  breezy.plugins.test_foo.test_bar.__file__)
938
940
 
939
941
    def test_loading_from___init__only(self):
940
942
        # We rename the existing __init__.py file to ensure that we don't load
943
945
        random = 'non-standard-dir/setup.py'
944
946
        os.rename(init, random)
945
947
        self.addCleanup(os.rename, random, init)
946
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@non-standard-dir')
 
948
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@non-standard-dir')
947
949
        plugin.load_plugins(['standard'])
948
950
        self.assertPluginUnknown('test_foo')
949
951
 
957
959
''' % ('test_foo', plugin_path)
958
960
        self.create_plugin('test_foo', source=source,
959
961
                           dir=plugin_dir, file_name=plugin_file_name)
960
 
        self.overrideEnv('BZR_PLUGINS_AT', 'test_foo@%s' % plugin_path)
 
962
        self.overrideEnv('BRZ_PLUGINS_AT', 'test_foo@%s' % plugin_path)
961
963
        plugin.load_plugins(['standard'])
962
964
        self.assertTestFooLoadedFrom(plugin_path)
963
965