~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import errno
 
19
import inspect
19
20
import sys
20
21
 
21
22
from bzrlib import (
33
34
 
34
35
class TestCommands(tests.TestCase):
35
36
 
 
37
    def test_all_commands_have_help(self):
 
38
        commands._register_builtin_commands()
 
39
        commands_without_help = set()
 
40
        base_doc = inspect.getdoc(commands.Command)
 
41
        for cmd_name in commands.all_command_names():
 
42
            cmd = commands.get_cmd_object(cmd_name)
 
43
            cmd_help = cmd.help()
 
44
            if not cmd_help or cmd_help == base_doc:
 
45
                commands_without_help.append(cmd_name)
 
46
        self.assertLength(0, commands_without_help)
 
47
 
36
48
    def test_display_command(self):
37
49
        """EPIPE message is selectively suppressed"""
38
50
        def pipe_thrower():
83
95
class TestGetAlias(tests.TestCase):
84
96
 
85
97
    def _get_config(self, config_text):
86
 
        my_config = config.GlobalConfig()
87
 
        config_file = StringIO(config_text.encode('utf-8'))
88
 
        my_config._parser = my_config._get_parser(file=config_file)
 
98
        my_config = config.GlobalConfig.from_string(config_text)
89
99
        return my_config
90
100
 
91
101
    def test_simple(self):
334
344
        self.assertEqual(['called'], hook_calls)
335
345
        self.assertSubset(['foo', 'bar'], cmds)
336
346
 
 
347
 
337
348
class TestDeprecations(tests.TestCase):
338
349
 
339
350
    def test_shlex_split_unicode_deprecation(self):