~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Martin
  • Date: 2010-06-22 00:32:37 UTC
  • mto: This revision was merged to the branch mainline in revision 5315.
  • Revision ID: gzlist@googlemail.com-20100622003237-zntnpyx8hjb5jnpw
Change interface of _command_line_to_argv so old tests can still be used with new stripping logic

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
16
16
 
17
17
"""Tests for the formatting and construction of errors."""
18
18
 
19
 
import inspect
20
 
import re
21
19
import socket
22
20
import sys
23
21
 
25
23
    bzrdir,
26
24
    errors,
27
25
    osutils,
 
26
    symbol_versioning,
28
27
    urlutils,
29
28
    )
30
 
from bzrlib.tests import (
31
 
    TestCase,
32
 
    TestCaseWithTransport,
33
 
    TestSkipped,
34
 
    )
 
29
from bzrlib.tests import TestCase, TestCaseWithTransport
35
30
 
36
31
 
37
32
class TestErrors(TestCaseWithTransport):
38
33
 
39
 
    def test_no_arg_named_message(self):
40
 
        """Ensure the __init__ and _fmt in errors do not have "message" arg.
41
 
 
42
 
        This test fails if __init__ or _fmt in errors has an argument
43
 
        named "message" as this can cause errors in some Python versions.
44
 
        Python 2.5 uses a slot for StandardError.message.
45
 
        See bug #603461
46
 
        """
47
 
        fmt_pattern = re.compile("%\(message\)[sir]")
48
 
        subclasses_present = getattr(errors.BzrError, '__subclasses__', None)
49
 
        if not subclasses_present:
50
 
            raise TestSkipped('__subclasses__ attribute required for classes. '
51
 
                'Requires Python 2.5 or later.')
52
 
        for c in errors.BzrError.__subclasses__():
53
 
            init = getattr(c, '__init__', None)
54
 
            fmt = getattr(c, '_fmt', None)
55
 
            if init:
56
 
                args = inspect.getargspec(init)[0]
57
 
                self.assertFalse('message' in args,
58
 
                    ('Argument name "message" not allowed for '
59
 
                    '"errors.%s.__init__"' % c.__name__))
60
 
            if fmt and fmt_pattern.search(fmt):
61
 
                self.assertFalse(True, ('"message" not allowed in '
62
 
                    '"errors.%s._fmt"' % c.__name__))
63
 
 
64
34
    def test_bad_filename_encoding(self):
65
35
        error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
66
36
        self.assertEqualDiff(
162
132
            "cannot be broken.",
163
133
            str(error))
164
134
 
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
135
    def test_knit_data_stream_incompatible(self):
173
136
        error = errors.KnitDataStreamIncompatible(
174
137
            'stream format', 'target format')
300
263
            str(error))
301
264
 
302
265
    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))
 
266
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
 
267
        self.assertEqualDiff("The branch format All-in-one "
 
268
                             "format 4 is already at the most "
 
269
                             "recent format.",
 
270
                             str(error))
307
271
 
308
272
    def test_corrupt_repository(self):
309
273
        repo = self.make_repository('.')
674
638
        err = errors.NotBranchError('path', bzrdir=bzrdir)
675
639
        self.assertEqual('Not a branch: "path".', str(err))
676
640
 
677
 
    def test_not_branch_bzrdir_with_recursive_not_branch_error(self):
678
 
        class FakeBzrDir(object):
679
 
            def open_repository(self):
680
 
                # str() on the NotBranchError will trigger a call to this,
681
 
                # which in turn will another, identical NotBranchError.
682
 
                raise errors.NotBranchError('path', bzrdir=FakeBzrDir())
683
 
        err = errors.NotBranchError('path', bzrdir=FakeBzrDir())
684
 
        self.assertEqual('Not a branch: "path".', str(err))
685
 
 
686
641
    def test_not_branch_laziness(self):
687
642
        real_bzrdir = self.make_bzrdir('path')
688
643
        class FakeBzrDir(object):
700
655
        str(err)
701
656
        self.assertEqual(['open_repository'], fake_bzrdir.calls)
702
657
 
703
 
    def test_invalid_pattern(self):
704
 
        error = errors.InvalidPattern('Bad pattern msg.')
705
 
        self.assertEqualDiff("Invalid pattern(s) found. Bad pattern msg.",
706
 
            str(error))
707
 
 
708
 
    def test_recursive_bind(self):
709
 
        error = errors.RecursiveBind('foo_bar_branch')
710
 
        msg = ('Branch "foo_bar_branch" appears to be bound to itself. '
711
 
            'Please use `bzr unbind` to fix.')
712
 
        self.assertEqualDiff(msg, str(error))
713
 
 
714
658
 
715
659
class PassThroughError(errors.BzrError):
716
660