/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: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

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")
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'):
325
318
 
326
319
    def test_not_found_no_suggestion(self):
327
320
        e = self.assertRaises(errors.BzrCommandError,
328
 
                              commands.get_cmd_object, 'idontexistand')
 
321
            commands.get_cmd_object, 'idontexistand')
329
322
        self.assertEqual('unknown command "idontexistand"', str(e))
330
323
 
331
324
    def test_not_found_with_suggestion(self):
332
325
        e = self.assertRaises(errors.BzrCommandError,
333
 
                              commands.get_cmd_object, 'statue')
 
326
            commands.get_cmd_object, 'statue')
334
327
        self.assertEqual('unknown command "statue". Perhaps you meant "status"',
335
 
                         str(e))
 
328
            str(e))
336
329
 
337
330
 
338
331
class TestGetMissingCommandHook(tests.TestCase):
340
333
    def hook_missing(self):
341
334
        """Hook get_missing_command for testing."""
342
335
        self.hook_calls = []
343
 
 
344
336
        class ACommand(commands.Command):
345
337
            __doc__ = """A sample command."""
346
 
 
347
338
        def get_missing_cmd(cmd_name):
348
339
            self.hook_calls.append(('called', cmd_name))
349
340
            if cmd_name in ('foo', 'info'):
386
377
        # The list_commands() hook fires when all_command_names() is invoked.
387
378
        hook_calls = []
388
379
        commands.install_bzr_command_hooks()
389
 
 
390
380
        def list_my_commands(cmd_names):
391
381
            hook_calls.append('called')
392
382
            cmd_names.update(['foo', 'bar'])
401
391
        self.assertEqual(['called'], hook_calls)
402
392
        self.assertSubset(['foo', 'bar'], cmds)
403
393
 
404
 
 
405
394
class TestPreAndPostCommandHooks(tests.TestCase):
406
395
    class TestError(Exception):
407
396
        __doc__ = """A test exception."""