/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: Breezy landing bot
  • Author(s): Martin
  • Date: 2018-07-01 11:02:42 UTC
  • mfrom: (7015.1.3 test_plugins_repass)
  • Revision ID: breezy.the.bot@gmail.com-20180701110242-snd4rg6tj8qmebhe
Make plugins tests pass on Python 3 again

Merged from https://code.launchpad.net/~gz/brz/test_plugins_repass/+merge/348797

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd, 2017 Breezy developers
 
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
2
# Copyright (C) 2017-2018 Breezy developers
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
16
17
 
17
18
"""Tests for plugins"""
18
19
 
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
23
20
import importlib
24
21
import logging
25
22
import os
26
23
import sys
 
24
import types
27
25
 
28
26
import breezy
29
27
from .. import (
52
50
        super(BaseTestPlugins, self).setUp()
53
51
        self.module_name = "breezy.testingplugins"
54
52
        self.module_prefix = self.module_name + "."
55
 
        self.module = module_from_spec(self.module_name)
 
53
        self.module = types.ModuleType(self.module_name)
56
54
 
57
55
        self.overrideAttr(plugin, "_MODULE_PREFIX", self.module_prefix)
58
56
        self.overrideAttr(breezy, "testingplugins", self.module)
482
480
        self.assertEqual("1.2.3.2", plugin.__version__)
483
481
 
484
482
 
485
 
# GZ 2017-06-02: Move this suite to blackbox, as it's what it actually is.
486
 
class TestPluginHelp(BaseTestPlugins):
487
 
 
488
 
    def split_help_commands(self):
489
 
        help = {}
490
 
        current = None
491
 
        out, err = self.run_bzr('--no-plugins help commands')
492
 
        for line in out.splitlines():
493
 
            if not line.startswith(' '):
494
 
                current = line.split()[0]
495
 
            help[current] = help.get(current, '') + line
496
 
 
497
 
        return help
498
 
 
499
 
    def test_plugin_help_builtins_unaffected(self):
500
 
        # Check we don't get false positives
501
 
        help_commands = self.split_help_commands()
502
 
        for cmd_name in breezy.commands.builtin_command_names():
503
 
            if cmd_name in breezy.commands.plugin_command_names():
504
 
                continue
505
 
            try:
506
 
                help = breezy.commands.get_cmd_object(cmd_name).get_help_text()
507
 
            except NotImplementedError:
508
 
                # some commands have no help
509
 
                pass
510
 
            else:
511
 
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
512
 
 
513
 
            if cmd_name in help_commands:
514
 
                # some commands are hidden
515
 
                help = help_commands[cmd_name]
516
 
                self.assertNotContainsRe(help, 'plugin "[^"]*"')
517
 
 
518
 
    def test_plugin_help_shows_plugin(self):
519
 
        # Create a test plugin
520
 
        os.mkdir('plugin_test')
521
 
        source = (
522
 
            "from breezy import commands\n"
523
 
            "class cmd_myplug(commands.Command):\n"
524
 
            "    __doc__ = '''Just a simple test plugin.'''\n"
525
 
            "    aliases = ['mplg']\n"
526
 
            "    def run(self):\n"
527
 
            "        print ('Hello from my plugin')\n"
528
 
        )
529
 
        self.create_plugin('myplug', source, 'plugin_test')
530
 
 
531
 
        # Check its help
532
 
        self.load_with_paths(['plugin_test'])
533
 
        myplug = self.plugins['myplug'].module
534
 
        breezy.commands.register_command(myplug.cmd_myplug)
535
 
        self.addCleanup(breezy.commands.plugin_cmds.remove, 'myplug')
536
 
        help = self.run_bzr('help myplug')[0]
537
 
        self.assertContainsRe(help, 'plugin "myplug"')
538
 
        help = self.split_help_commands()['myplug']
539
 
        self.assertContainsRe(help, '\\[myplug\\]')
540
 
 
541
 
 
542
483
class TestHelpIndex(tests.TestCase):
543
484
    """Tests for the PluginsHelpIndex class."""
544
485