~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Martin Pool
  • Date: 2010-08-18 07:25:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5383.
  • Revision ID: mbp@sourcefrog.net-20100818072522-uk3gsazoia3l3s0a
Start adding 'what's new in 2.3'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
25
25
    bzrdir,
26
26
    errors,
27
27
    osutils,
 
28
    symbol_versioning,
28
29
    urlutils,
29
30
    )
30
 
from bzrlib.tests import (
31
 
    TestCase,
32
 
    TestCaseWithTransport,
33
 
    TestSkipped,
34
 
    )
 
31
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
35
32
 
36
33
 
37
34
class TestErrors(TestCaseWithTransport):
162
159
            "cannot be broken.",
163
160
            str(error))
164
161
 
165
 
    def test_lock_corrupt(self):
166
 
        error = errors.LockCorrupt("corruption info")
167
 
        self.assertEqualDiff("Lock is apparently held, but corrupted: "
168
 
            "corruption info\n"
169
 
            "Use 'bzr break-lock' to clear it",
170
 
            str(error))
171
 
 
172
162
    def test_knit_data_stream_incompatible(self):
173
163
        error = errors.KnitDataStreamIncompatible(
174
164
            'stream format', 'target format')
300
290
            str(error))
301
291
 
302
292
    def test_up_to_date(self):
303
 
        error = errors.UpToDateFormat("someformat")
304
 
        self.assertEqualDiff(
305
 
            "The branch format someformat is already at the most "
306
 
            "recent format.", str(error))
 
293
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
 
294
        self.assertEqualDiff("The branch format All-in-one "
 
295
                             "format 4 is already at the most "
 
296
                             "recent format.",
 
297
                             str(error))
307
298
 
308
299
    def test_corrupt_repository(self):
309
300
        repo = self.make_repository('.')
577
568
        try:
578
569
            1/0
579
570
        except ZeroDivisionError:
580
 
            err = errors.HookFailed('hook stage', 'hook name', sys.exc_info(),
581
 
                warn=False)
582
 
        # GZ 2010-11-08: Should not store exc_info in exception instances, but
583
 
        #                HookFailed is deprecated anyway and could maybe go.
584
 
        try:
585
 
            self.assertStartsWith(
586
 
                str(err), 'Hook \'hook name\' during hook stage failed:\n')
587
 
            self.assertEndsWith(
588
 
                str(err), 'integer division or modulo by zero')
589
 
        finally:
590
 
            del err
 
571
            exc_info = sys.exc_info()
 
572
        err = errors.HookFailed('hook stage', 'hook name', exc_info, warn=False)
 
573
        self.assertStartsWith(
 
574
            str(err), 'Hook \'hook name\' during hook stage failed:\n')
 
575
        self.assertEndsWith(
 
576
            str(err), 'integer division or modulo by zero')
591
577
 
592
578
    def test_tip_change_rejected(self):
593
579
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
616
602
        try:
617
603
            raise Exception("example error")
618
604
        except Exception:
619
 
            err = errors.SmartMessageHandlerError(sys.exc_info())
620
 
        # GZ 2010-11-08: Should not store exc_info in exception instances.
621
 
        try:
622
 
            self.assertStartsWith(
623
 
                str(err), "The message handler raised an exception:\n")
624
 
            self.assertEndsWith(str(err), "Exception: example error\n")
625
 
        finally:
626
 
            del err
 
605
            exc_info = sys.exc_info()
 
606
        err = errors.SmartMessageHandlerError(exc_info)
 
607
        self.assertStartsWith(
 
608
            str(err), "The message handler raised an exception:\n")
 
609
        self.assertEndsWith(str(err), "Exception: example error\n")
627
610
 
628
611
    def test_must_have_working_tree(self):
629
612
        err = errors.MustHaveWorkingTree('foo', 'bar')
682
665
        err = errors.NotBranchError('path', bzrdir=bzrdir)
683
666
        self.assertEqual('Not a branch: "path".', str(err))
684
667
 
685
 
    def test_not_branch_bzrdir_with_recursive_not_branch_error(self):
686
 
        class FakeBzrDir(object):
687
 
            def open_repository(self):
688
 
                # str() on the NotBranchError will trigger a call to this,
689
 
                # which in turn will another, identical NotBranchError.
690
 
                raise errors.NotBranchError('path', bzrdir=FakeBzrDir())
691
 
        err = errors.NotBranchError('path', bzrdir=FakeBzrDir())
692
 
        self.assertEqual('Not a branch: "path".', str(err))
693
 
 
694
668
    def test_not_branch_laziness(self):
695
669
        real_bzrdir = self.make_bzrdir('path')
696
670
        class FakeBzrDir(object):