/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Parth Malwankar
  • Date: 2010-03-06 01:26:10 UTC
  • mfrom: (5076 +trunk)
  • mto: (5094.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5107.
  • Revision ID: parth.malwankar@gmail.com-20100306012610-a32cmtc938t6vw8p
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    config,
25
25
    errors,
26
26
    option,
 
27
    symbol_versioning,
27
28
    tests,
28
29
    )
29
30
from bzrlib.commands import display_command
276
277
 
277
278
class TestGetMissingCommandHook(tests.TestCase):
278
279
 
279
 
    def test_fires_on_get_cmd_object(self):
280
 
        # The get_missing_command(cmd) hook fires when commands are delivered to the
281
 
        # ui.
282
 
        hook_calls = []
 
280
    def hook_missing(self):
 
281
        """Hook get_missing_command for testing."""
 
282
        self.hook_calls = []
283
283
        class ACommand(commands.Command):
284
284
            """A sample command."""
285
285
        def get_missing_cmd(cmd_name):
286
 
            hook_calls.append(('called', cmd_name))
 
286
            self.hook_calls.append(('called', cmd_name))
287
287
            if cmd_name in ('foo', 'info'):
288
288
                return ACommand()
289
289
        commands.Command.hooks.install_named_hook(
290
290
            "get_missing_command", get_missing_cmd, None)
 
291
        self.ACommand = ACommand
 
292
 
 
293
    def test_fires_on_get_cmd_object(self):
 
294
        # The get_missing_command(cmd) hook fires when commands are delivered to the
 
295
        # ui.
 
296
        self.hook_missing()
291
297
        # create a command directly, should not fire
292
 
        cmd = ACommand()
293
 
        self.assertEqual([], hook_calls)
 
298
        self.cmd = self.ACommand()
 
299
        self.assertEqual([], self.hook_calls)
294
300
        # ask by name, should fire and give us our command
295
301
        cmd = commands.get_cmd_object('foo')
296
 
        self.assertEqual([('called', 'foo')], hook_calls)
297
 
        self.assertIsInstance(cmd, ACommand)
298
 
        del hook_calls[:]
 
302
        self.assertEqual([('called', 'foo')], self.hook_calls)
 
303
        self.assertIsInstance(cmd, self.ACommand)
 
304
        del self.hook_calls[:]
299
305
        # ask by a name that is supplied by a builtin - the hook should not
300
306
        # fire and we still get our object.
301
307
        commands.install_bzr_command_hooks()
302
308
        cmd = commands.get_cmd_object('info')
303
309
        self.assertNotEqual(None, cmd)
304
 
        self.assertEqual(0, len(hook_calls))
 
310
        self.assertEqual(0, len(self.hook_calls))
 
311
 
 
312
    def test_skipped_on_HelpCommandIndex_get_topics(self):
 
313
        # The get_missing_command(cmd_name) hook is not fired when
 
314
        # looking up help topics.
 
315
        self.hook_missing()
 
316
        topic = commands.HelpCommandIndex()
 
317
        topics = topic.get_topics('foo')
 
318
        self.assertEqual([], self.hook_calls)
305
319
 
306
320
 
307
321
class TestListCommandHook(tests.TestCase):
323
337
        cmds = list(commands.all_command_names())
324
338
        self.assertEqual(['called'], hook_calls)
325
339
        self.assertSubset(['foo', 'bar'], cmds)
 
340
 
 
341
class TestDeprecations(tests.TestCase):
 
342
 
 
343
    def test_shlex_split_unicode_deprecation(self):
 
344
        res = self.applyDeprecated(
 
345
                symbol_versioning.deprecated_in((2, 2, 0)),
 
346
                commands.shlex_split_unicode, 'whatever')