~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Aaron Bentley
  • Date: 2008-10-26 10:00:24 UTC
  • mfrom: (0.12.70 shelf-manager)
  • mto: This revision was merged to the branch mainline in revision 3823.
  • Revision ID: aaron@aaronbentley.com-20081026100024-08whjq5p54yah68r
Merge shelf-manager into shelf-ui

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import errno
 
19
import sys
19
20
 
20
21
from bzrlib import (
21
22
    commands,
134
135
        self.assertEqual(['bar', 'foo', 'gam'],
135
136
            command.get_see_also(['gam', 'bar', 'gam']))
136
137
 
 
138
 
 
139
class TestRegisterLazy(tests.TestCase):
 
140
 
 
141
    def setUp(self):
 
142
        import bzrlib.tests.fake_command
 
143
        del sys.modules['bzrlib.tests.fake_command']
 
144
        global lazy_command_imported
 
145
        lazy_command_imported = False
 
146
 
 
147
    @staticmethod
 
148
    def remove_fake():
 
149
        commands.plugin_cmds.remove('fake')
 
150
 
 
151
    def assertIsFakeCommand(self, cmd_obj):
 
152
        from bzrlib.tests.fake_command import cmd_fake
 
153
        self.assertIsInstance(cmd_obj, cmd_fake)
 
154
 
 
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)
 
164
 
 
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)
 
171
 
 
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)