/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 breezy/tests/test_plugins.py

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 00:52:27 UTC
  • mfrom: (6939 work)
  • mto: This revision was merged to the branch mainline in revision 7274.
  • Revision ID: jelmer@jelmer.uk-20180402005227-pecflp1mvdjrjqd6
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for plugins"""
18
18
 
19
 
import imp
 
19
try:
 
20
    from importlib.util import module_from_spec
 
21
except ImportError:  # python < 3
 
22
    from imp import new_module as module_from_spec
20
23
import importlib
21
24
import logging
22
25
import os
49
52
        super(BaseTestPlugins, self).setUp()
50
53
        self.module_name = "breezy.testingplugins"
51
54
        self.module_prefix = self.module_name + "."
52
 
        self.module = imp.new_module(self.module_name)
 
55
        self.module = module_from_spec(self.module_name)
53
56
 
54
57
        self.overrideAttr(plugin, "_MODULE_PREFIX", self.module_prefix)
55
58
        self.overrideAttr(breezy, "testingplugins", self.module)
315
318
        self.assertContainsRe(log,
316
319
            r"Unable to load 'brz-bad plugin-name\.' in '\.' as a plugin "
317
320
            "because the file path isn't a valid module name; try renaming "
318
 
            "it to 'bad_plugin_name_'\.")
 
321
            "it to 'bad_plugin_name_'\\.")
319
322
 
320
323
 
321
324
class TestPlugins(BaseTestPlugins):
328
331
        with open('plugin.py', 'w') as f: f.write(source + '\n')
329
332
        self.load_with_paths(['.'])
330
333
 
 
334
    def test_plugin_loaded(self):
 
335
        self.assertPluginUnknown('plugin')
 
336
        self.assertIs(None, breezy.plugin.get_loaded_plugin('plugin'))
 
337
        self.setup_plugin()
 
338
        p = breezy.plugin.get_loaded_plugin('plugin')
 
339
        self.assertIsInstance(p, breezy.plugin.PlugIn)
 
340
        self.assertIs(p.module, sys.modules[self.module_prefix + 'plugin'])
 
341
 
 
342
    def test_plugin_loaded_disabled(self):
 
343
        self.assertPluginUnknown('plugin')
 
344
        self.overrideEnv('BRZ_DISABLE_PLUGINS', 'plugin')
 
345
        self.setup_plugin()
 
346
        self.assertIs(None, breezy.plugin.get_loaded_plugin('plugin'))
 
347
 
331
348
    def test_plugin_appears_in_plugins(self):
332
349
        self.setup_plugin()
333
350
        self.assertPluginKnown('plugin')
519
536
        help = self.run_bzr('help myplug')[0]
520
537
        self.assertContainsRe(help, 'plugin "myplug"')
521
538
        help = self.split_help_commands()['myplug']
522
 
        self.assertContainsRe(help, '\[myplug\]')
 
539
        self.assertContainsRe(help, '\\[myplug\\]')
523
540
 
524
541
 
525
542
class TestHelpIndex(tests.TestCase):