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."""
123
130
def test_default_subclass_no_see_also(self):
124
class ACommand(commands.Command):
125
"""A sample command."""
131
command = self._get_command_with_see_also([])
127
132
self.assertEqual([], command.get_see_also())
129
134
def test__see_also(self):
130
135
"""When _see_also is defined, it sets the result of get_see_also()."""
131
class ACommand(commands.Command):
132
_see_also = ['bar', 'foo']
136
command = self._get_command_with_see_also(['bar', 'foo'])
134
137
self.assertEqual(['bar', 'foo'], command.get_see_also())
136
139
def test_deduplication(self):
137
140
"""Duplicates in _see_also are stripped out."""
138
class ACommand(commands.Command):
139
_see_also = ['foo', 'foo']
141
command = self._get_command_with_see_also(['foo', 'foo'])
141
142
self.assertEqual(['foo'], command.get_see_also())
143
144
def test_sorted(self):
144
145
"""_see_also is sorted by get_see_also."""
145
class ACommand(commands.Command):
146
_see_also = ['foo', 'bar']
146
command = self._get_command_with_see_also(['foo', 'bar'])
148
147
self.assertEqual(['bar', 'foo'], command.get_see_also())
150
149
def test_additional_terms(self):
151
150
"""Additional terms can be supplied and are deduped and sorted."""
152
class ACommand(commands.Command):
153
_see_also = ['foo', 'bar']
151
command = self._get_command_with_see_also(['foo', 'bar'])
155
152
self.assertEqual(['bar', 'foo', 'gam'],
156
153
command.get_see_also(['gam', 'bar', 'gam']))
212
209
"extend_command", hook_calls.append, None)
213
210
# create a command, should not fire
214
211
class cmd_test_extend_command_hook(commands.Command):
215
"""A sample command."""
212
__doc__ = """A sample command."""
216
213
self.assertEqual([], hook_calls)
217
214
# -- as a builtin
218
215
# register the command class, should not fire
249
246
commands.install_bzr_command_hooks()
251
248
class ACommand(commands.Command):
252
"""A sample command."""
249
__doc__ = """A sample command."""
253
250
def get_cmd(cmd_or_None, cmd_name):
254
251
hook_calls.append(('called', cmd_or_None, cmd_name))
255
252
if cmd_name in ('foo', 'info'):
280
277
"""Hook get_missing_command for testing."""
281
278
self.hook_calls = []
282
279
class ACommand(commands.Command):
283
"""A sample command."""
280
__doc__ = """A sample command."""
284
281
def get_missing_cmd(cmd_name):
285
282
self.hook_calls.append(('called', cmd_name))
286
283
if cmd_name in ('foo', 'info'):