/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/blackbox/test_exceptions.py

  • Committer: Jelmer Vernooij
  • Date: 2011-06-16 12:50:32 UTC
  • mto: This revision was merged to the branch mainline in revision 5979.
  • Revision ID: jelmer@samba.org-20110616125032-zgqiqw430te32584
Deprecate Repository.iter_reverse_revision_history.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009, 2010, 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
16
16
 
17
17
"""Tests for display of exceptions."""
18
18
 
19
 
from cStringIO import StringIO
20
19
import os
21
 
import sys
 
20
import re
22
21
 
23
22
from bzrlib import (
24
23
    bzrdir,
25
24
    config,
 
25
    controldir,
26
26
    errors,
27
27
    osutils,
28
28
    repository,
29
29
    tests,
30
 
    trace,
31
30
    )
 
31
from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
32
32
 
33
 
from bzrlib.tests import TestCaseInTempDir, TestCase
34
 
from bzrlib.errors import NotBranchError
 
33
from bzrlib.tests import TestCase
35
34
 
36
35
 
37
36
class TestExceptionReporting(TestCase):
47
46
                r'exceptions\.AssertionError: always fails\n')
48
47
        self.assertContainsRe(err, r'Bazaar has encountered an internal error')
49
48
 
 
49
    def test_undecodable_argv(self):
 
50
        """A user error must be reported if argv is not in the locale encoding
 
51
 
 
52
        A subprocess with an environment ascii-only setting is used so the test
 
53
        can run without worrying about the locale the test suite is using.
 
54
        """
 
55
        if os.name != "posix":
 
56
            raise tests.TestNotApplicable("Needs system beholden to C locales")
 
57
        out, err = self.run_bzr_subprocess(["\xa0"],
 
58
            env_changes={"LANG": "C", "LC_ALL": "C"},
 
59
            universal_newlines=True,
 
60
            retcode=errors.EXIT_ERROR)
 
61
        self.assertContainsRe(err, r"^bzr: ERROR: .*'\\xa0'.* unsupported",
 
62
            flags=re.MULTILINE)
 
63
        self.assertEquals(out, "")
 
64
 
 
65
 
 
66
class TestOptParseBugHandling(TestCase):
 
67
    "Test that we handle http://bugs.python.org/issue2931"
 
68
 
 
69
    def test_nonascii_optparse(self):
 
70
        """Reasonable error raised when non-ascii in option name"""
 
71
        error_re = 'Only ASCII permitted in option names'
 
72
        out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
 
73
 
 
74
 
 
75
class TestObsoleteRepoFormat(RepositoryFormat2a):
 
76
 
 
77
    @classmethod
 
78
    def get_format_string(cls):
 
79
        return "Test Obsolete Repository Format"
 
80
 
 
81
    def is_deprecated(self):
 
82
        return True
 
83
 
50
84
 
51
85
class TestDeprecationWarning(tests.TestCaseWithTransport):
52
86
    """The deprecation warning is controlled via a global variable:
59
93
 
60
94
    def setUp(self):
61
95
        super(TestDeprecationWarning, self).setUp()
 
96
        self.addCleanup(repository.format_registry.remove,
 
97
            TestObsoleteRepoFormat)
 
98
        repository.format_registry.register(TestObsoleteRepoFormat)
 
99
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
 
100
        bzrdir.register_metadir(controldir.format_registry, "testobsolete",
 
101
            "bzrlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
 
102
            branch_format='bzrlib.branch.BzrBranchFormat7',
 
103
            tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
104
            deprecated=True,
 
105
            help='Same as 2a, but with an obsolete repo format.')
62
106
        self.disable_deprecation_warning()
63
107
 
64
108
    def enable_deprecation_warning(self, repo=None):
71
115
 
72
116
    def make_obsolete_repo(self, path):
73
117
        # We don't want the deprecation raising during the repo creation
74
 
        tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
 
118
        format = controldir.format_registry.make_bzrdir("testobsolete")
 
119
        tree = self.make_branch_and_tree(path, format=format)
75
120
        return tree
76
121
 
77
122
    def check_warning(self, present):
79
124
            check = self.assertContainsRe
80
125
        else:
81
126
            check = self.assertNotContainsRe
82
 
        check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
 
127
        check(self.get_log(), 'WARNING.*bzr upgrade')
83
128
 
84
129
    def test_repository_deprecation_warning(self):
85
130
        """Old formats give a warning"""