79
79
c = self.get_command([option.Option('foo', hidden=False)])
80
80
self.assertContainsRe(c.get_help_text(), '--foo')
82
def test_no_help_init_failure(self):
83
class cmd_foo(commands.Command):
85
self.assertRaises(ValueError, cmd_foo)
83
88
class TestGetAlias(tests.TestCase):
120
125
class TestSeeAlso(tests.TestCase):
121
126
"""Tests for the see also functional of Command."""
129
def _get_command_with_see_also(see_also):
130
class ACommand(commands.Command):
131
__doc__ = """A sample command."""
123
135
def test_default_subclass_no_see_also(self):
124
class ACommand(commands.Command):
125
"""A sample command."""
136
command = self._get_command_with_see_also([])
127
137
self.assertEqual([], command.get_see_also())
129
139
def test__see_also(self):
130
140
"""When _see_also is defined, it sets the result of get_see_also()."""
131
class ACommand(commands.Command):
132
_see_also = ['bar', 'foo']
141
command = self._get_command_with_see_also(['bar', 'foo'])
134
142
self.assertEqual(['bar', 'foo'], command.get_see_also())
136
144
def test_deduplication(self):
137
145
"""Duplicates in _see_also are stripped out."""
138
class ACommand(commands.Command):
139
_see_also = ['foo', 'foo']
146
command = self._get_command_with_see_also(['foo', 'foo'])
141
147
self.assertEqual(['foo'], command.get_see_also())
143
149
def test_sorted(self):
144
150
"""_see_also is sorted by get_see_also."""
145
class ACommand(commands.Command):
146
_see_also = ['foo', 'bar']
151
command = self._get_command_with_see_also(['foo', 'bar'])
148
152
self.assertEqual(['bar', 'foo'], command.get_see_also())
150
154
def test_additional_terms(self):
151
155
"""Additional terms can be supplied and are deduped and sorted."""
152
class ACommand(commands.Command):
153
_see_also = ['foo', 'bar']
156
command = self._get_command_with_see_also(['foo', 'bar'])
155
157
self.assertEqual(['bar', 'foo', 'gam'],
156
158
command.get_see_also(['gam', 'bar', 'gam']))
212
214
"extend_command", hook_calls.append, None)
213
215
# create a command, should not fire
214
216
class cmd_test_extend_command_hook(commands.Command):
215
"""A sample command."""
217
__doc__ = """A sample command."""
216
218
self.assertEqual([], hook_calls)
217
219
# -- as a builtin
218
220
# register the command class, should not fire
249
251
commands.install_bzr_command_hooks()
251
253
class ACommand(commands.Command):
252
"""A sample command."""
254
__doc__ = """A sample command."""
253
255
def get_cmd(cmd_or_None, cmd_name):
254
256
hook_calls.append(('called', cmd_or_None, cmd_name))
255
257
if cmd_name in ('foo', 'info'):
280
282
"""Hook get_missing_command for testing."""
281
283
self.hook_calls = []
282
284
class ACommand(commands.Command):
283
"""A sample command."""
285
__doc__ = """A sample command."""
284
286
def get_missing_cmd(cmd_name):
285
287
self.hook_calls.append(('called', cmd_name))
286
288
if cmd_name in ('foo', 'info'):