134
135
self.assertEqual(['bar', 'foo', 'gam'],
135
136
command.get_see_also(['gam', 'bar', 'gam']))
139
class TestRegisterLazy(tests.TestCase):
142
import bzrlib.tests.fake_command
143
del sys.modules['bzrlib.tests.fake_command']
144
global lazy_command_imported
145
lazy_command_imported = False
149
commands.plugin_cmds.remove('fake')
151
def assertIsFakeCommand(self, cmd_obj):
152
from bzrlib.tests.fake_command import cmd_fake
153
self.assertIsInstance(cmd_obj, cmd_fake)
155
def test_register_lazy(self):
156
"""Ensure lazy registration works"""
157
commands.plugin_cmds.register_lazy('cmd_fake', [],
158
'bzrlib.tests.fake_command')
159
self.addCleanup(self.remove_fake)
160
self.assertFalse(lazy_command_imported)
161
fake_instance = commands.get_cmd_object('fake')
162
self.assertTrue(lazy_command_imported)
163
self.assertIsFakeCommand(fake_instance)
165
def test_get_unrelated_does_not_import(self):
166
commands.plugin_cmds.register_lazy('cmd_fake', [],
167
'bzrlib.tests.fake_command')
168
self.addCleanup(self.remove_fake)
169
commands.get_cmd_object('status')
170
self.assertFalse(lazy_command_imported)
172
def test_aliases(self):
173
commands.plugin_cmds.register_lazy('cmd_fake', ['fake_alias'],
174
'bzrlib.tests.fake_command')
175
self.addCleanup(self.remove_fake)
176
fake_instance = commands.get_cmd_object('fake_alias')
177
self.assertIsFakeCommand(fake_instance)