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

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 21:59:15 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610215915-zcpu0in3r1irx3ml
Move serializer to bzr.

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-2012, 2016 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
 
from bzrlib import (
24
 
    bzrdir,
 
22
from breezy import (
25
23
    config,
 
24
    controldir,
26
25
    errors,
27
26
    osutils,
28
27
    repository,
29
28
    tests,
30
 
    trace,
31
 
    )
32
 
 
33
 
from bzrlib.tests import TestCaseInTempDir, TestCase
34
 
from bzrlib.errors import NotBranchError
35
 
 
36
 
 
37
 
class TestExceptionReporting(TestCase):
 
29
    )
 
30
from breezy.bzr import (
 
31
    bzrdir,
 
32
    )
 
33
from breezy.bzr.groupcompress_repo import RepositoryFormat2a
 
34
 
 
35
 
 
36
class TestExceptionReporting(tests.TestCaseInTempDir):
38
37
 
39
38
    def test_exception_exitcode(self):
40
39
        # we must use a subprocess, because the normal in-memory mechanism
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"^brz: ERROR: .*'\\xa0'.* unsupported",
 
62
            flags=re.MULTILINE)
 
63
        self.assertEqual(out, "")
 
64
 
 
65
    def test_utf8_default_fs_enc(self):
 
66
        """In the C locale brz treats a posix filesystem as UTF-8 encoded"""
 
67
        if os.name != "posix":
 
68
            raise tests.TestNotApplicable("Needs system beholden to C locales")
 
69
        out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
 
70
            env_changes={"LANG": "C", "LC_ALL": "C"})
 
71
        self.assertContainsRe(out, "^Created a standalone tree .*$")
 
72
 
 
73
 
 
74
class TestOptParseBugHandling(tests.TestCase):
 
75
    "Test that we handle http://bugs.python.org/issue2931"
 
76
 
 
77
    def test_nonascii_optparse(self):
 
78
        """Reasonable error raised when non-ascii in option name"""
 
79
        error_re = 'Only ASCII permitted in option names'
 
80
        out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
 
81
 
 
82
 
 
83
class TestObsoleteRepoFormat(RepositoryFormat2a):
 
84
 
 
85
    @classmethod
 
86
    def get_format_string(cls):
 
87
        return "Test Obsolete Repository Format"
 
88
 
 
89
    def is_deprecated(self):
 
90
        return True
 
91
 
50
92
 
51
93
class TestDeprecationWarning(tests.TestCaseWithTransport):
52
94
    """The deprecation warning is controlled via a global variable:
53
95
    repository._deprecation_warning_done. As such, it can be emitted only once
54
 
    during a bzr invocation, no matter how many repositories are involved.
 
96
    during a brz invocation, no matter how many repositories are involved.
55
97
 
56
98
    It would be better if it was a repo attribute instead but that's far more
57
99
    work than I want to do right now -- vila 20091215.
59
101
 
60
102
    def setUp(self):
61
103
        super(TestDeprecationWarning, self).setUp()
 
104
        self.addCleanup(repository.format_registry.remove,
 
105
            TestObsoleteRepoFormat)
 
106
        repository.format_registry.register(TestObsoleteRepoFormat)
 
107
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
 
108
        bzrdir.register_metadir(controldir.format_registry, "testobsolete",
 
109
            "breezy.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
 
110
            branch_format='breezy.bzrbranch.BzrBranchFormat7',
 
111
            tree_format='breezy.workingtree_4.WorkingTreeFormat6',
 
112
            deprecated=True,
 
113
            help='Same as 2a, but with an obsolete repo format.')
62
114
        self.disable_deprecation_warning()
63
115
 
64
116
    def enable_deprecation_warning(self, repo=None):
71
123
 
72
124
    def make_obsolete_repo(self, path):
73
125
        # We don't want the deprecation raising during the repo creation
74
 
        tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
 
126
        format = controldir.format_registry.make_controldir("testobsolete")
 
127
        tree = self.make_branch_and_tree(path, format=format)
75
128
        return tree
76
129
 
77
130
    def check_warning(self, present):
79
132
            check = self.assertContainsRe
80
133
        else:
81
134
            check = self.assertNotContainsRe
82
 
        check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
 
135
        check(self.get_log(), 'WARNING.*brz upgrade')
83
136
 
84
137
    def test_repository_deprecation_warning(self):
85
138
        """Old formats give a warning"""
90
143
 
91
144
    def test_repository_deprecation_warning_suppressed_global(self):
92
145
        """Old formats give a warning"""
93
 
        conf = config.GlobalConfig()
94
 
        conf.set_user_option('suppress_warnings', 'format_deprecation')
 
146
        conf = config.GlobalStack()
 
147
        conf.set('suppress_warnings', 'format_deprecation')
95
148
        self.make_obsolete_repo('foo')
96
149
        self.enable_deprecation_warning()
97
150
        out, err = self.run_bzr('status', working_dir='foo')
100
153
    def test_repository_deprecation_warning_suppressed_locations(self):
101
154
        """Old formats give a warning"""
102
155
        self.make_obsolete_repo('foo')
103
 
        conf = config.LocationConfig(osutils.pathjoin(self.test_dir, 'foo'))
104
 
        conf.set_user_option('suppress_warnings', 'format_deprecation')
 
156
        conf = config.LocationStack(osutils.pathjoin(self.test_dir, 'foo'))
 
157
        conf.set('suppress_warnings', 'format_deprecation')
105
158
        self.enable_deprecation_warning()
106
159
        out, err = self.run_bzr('status', working_dir='foo')
107
160
        self.check_warning(False)
109
162
    def test_repository_deprecation_warning_suppressed_branch(self):
110
163
        """Old formats give a warning"""
111
164
        tree = self.make_obsolete_repo('foo')
112
 
        conf = tree.branch.get_config()
113
 
        conf.set_user_option('suppress_warnings', 'format_deprecation')
 
165
        conf = tree.branch.get_config_stack()
 
166
        conf.set('suppress_warnings', 'format_deprecation')
114
167
        self.enable_deprecation_warning()
115
168
        out, err = self.run_bzr('status', working_dir='foo')
116
169
        self.check_warning(False)