120
120
class TestSeeAlso(tests.TestCase):
121
121
"""Tests for the see also functional of Command."""
124
def _get_command_with_see_also(see_also):
125
class ACommand(commands.Command):
126
__doc__ = """A sample command."""
130
123
def test_default_subclass_no_see_also(self):
131
command = self._get_command_with_see_also([])
124
class ACommand(commands.Command):
125
"""A sample command."""
132
127
self.assertEqual([], command.get_see_also())
134
129
def test__see_also(self):
135
130
"""When _see_also is defined, it sets the result of get_see_also()."""
136
command = self._get_command_with_see_also(['bar', 'foo'])
131
class ACommand(commands.Command):
132
_see_also = ['bar', 'foo']
137
134
self.assertEqual(['bar', 'foo'], command.get_see_also())
139
136
def test_deduplication(self):
140
137
"""Duplicates in _see_also are stripped out."""
141
command = self._get_command_with_see_also(['foo', 'foo'])
138
class ACommand(commands.Command):
139
_see_also = ['foo', 'foo']
142
141
self.assertEqual(['foo'], command.get_see_also())
144
143
def test_sorted(self):
145
144
"""_see_also is sorted by get_see_also."""
146
command = self._get_command_with_see_also(['foo', 'bar'])
145
class ACommand(commands.Command):
146
_see_also = ['foo', 'bar']
147
148
self.assertEqual(['bar', 'foo'], command.get_see_also())
149
150
def test_additional_terms(self):
150
151
"""Additional terms can be supplied and are deduped and sorted."""
151
command = self._get_command_with_see_also(['foo', 'bar'])
152
class ACommand(commands.Command):
153
_see_also = ['foo', 'bar']
152
155
self.assertEqual(['bar', 'foo', 'gam'],
153
156
command.get_see_also(['gam', 'bar', 'gam']))
208
211
commands.Command.hooks.install_named_hook(
209
212
"extend_command", hook_calls.append, None)
210
213
# create a command, should not fire
211
class cmd_test_extend_command_hook(commands.Command):
212
__doc__ = """A sample command."""
214
class ACommand(commands.Command):
215
"""A sample command."""
213
217
self.assertEqual([], hook_calls)
214
218
# -- as a builtin
215
219
# register the command class, should not fire
217
commands.builtin_command_registry.register(cmd_test_extend_command_hook)
221
builtins.cmd_test_extend_command_hook = ACommand
218
222
self.assertEqual([], hook_calls)
219
223
# and ask for the object, should fire
220
224
cmd = commands.get_cmd_object('test-extend-command-hook')
224
228
self.assertSubset([cmd], hook_calls)
225
229
del hook_calls[:]
227
commands.builtin_command_registry.remove('test-extend-command-hook')
231
del builtins.cmd_test_extend_command_hook
228
232
# -- as a plugin lazy registration
230
234
# register the command class, should not fire
246
250
commands.install_bzr_command_hooks()
248
252
class ACommand(commands.Command):
249
__doc__ = """A sample command."""
253
"""A sample command."""
250
254
def get_cmd(cmd_or_None, cmd_name):
251
255
hook_calls.append(('called', cmd_or_None, cmd_name))
252
256
if cmd_name in ('foo', 'info'):
277
281
"""Hook get_missing_command for testing."""
278
282
self.hook_calls = []
279
283
class ACommand(commands.Command):
280
__doc__ = """A sample command."""
284
"""A sample command."""
281
285
def get_missing_cmd(cmd_name):
282
286
self.hook_calls.append(('called', cmd_name))
283
287
if cmd_name in ('foo', 'info'):