/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 breezy/tests/test_commands.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        def pipe_thrower():
50
50
            raise IOError(errno.EPIPE, "Bogus pipe error")
51
51
        self.assertRaises(IOError, pipe_thrower)
52
 
 
53
52
        @display_command
54
53
        def non_thrower():
55
54
            pipe_thrower()
56
55
        non_thrower()
57
 
 
58
56
        @display_command
59
57
        def other_thrower():
60
58
            raise IOError(errno.ESPIPE, "Bogus pipe error")
63
61
    def test_unicode_command(self):
64
62
        # This error is thrown when we can't find the command in the
65
63
        # list of available commands
66
 
        self.assertRaises(errors.CommandError,
 
64
        self.assertRaises(errors.BzrCommandError,
67
65
                          commands.run_bzr, [u'cmd\xb5'])
68
66
 
69
67
    def test_unicode_option(self):
72
70
        import optparse
73
71
        if optparse.__version__ == "1.5.3":
74
72
            raise TestSkipped("optparse 1.5.3 can't handle unicode options")
75
 
        self.assertRaises(errors.CommandError,
 
73
        self.assertRaises(errors.BzrCommandError,
76
74
                          commands.run_bzr, ['log', u'--option\xb5'])
77
75
 
78
76
    @staticmethod
130
128
 
131
129
    def test_simple(self):
132
130
        my_config = self._get_config("[ALIASES]\n"
133
 
                                     "diff=diff -r -2..-1\n")
 
131
            "diff=diff -r -2..-1\n")
134
132
        self.assertEqual([u'diff', u'-r', u'-2..-1'],
135
 
                         commands.get_alias("diff", config=my_config))
 
133
            commands.get_alias("diff", config=my_config))
136
134
 
137
135
    def test_single_quotes(self):
138
136
        my_config = self._get_config("[ALIASES]\n"
139
 
                                     "diff=diff -r -2..-1 --diff-options "
140
 
                                     "'--strip-trailing-cr -wp'\n")
 
137
            "diff=diff -r -2..-1 --diff-options "
 
138
            "'--strip-trailing-cr -wp'\n")
141
139
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
142
140
                          u'--strip-trailing-cr -wp'],
143
 
                         commands.get_alias("diff", config=my_config))
 
141
                          commands.get_alias("diff", config=my_config))
144
142
 
145
143
    def test_double_quotes(self):
146
144
        my_config = self._get_config("[ALIASES]\n"
147
 
                                     "diff=diff -r -2..-1 --diff-options "
148
 
                                     "\"--strip-trailing-cr -wp\"\n")
 
145
            "diff=diff -r -2..-1 --diff-options "
 
146
            "\"--strip-trailing-cr -wp\"\n")
149
147
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
150
148
                          u'--strip-trailing-cr -wp'],
151
 
                         commands.get_alias("diff", config=my_config))
 
149
                          commands.get_alias("diff", config=my_config))
152
150
 
153
151
    def test_unicode(self):
154
152
        my_config = self._get_config("[ALIASES]\n"
155
 
                                     u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
 
153
            u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
156
154
        self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
157
 
                         commands.get_alias("iam", config=my_config))
 
155
                          commands.get_alias("iam", config=my_config))
158
156
 
159
157
 
160
158
class TestSeeAlso(tests.TestCase):
190
188
        """Additional terms can be supplied and are deduped and sorted."""
191
189
        command = self._get_command_with_see_also(['foo', 'bar'])
192
190
        self.assertEqual(['bar', 'foo', 'gam'],
193
 
                         command.get_see_also(['gam', 'bar', 'gam']))
 
191
            command.get_see_also(['gam', 'bar', 'gam']))
194
192
 
195
193
 
196
194
class TestRegisterLazy(tests.TestCase):
248
246
        commands.Command.hooks.install_named_hook(
249
247
            "extend_command", hook_calls.append, None)
250
248
        # create a command, should not fire
251
 
 
252
249
        class cmd_test_extend_command_hook(commands.Command):
253
250
            __doc__ = """A sample command."""
254
251
        self.assertEqual([], hook_calls)
255
252
        # -- as a builtin
256
253
        # register the command class, should not fire
257
254
        try:
258
 
            commands.builtin_command_registry.register(
259
 
                cmd_test_extend_command_hook)
 
255
            commands.builtin_command_registry.register(cmd_test_extend_command_hook)
260
256
            self.assertEqual([], hook_calls)
261
257
            # and ask for the object, should fire
262
258
            cmd = commands.get_cmd_object('test-extend-command-hook')
266
262
            self.assertSubset([cmd], hook_calls)
267
263
            del hook_calls[:]
268
264
        finally:
269
 
            commands.builtin_command_registry.remove(
270
 
                'test-extend-command-hook')
 
265
            commands.builtin_command_registry.remove('test-extend-command-hook')
271
266
        # -- as a plugin lazy registration
272
267
        try:
273
268
            # register the command class, should not fire
288
283
        # ui.
289
284
        commands.install_bzr_command_hooks()
290
285
        hook_calls = []
291
 
 
292
286
        class ACommand(commands.Command):
293
287
            __doc__ = """A sample command."""
294
 
 
295
288
        def get_cmd(cmd_or_None, cmd_name):
296
289
            hook_calls.append(('called', cmd_or_None, cmd_name))
297
290
            if cmd_name in ('foo', 'info'):
316
309
        self.assertIsInstance(hook_calls[0][1], builtins.cmd_info)
317
310
 
318
311
 
319
 
class TestCommandNotFound(tests.TestCase):
320
 
 
321
 
    def setUp(self):
322
 
        super(TestCommandNotFound, self).setUp()
323
 
        commands._register_builtin_commands()
324
 
        commands.install_bzr_command_hooks()
325
 
 
326
 
    def test_not_found_no_suggestion(self):
327
 
        e = self.assertRaises(errors.CommandError,
328
 
                              commands.get_cmd_object, 'idontexistand')
329
 
        self.assertEqual('unknown command "idontexistand"', str(e))
330
 
 
331
 
    def test_not_found_with_suggestion(self):
332
 
        e = self.assertRaises(errors.CommandError,
333
 
                              commands.get_cmd_object, 'statue')
334
 
        self.assertEqual('unknown command "statue". Perhaps you meant "status"',
335
 
                         str(e))
336
 
 
337
 
 
338
312
class TestGetMissingCommandHook(tests.TestCase):
339
313
 
340
314
    def hook_missing(self):
341
315
        """Hook get_missing_command for testing."""
342
316
        self.hook_calls = []
343
 
 
344
317
        class ACommand(commands.Command):
345
318
            __doc__ = """A sample command."""
346
 
 
347
319
        def get_missing_cmd(cmd_name):
348
320
            self.hook_calls.append(('called', cmd_name))
349
321
            if cmd_name in ('foo', 'info'):
386
358
        # The list_commands() hook fires when all_command_names() is invoked.
387
359
        hook_calls = []
388
360
        commands.install_bzr_command_hooks()
389
 
 
390
361
        def list_my_commands(cmd_names):
391
362
            hook_calls.append('called')
392
363
            cmd_names.update(['foo', 'bar'])
401
372
        self.assertEqual(['called'], hook_calls)
402
373
        self.assertSubset(['foo', 'bar'], cmds)
403
374
 
404
 
 
405
375
class TestPreAndPostCommandHooks(tests.TestCase):
406
376
    class TestError(Exception):
407
377
        __doc__ = """A test exception."""
452
422
        self.assertEqual(['run', 'post'], hook_calls)
453
423
 
454
424
    def test_pre_command_error(self):
455
 
        """Ensure an CommandError in pre_command aborts the command"""
 
425
        """Ensure an BzrCommandError in pre_command aborts the command"""
456
426
 
457
427
        hook_calls = []
458
428
 
459
429
        def pre_command(cmd):
460
430
            hook_calls.append('pre')
461
 
            # verify that all subclasses of CommandError caught too
462
 
            raise commands.BzrOptionError()
 
431
            # verify that all subclasses of BzrCommandError caught too
 
432
            raise errors.BzrOptionError()
463
433
 
464
434
        def post_command(cmd, e):
465
435
            self.fail('post_command should not be called')
475
445
            "post_command", post_command, None)
476
446
 
477
447
        self.assertEqual([], hook_calls)
478
 
        self.assertRaises(errors.CommandError,
 
448
        self.assertRaises(errors.BzrCommandError,
479
449
                          commands.run_bzr, [u'rocks'])
480
450
        self.assertEqual(['pre'], hook_calls)
481
451
 
482
 
 
483
 
class GuessCommandTests(tests.TestCase):
484
 
 
485
 
    def setUp(self):
486
 
        super(GuessCommandTests, self).setUp()
487
 
        commands._register_builtin_commands()
488
 
        commands.install_bzr_command_hooks()
489
 
 
490
 
    def test_guess_override(self):
491
 
        self.assertEqual('ci', commands.guess_command('ic'))
492
 
 
493
 
    def test_guess(self):
494
 
        commands.get_cmd_object('status')
495
 
        self.assertEqual('status', commands.guess_command('statue'))
496
 
 
497
 
    def test_none(self):
498
 
        self.assertIs(None, commands.guess_command('nothingisevenclose'))