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']))
209
212
"extend_command", hook_calls.append, None)
210
213
# create a command, should not fire
211
214
class cmd_test_extend_command_hook(commands.Command):
212
__doc__ = """A sample command."""
215
"""A sample command."""
213
216
self.assertEqual([], hook_calls)
214
217
# -- as a builtin
215
218
# register the command class, should not fire
246
249
commands.install_bzr_command_hooks()
248
251
class ACommand(commands.Command):
249
__doc__ = """A sample command."""
252
"""A sample command."""
250
253
def get_cmd(cmd_or_None, cmd_name):
251
254
hook_calls.append(('called', cmd_or_None, cmd_name))
252
255
if cmd_name in ('foo', 'info'):
277
280
"""Hook get_missing_command for testing."""
278
281
self.hook_calls = []
279
282
class ACommand(commands.Command):
280
__doc__ = """A sample command."""
283
"""A sample command."""
281
284
def get_missing_cmd(cmd_name):
282
285
self.hook_calls.append(('called', cmd_name))
283
286
if cmd_name in ('foo', 'info'):