/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
import inspect
19
19
import sys
20
20
 
21
 
from .. import (
 
21
from bzrlib import (
22
22
    builtins,
23
23
    commands,
24
24
    config,
27
27
    tests,
28
28
    trace,
29
29
    )
30
 
from ..commands import display_command
31
 
from . import TestSkipped
 
30
from bzrlib.commands import display_command
 
31
from bzrlib.tests import TestSkipped
32
32
 
33
33
 
34
34
class TestCommands(tests.TestCase):
98
98
            # We override the run() command method so we can observe the
99
99
            # overrides from inside.
100
100
            c = config.GlobalStack()
101
 
            self.assertEqual('12', c.get('xx'))
102
 
            self.assertEqual('foo', c.get('yy'))
 
101
            self.assertEquals('12', c.get('xx'))
 
102
            self.assertEquals('foo', c.get('yy'))
103
103
        self.overrideAttr(builtins.cmd_rocks, 'run', run)
104
104
        self.run_bzr(['rocks', '-Oxx=12', '-Oyy=foo'])
105
105
        c = config.GlobalStack()
106
106
        # Ensure that we don't leak outside of the command
107
 
        self.assertEqual(None, c.get('xx'))
108
 
        self.assertEqual(None, c.get('yy'))
 
107
        self.assertEquals(None, c.get('xx'))
 
108
        self.assertEquals(None, c.get('yy'))
109
109
 
110
110
 
111
111
class TestInvokedAs(tests.TestCase):
117
117
        # get one from the real get_cmd_object.
118
118
        c = commands.get_cmd_object('ci')
119
119
        self.assertIsInstance(c, builtins.cmd_commit)
120
 
        self.assertEqual(c.invoked_as, 'ci')
 
120
        self.assertEquals(c.invoked_as, 'ci')
121
121
 
122
122
 
123
123
class TestGetAlias(tests.TestCase):
195
195
 
196
196
    def setUp(self):
197
197
        super(TestRegisterLazy, self).setUp()
198
 
        import breezy.tests.fake_command
199
 
        del sys.modules['breezy.tests.fake_command']
 
198
        import bzrlib.tests.fake_command
 
199
        del sys.modules['bzrlib.tests.fake_command']
200
200
        global lazy_command_imported
201
201
        lazy_command_imported = False
202
202
        commands.install_bzr_command_hooks()
206
206
        commands.plugin_cmds.remove('fake')
207
207
 
208
208
    def assertIsFakeCommand(self, cmd_obj):
209
 
        from breezy.tests.fake_command import cmd_fake
 
209
        from bzrlib.tests.fake_command import cmd_fake
210
210
        self.assertIsInstance(cmd_obj, cmd_fake)
211
211
 
212
212
    def test_register_lazy(self):
213
213
        """Ensure lazy registration works"""
214
214
        commands.plugin_cmds.register_lazy('cmd_fake', [],
215
 
                                           'breezy.tests.fake_command')
 
215
                                           'bzrlib.tests.fake_command')
216
216
        self.addCleanup(self.remove_fake)
217
217
        self.assertFalse(lazy_command_imported)
218
218
        fake_instance = commands.get_cmd_object('fake')
221
221
 
222
222
    def test_get_unrelated_does_not_import(self):
223
223
        commands.plugin_cmds.register_lazy('cmd_fake', [],
224
 
                                           'breezy.tests.fake_command')
 
224
                                           'bzrlib.tests.fake_command')
225
225
        self.addCleanup(self.remove_fake)
226
226
        commands.get_cmd_object('status')
227
227
        self.assertFalse(lazy_command_imported)
228
228
 
229
229
    def test_aliases(self):
230
230
        commands.plugin_cmds.register_lazy('cmd_fake', ['fake_alias'],
231
 
                                           'breezy.tests.fake_command')
 
231
                                           'bzrlib.tests.fake_command')
232
232
        self.addCleanup(self.remove_fake)
233
233
        fake_instance = commands.get_cmd_object('fake_alias')
234
234
        self.assertIsFakeCommand(fake_instance)
267
267
        try:
268
268
            # register the command class, should not fire
269
269
            commands.plugin_cmds.register_lazy('cmd_fake', [],
270
 
                                               'breezy.tests.fake_command')
 
270
                                               'bzrlib.tests.fake_command')
271
271
            self.assertEqual([], hook_calls)
272
272
            # and ask for the object, should fire
273
273
            cmd = commands.get_cmd_object('fake')
309
309
        self.assertIsInstance(hook_calls[0][1], builtins.cmd_info)
310
310
 
311
311
 
312
 
class TestCommandNotFound(tests.TestCase):
313
 
 
314
 
    def setUp(self):
315
 
        super(TestCommandNotFound, self).setUp()
316
 
        commands._register_builtin_commands()
317
 
        commands.install_bzr_command_hooks()
318
 
 
319
 
    def test_not_found_no_suggestion(self):
320
 
        e = self.assertRaises(errors.BzrCommandError,
321
 
            commands.get_cmd_object, 'idontexistand')
322
 
        self.assertEqual('unknown command "idontexistand"', str(e))
323
 
 
324
 
    def test_not_found_with_suggestion(self):
325
 
        e = self.assertRaises(errors.BzrCommandError,
326
 
            commands.get_cmd_object, 'statue')
327
 
        self.assertEqual('unknown command "statue". Perhaps you meant "status"',
328
 
            str(e))
329
 
 
330
 
 
331
312
class TestGetMissingCommandHook(tests.TestCase):
332
313
 
333
314
    def hook_missing(self):
392
373
        self.assertSubset(['foo', 'bar'], cmds)
393
374
 
394
375
class TestPreAndPostCommandHooks(tests.TestCase):
395
 
    class TestError(Exception):
 
376
    class TestError(StandardError):
396
377
        __doc__ = """A test exception."""
397
378
 
398
379
    def test_pre_and_post_hooks(self):
448
429
        def pre_command(cmd):
449
430
            hook_calls.append('pre')
450
431
            # verify that all subclasses of BzrCommandError caught too
451
 
            raise commands.BzrOptionError()
 
432
            raise errors.BzrOptionError()
452
433
 
453
434
        def post_command(cmd, e):
454
435
            self.fail('post_command should not be called')
468
449
                          commands.run_bzr, [u'rocks'])
469
450
        self.assertEqual(['pre'], hook_calls)
470
451
 
471
 
 
472
 
class GuessCommandTests(tests.TestCase):
473
 
 
474
 
    def setUp(self):
475
 
        super(GuessCommandTests, self).setUp()
476
 
        commands._register_builtin_commands()
477
 
        commands.install_bzr_command_hooks()
478
 
 
479
 
    def test_guess_override(self):
480
 
        self.assertEqual('ci', commands.guess_command('ic'))
481
 
 
482
 
    def test_guess(self):
483
 
        commands.get_cmd_object('status')
484
 
        self.assertEqual('status', commands.guess_command('statue'))
485
 
 
486
 
    def test_none(self):
487
 
        self.assertIs(None, commands.guess_command('nothingisevenclose'))