35
34
class TestCommands(tests.TestCase):
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)
44
if not cmd_help or cmd_help == base_doc:
45
commands_without_help.append(cmd_name)
46
self.assertLength(0, commands_without_help)
48
36
def test_display_command(self):
49
37
"""EPIPE message is selectively suppressed"""
50
38
def pipe_thrower():
95
83
class TestGetAlias(tests.TestCase):
97
85
def _get_config(self, config_text):
98
my_config = config.GlobalConfig.from_string(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)
101
91
def test_simple(self):
130
120
class TestSeeAlso(tests.TestCase):
131
121
"""Tests for the see also functional of Command."""
134
def _get_command_with_see_also(see_also):
135
class ACommand(commands.Command):
136
__doc__ = """A sample command."""
140
123
def test_default_subclass_no_see_also(self):
141
command = self._get_command_with_see_also([])
124
class ACommand(commands.Command):
125
"""A sample command."""
142
127
self.assertEqual([], command.get_see_also())
144
129
def test__see_also(self):
145
130
"""When _see_also is defined, it sets the result of get_see_also()."""
146
command = self._get_command_with_see_also(['bar', 'foo'])
131
class ACommand(commands.Command):
132
_see_also = ['bar', 'foo']
147
134
self.assertEqual(['bar', 'foo'], command.get_see_also())
149
136
def test_deduplication(self):
150
137
"""Duplicates in _see_also are stripped out."""
151
command = self._get_command_with_see_also(['foo', 'foo'])
138
class ACommand(commands.Command):
139
_see_also = ['foo', 'foo']
152
141
self.assertEqual(['foo'], command.get_see_also())
154
143
def test_sorted(self):
155
144
"""_see_also is sorted by get_see_also."""
156
command = self._get_command_with_see_also(['foo', 'bar'])
145
class ACommand(commands.Command):
146
_see_also = ['foo', 'bar']
157
148
self.assertEqual(['bar', 'foo'], command.get_see_also())
159
150
def test_additional_terms(self):
160
151
"""Additional terms can be supplied and are deduped and sorted."""
161
command = self._get_command_with_see_also(['foo', 'bar'])
152
class ACommand(commands.Command):
153
_see_also = ['foo', 'bar']
162
155
self.assertEqual(['bar', 'foo', 'gam'],
163
156
command.get_see_also(['gam', 'bar', 'gam']))
219
212
"extend_command", hook_calls.append, None)
220
213
# create a command, should not fire
221
214
class cmd_test_extend_command_hook(commands.Command):
222
__doc__ = """A sample command."""
215
"""A sample command."""
223
216
self.assertEqual([], hook_calls)
224
217
# -- as a builtin
225
218
# register the command class, should not fire
256
249
commands.install_bzr_command_hooks()
258
251
class ACommand(commands.Command):
259
__doc__ = """A sample command."""
252
"""A sample command."""
260
253
def get_cmd(cmd_or_None, cmd_name):
261
254
hook_calls.append(('called', cmd_or_None, cmd_name))
262
255
if cmd_name in ('foo', 'info'):
287
280
"""Hook get_missing_command for testing."""
288
281
self.hook_calls = []
289
282
class ACommand(commands.Command):
290
__doc__ = """A sample command."""
283
"""A sample command."""
291
284
def get_missing_cmd(cmd_name):
292
285
self.hook_calls.append(('called', cmd_name))
293
286
if cmd_name in ('foo', 'info'):
344
337
self.assertEqual(['called'], hook_calls)
345
338
self.assertSubset(['foo', 'bar'], cmds)
348
340
class TestDeprecations(tests.TestCase):
350
342
def test_shlex_split_unicode_deprecation(self):