/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

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
 
52
53
        @display_command
53
54
        def non_thrower():
54
55
            pipe_thrower()
55
56
        non_thrower()
 
57
 
56
58
        @display_command
57
59
        def other_thrower():
58
60
            raise IOError(errno.ESPIPE, "Bogus pipe error")
128
130
 
129
131
    def test_simple(self):
130
132
        my_config = self._get_config("[ALIASES]\n"
131
 
            "diff=diff -r -2..-1\n")
 
133
                                     "diff=diff -r -2..-1\n")
132
134
        self.assertEqual([u'diff', u'-r', u'-2..-1'],
133
 
            commands.get_alias("diff", config=my_config))
 
135
                         commands.get_alias("diff", config=my_config))
134
136
 
135
137
    def test_single_quotes(self):
136
138
        my_config = self._get_config("[ALIASES]\n"
137
 
            "diff=diff -r -2..-1 --diff-options "
138
 
            "'--strip-trailing-cr -wp'\n")
 
139
                                     "diff=diff -r -2..-1 --diff-options "
 
140
                                     "'--strip-trailing-cr -wp'\n")
139
141
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
140
142
                          u'--strip-trailing-cr -wp'],
141
 
                          commands.get_alias("diff", config=my_config))
 
143
                         commands.get_alias("diff", config=my_config))
142
144
 
143
145
    def test_double_quotes(self):
144
146
        my_config = self._get_config("[ALIASES]\n"
145
 
            "diff=diff -r -2..-1 --diff-options "
146
 
            "\"--strip-trailing-cr -wp\"\n")
 
147
                                     "diff=diff -r -2..-1 --diff-options "
 
148
                                     "\"--strip-trailing-cr -wp\"\n")
147
149
        self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
148
150
                          u'--strip-trailing-cr -wp'],
149
 
                          commands.get_alias("diff", config=my_config))
 
151
                         commands.get_alias("diff", config=my_config))
150
152
 
151
153
    def test_unicode(self):
152
154
        my_config = self._get_config("[ALIASES]\n"
153
 
            u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
 
155
                                     u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
154
156
        self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
155
 
                          commands.get_alias("iam", config=my_config))
 
157
                         commands.get_alias("iam", config=my_config))
156
158
 
157
159
 
158
160
class TestSeeAlso(tests.TestCase):
188
190
        """Additional terms can be supplied and are deduped and sorted."""
189
191
        command = self._get_command_with_see_also(['foo', 'bar'])
190
192
        self.assertEqual(['bar', 'foo', 'gam'],
191
 
            command.get_see_also(['gam', 'bar', 'gam']))
 
193
                         command.get_see_also(['gam', 'bar', 'gam']))
192
194
 
193
195
 
194
196
class TestRegisterLazy(tests.TestCase):
246
248
        commands.Command.hooks.install_named_hook(
247
249
            "extend_command", hook_calls.append, None)
248
250
        # create a command, should not fire
 
251
 
249
252
        class cmd_test_extend_command_hook(commands.Command):
250
253
            __doc__ = """A sample command."""
251
254
        self.assertEqual([], hook_calls)
252
255
        # -- as a builtin
253
256
        # register the command class, should not fire
254
257
        try:
255
 
            commands.builtin_command_registry.register(cmd_test_extend_command_hook)
 
258
            commands.builtin_command_registry.register(
 
259
                cmd_test_extend_command_hook)
256
260
            self.assertEqual([], hook_calls)
257
261
            # and ask for the object, should fire
258
262
            cmd = commands.get_cmd_object('test-extend-command-hook')
262
266
            self.assertSubset([cmd], hook_calls)
263
267
            del hook_calls[:]
264
268
        finally:
265
 
            commands.builtin_command_registry.remove('test-extend-command-hook')
 
269
            commands.builtin_command_registry.remove(
 
270
                'test-extend-command-hook')
266
271
        # -- as a plugin lazy registration
267
272
        try:
268
273
            # register the command class, should not fire
283
288
        # ui.
284
289
        commands.install_bzr_command_hooks()
285
290
        hook_calls = []
 
291
 
286
292
        class ACommand(commands.Command):
287
293
            __doc__ = """A sample command."""
 
294
 
288
295
        def get_cmd(cmd_or_None, cmd_name):
289
296
            hook_calls.append(('called', cmd_or_None, cmd_name))
290
297
            if cmd_name in ('foo', 'info'):
318
325
 
319
326
    def test_not_found_no_suggestion(self):
320
327
        e = self.assertRaises(errors.BzrCommandError,
321
 
            commands.get_cmd_object, 'idontexistand')
 
328
                              commands.get_cmd_object, 'idontexistand')
322
329
        self.assertEqual('unknown command "idontexistand"', str(e))
323
330
 
324
331
    def test_not_found_with_suggestion(self):
325
332
        e = self.assertRaises(errors.BzrCommandError,
326
 
            commands.get_cmd_object, 'statue')
 
333
                              commands.get_cmd_object, 'statue')
327
334
        self.assertEqual('unknown command "statue". Perhaps you meant "status"',
328
 
            str(e))
 
335
                         str(e))
329
336
 
330
337
 
331
338
class TestGetMissingCommandHook(tests.TestCase):
333
340
    def hook_missing(self):
334
341
        """Hook get_missing_command for testing."""
335
342
        self.hook_calls = []
 
343
 
336
344
        class ACommand(commands.Command):
337
345
            __doc__ = """A sample command."""
 
346
 
338
347
        def get_missing_cmd(cmd_name):
339
348
            self.hook_calls.append(('called', cmd_name))
340
349
            if cmd_name in ('foo', 'info'):
377
386
        # The list_commands() hook fires when all_command_names() is invoked.
378
387
        hook_calls = []
379
388
        commands.install_bzr_command_hooks()
 
389
 
380
390
        def list_my_commands(cmd_names):
381
391
            hook_calls.append('called')
382
392
            cmd_names.update(['foo', 'bar'])
391
401
        self.assertEqual(['called'], hook_calls)
392
402
        self.assertSubset(['foo', 'bar'], cmds)
393
403
 
 
404
 
394
405
class TestPreAndPostCommandHooks(tests.TestCase):
395
406
    class TestError(Exception):
396
407
        __doc__ = """A test exception."""