~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Ian Clatworthy
  • Date: 2009-07-02 08:26:00 UTC
  • mto: (4527.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4529.
  • Revision ID: ian.clatworthy@canonical.com-20090702082600-qwb1evvvfa8ctnye
first draft of a 2.0 Upgrade Guide

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    config,
25
25
    errors,
26
26
    option,
27
 
    symbol_versioning,
28
27
    tests,
29
28
    )
30
29
from bzrlib.commands import display_command
112
111
 
113
112
    def test_unicode(self):
114
113
        my_config = self._get_config("[ALIASES]\n"
115
 
            u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
 
114
            u"iam=whoami 'Erik B\u00e5gfors <erik@bagfors.nu>'\n")
116
115
        self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
117
116
                          commands.get_alias("iam", config=my_config))
118
117
 
277
276
 
278
277
class TestGetMissingCommandHook(tests.TestCase):
279
278
 
280
 
    def hook_missing(self):
281
 
        """Hook get_missing_command for testing."""
282
 
        self.hook_calls = []
 
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 = []
283
283
        class ACommand(commands.Command):
284
284
            """A sample command."""
285
285
        def get_missing_cmd(cmd_name):
286
 
            self.hook_calls.append(('called', cmd_name))
 
286
            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()
297
291
        # create a command directly, should not fire
298
 
        self.cmd = self.ACommand()
299
 
        self.assertEqual([], self.hook_calls)
 
292
        cmd = ACommand()
 
293
        self.assertEqual([], hook_calls)
300
294
        # ask by name, should fire and give us our command
301
295
        cmd = commands.get_cmd_object('foo')
302
 
        self.assertEqual([('called', 'foo')], self.hook_calls)
303
 
        self.assertIsInstance(cmd, self.ACommand)
304
 
        del self.hook_calls[:]
 
296
        self.assertEqual([('called', 'foo')], hook_calls)
 
297
        self.assertIsInstance(cmd, ACommand)
 
298
        del hook_calls[:]
305
299
        # ask by a name that is supplied by a builtin - the hook should not
306
300
        # fire and we still get our object.
307
301
        commands.install_bzr_command_hooks()
308
302
        cmd = commands.get_cmd_object('info')
309
303
        self.assertNotEqual(None, cmd)
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)
 
304
        self.assertEqual(0, len(hook_calls))
319
305
 
320
306
 
321
307
class TestListCommandHook(tests.TestCase):
337
323
        cmds = list(commands.all_command_names())
338
324
        self.assertEqual(['called'], hook_calls)
339
325
        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')