/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: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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 (
 
23
    bzr,
25
24
    config,
 
25
    controldir,
26
26
    errors,
27
27
    osutils,
28
28
    repository,
29
29
    tests,
30
 
    trace,
31
30
    )
32
 
 
33
 
from bzrlib.tests import TestCaseInTempDir, TestCase
34
 
from bzrlib.errors import NotBranchError
35
 
 
36
 
 
37
 
class TestExceptionReporting(TestCase):
 
31
from breezy.sixish import PY3
 
32
from breezy.bzr.groupcompress_repo import RepositoryFormat2a
 
33
 
 
34
 
 
35
class TestExceptionReporting(tests.TestCaseInTempDir):
38
36
 
39
37
    def test_exception_exitcode(self):
40
38
        # we must use a subprocess, because the normal in-memory mechanism
41
39
        # allows errors to propagate up through the test suite
42
40
        out, err = self.run_bzr_subprocess(['assert-fail'],
43
 
            universal_newlines=True,
44
 
            retcode=errors.EXIT_INTERNAL_ERROR)
 
41
                                           universal_newlines=True,
 
42
                                           retcode=errors.EXIT_INTERNAL_ERROR)
45
43
        self.assertEqual(4, errors.EXIT_INTERNAL_ERROR)
46
 
        self.assertContainsRe(err,
47
 
                r'exceptions\.AssertionError: always fails\n')
48
 
        self.assertContainsRe(err, r'Bazaar has encountered an internal error')
 
44
        self.assertContainsRe(err, br'\nAssertionError: always fails\n')
 
45
        self.assertContainsRe(
 
46
            err, br'Bazaar has encountered an internal error')
 
47
 
 
48
    def test_undecodable_argv(self):
 
49
        """A user error must be reported if argv is not in the locale encoding
 
50
 
 
51
        A subprocess with an environment ascii-only setting is used so the test
 
52
        can run without worrying about the locale the test suite is using.
 
53
        """
 
54
        if os.name != "posix":
 
55
            raise tests.TestNotApplicable("Needs system beholden to C locales")
 
56
        if PY3:
 
57
            raise tests.TestNotApplicable(
 
58
                "Unable to pass argv to subprocess as bytes")
 
59
        out, err = self.run_bzr_subprocess([b"\xa0"],
 
60
                                           env_changes={
 
61
                                               "LANG": "C", "LC_ALL": "C"},
 
62
                                           universal_newlines=True,
 
63
                                           retcode=errors.EXIT_ERROR)
 
64
        self.assertContainsRe(err, br"^brz: ERROR: .*'\\xa0'.* unsupported",
 
65
                              flags=re.MULTILINE)
 
66
        self.assertEqual(out, b"")
 
67
 
 
68
    def test_utf8_default_fs_enc(self):
 
69
        """In the C locale brz treats a posix filesystem as UTF-8 encoded"""
 
70
        if os.name != "posix":
 
71
            raise tests.TestNotApplicable("Needs system beholden to C locales")
 
72
        out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
 
73
                                           env_changes={"LANG": "C", "LC_ALL": "C"})
 
74
        self.assertContainsRe(out, b"^Created a standalone tree .*$")
 
75
 
 
76
 
 
77
class TestOptParseBugHandling(tests.TestCase):
 
78
    "Test that we handle http://bugs.python.org/issue2931"
 
79
 
 
80
    def test_nonascii_optparse(self):
 
81
        """Reasonable error raised when non-ascii in option name on Python 2"""
 
82
        if PY3:
 
83
            error_re = u'no such option: -\xe4'
 
84
        else:
 
85
            error_re = 'Only ASCII permitted in option names'
 
86
        out = self.run_bzr_error([error_re], ['st', u'-\xe4'])
 
87
 
 
88
 
 
89
class TestObsoleteRepoFormat(RepositoryFormat2a):
 
90
 
 
91
    @classmethod
 
92
    def get_format_string(cls):
 
93
        return b"Test Obsolete Repository Format"
 
94
 
 
95
    def is_deprecated(self):
 
96
        return True
49
97
 
50
98
 
51
99
class TestDeprecationWarning(tests.TestCaseWithTransport):
52
100
    """The deprecation warning is controlled via a global variable:
53
101
    repository._deprecation_warning_done. As such, it can be emitted only once
54
 
    during a bzr invocation, no matter how many repositories are involved.
 
102
    during a brz invocation, no matter how many repositories are involved.
55
103
 
56
104
    It would be better if it was a repo attribute instead but that's far more
57
105
    work than I want to do right now -- vila 20091215.
59
107
 
60
108
    def setUp(self):
61
109
        super(TestDeprecationWarning, self).setUp()
 
110
        self.addCleanup(repository.format_registry.remove,
 
111
                        TestObsoleteRepoFormat)
 
112
        repository.format_registry.register(TestObsoleteRepoFormat)
 
113
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
 
114
        bzr.register_metadir(controldir.format_registry, "testobsolete",
 
115
                             "breezy.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
 
116
                             branch_format='breezy.bzr.branch.BzrBranchFormat7',
 
117
                             tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
 
118
                             deprecated=True,
 
119
                             help='Same as 2a, but with an obsolete repo format.')
62
120
        self.disable_deprecation_warning()
63
121
 
64
122
    def enable_deprecation_warning(self, repo=None):
71
129
 
72
130
    def make_obsolete_repo(self, path):
73
131
        # We don't want the deprecation raising during the repo creation
74
 
        tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
 
132
        format = controldir.format_registry.make_controldir("testobsolete")
 
133
        tree = self.make_branch_and_tree(path, format=format)
75
134
        return tree
76
135
 
77
136
    def check_warning(self, present):
79
138
            check = self.assertContainsRe
80
139
        else:
81
140
            check = self.assertNotContainsRe
82
 
        check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
 
141
        check(self.get_log(), 'WARNING.*brz upgrade')
83
142
 
84
143
    def test_repository_deprecation_warning(self):
85
144
        """Old formats give a warning"""
90
149
 
91
150
    def test_repository_deprecation_warning_suppressed_global(self):
92
151
        """Old formats give a warning"""
93
 
        conf = config.GlobalConfig()
94
 
        conf.set_user_option('suppress_warnings', 'format_deprecation')
 
152
        conf = config.GlobalStack()
 
153
        conf.set('suppress_warnings', 'format_deprecation')
95
154
        self.make_obsolete_repo('foo')
96
155
        self.enable_deprecation_warning()
97
156
        out, err = self.run_bzr('status', working_dir='foo')
100
159
    def test_repository_deprecation_warning_suppressed_locations(self):
101
160
        """Old formats give a warning"""
102
161
        self.make_obsolete_repo('foo')
103
 
        conf = config.LocationConfig(osutils.pathjoin(self.test_dir, 'foo'))
104
 
        conf.set_user_option('suppress_warnings', 'format_deprecation')
 
162
        conf = config.LocationStack(osutils.pathjoin(self.test_dir, 'foo'))
 
163
        conf.set('suppress_warnings', 'format_deprecation')
105
164
        self.enable_deprecation_warning()
106
165
        out, err = self.run_bzr('status', working_dir='foo')
107
166
        self.check_warning(False)
109
168
    def test_repository_deprecation_warning_suppressed_branch(self):
110
169
        """Old formats give a warning"""
111
170
        tree = self.make_obsolete_repo('foo')
112
 
        conf = tree.branch.get_config()
113
 
        conf.set_user_option('suppress_warnings', 'format_deprecation')
 
171
        conf = tree.branch.get_config_stack()
 
172
        conf.set('suppress_warnings', 'format_deprecation')
114
173
        self.enable_deprecation_warning()
115
174
        out, err = self.run_bzr('status', working_dir='foo')
116
175
        self.check_warning(False)