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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import re
21
21
 
22
 
from breezy import (
23
 
    bzr,
 
22
from brzlib import (
 
23
    bzrdir,
24
24
    config,
25
25
    controldir,
26
26
    errors,
28
28
    repository,
29
29
    tests,
30
30
    )
31
 
from breezy.bzr.groupcompress_repo import RepositoryFormat2a
 
31
from brzlib.repofmt.groupcompress_repo import RepositoryFormat2a
32
32
 
33
33
 
34
34
class TestExceptionReporting(tests.TestCaseInTempDir):
37
37
        # we must use a subprocess, because the normal in-memory mechanism
38
38
        # allows errors to propagate up through the test suite
39
39
        out, err = self.run_bzr_subprocess(['assert-fail'],
40
 
                                           universal_newlines=True,
41
 
                                           retcode=errors.EXIT_INTERNAL_ERROR)
 
40
            universal_newlines=True,
 
41
            retcode=errors.EXIT_INTERNAL_ERROR)
42
42
        self.assertEqual(4, errors.EXIT_INTERNAL_ERROR)
43
 
        self.assertContainsRe(err, br'\nAssertionError: always fails\n')
44
 
        self.assertContainsRe(
45
 
            err, br'Bazaar has encountered an internal error')
 
43
        self.assertContainsRe(err,
 
44
                r'exceptions\.AssertionError: always fails\n')
 
45
        self.assertContainsRe(err, r'Bazaar has encountered an internal error')
 
46
 
 
47
    def test_undecodable_argv(self):
 
48
        """A user error must be reported if argv is not in the locale encoding
 
49
 
 
50
        A subprocess with an environment ascii-only setting is used so the test
 
51
        can run without worrying about the locale the test suite is using.
 
52
        """
 
53
        if os.name != "posix":
 
54
            raise tests.TestNotApplicable("Needs system beholden to C locales")
 
55
        out, err = self.run_bzr_subprocess(["\xa0"],
 
56
            env_changes={"LANG": "C", "LC_ALL": "C"},
 
57
            universal_newlines=True,
 
58
            retcode=errors.EXIT_ERROR)
 
59
        self.assertContainsRe(err, r"^bzr: ERROR: .*'\\xa0'.* unsupported",
 
60
            flags=re.MULTILINE)
 
61
        self.assertEqual(out, "")
46
62
 
47
63
    def test_utf8_default_fs_enc(self):
48
 
        """In the C locale brz treats a posix filesystem as UTF-8 encoded"""
 
64
        """In the C locale bzr treats a posix filesystem as UTF-8 encoded"""
49
65
        if os.name != "posix":
50
66
            raise tests.TestNotApplicable("Needs system beholden to C locales")
51
67
        out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
52
 
                                           env_changes={"LANG": "C", "LC_ALL": "C"})
53
 
        self.assertContainsRe(out, b"^Created a standalone tree .*$")
 
68
            env_changes={"LANG": "C", "LC_ALL": "C"})
 
69
        self.assertContainsRe(out, "^Created a standalone tree .*$")
54
70
 
55
71
 
56
72
class TestOptParseBugHandling(tests.TestCase):
57
73
    "Test that we handle http://bugs.python.org/issue2931"
58
74
 
59
75
    def test_nonascii_optparse(self):
60
 
        """Reasonable error raised when non-ascii in option name on Python 2"""
61
 
        error_re = u'no such option: -\xe4'
62
 
        out = self.run_bzr_error([error_re], ['st', u'-\xe4'])
 
76
        """Reasonable error raised when non-ascii in option name"""
 
77
        error_re = 'Only ASCII permitted in option names'
 
78
        out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
63
79
 
64
80
 
65
81
class TestObsoleteRepoFormat(RepositoryFormat2a):
66
82
 
67
83
    @classmethod
68
84
    def get_format_string(cls):
69
 
        return b"Test Obsolete Repository Format"
 
85
        return "Test Obsolete Repository Format"
70
86
 
71
87
    def is_deprecated(self):
72
88
        return True
75
91
class TestDeprecationWarning(tests.TestCaseWithTransport):
76
92
    """The deprecation warning is controlled via a global variable:
77
93
    repository._deprecation_warning_done. As such, it can be emitted only once
78
 
    during a brz invocation, no matter how many repositories are involved.
 
94
    during a bzr invocation, no matter how many repositories are involved.
79
95
 
80
96
    It would be better if it was a repo attribute instead but that's far more
81
97
    work than I want to do right now -- vila 20091215.
84
100
    def setUp(self):
85
101
        super(TestDeprecationWarning, self).setUp()
86
102
        self.addCleanup(repository.format_registry.remove,
87
 
                        TestObsoleteRepoFormat)
 
103
            TestObsoleteRepoFormat)
88
104
        repository.format_registry.register(TestObsoleteRepoFormat)
89
105
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
90
 
        bzr.register_metadir(controldir.format_registry, "testobsolete",
91
 
                             "breezy.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
92
 
                             branch_format='breezy.bzr.branch.BzrBranchFormat7',
93
 
                             tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
94
 
                             deprecated=True,
95
 
                             help='Same as 2a, but with an obsolete repo format.')
 
106
        bzrdir.register_metadir(controldir.format_registry, "testobsolete",
 
107
            "brzlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
 
108
            branch_format='brzlib.branch.BzrBranchFormat7',
 
109
            tree_format='brzlib.workingtree_4.WorkingTreeFormat6',
 
110
            deprecated=True,
 
111
            help='Same as 2a, but with an obsolete repo format.')
96
112
        self.disable_deprecation_warning()
97
113
 
98
114
    def enable_deprecation_warning(self, repo=None):
105
121
 
106
122
    def make_obsolete_repo(self, path):
107
123
        # We don't want the deprecation raising during the repo creation
108
 
        format = controldir.format_registry.make_controldir("testobsolete")
 
124
        format = controldir.format_registry.make_bzrdir("testobsolete")
109
125
        tree = self.make_branch_and_tree(path, format=format)
110
126
        return tree
111
127
 
114
130
            check = self.assertContainsRe
115
131
        else:
116
132
            check = self.assertNotContainsRe
117
 
        check(self.get_log(), 'WARNING.*brz upgrade')
 
133
        check(self.get_log(), 'WARNING.*bzr upgrade')
118
134
 
119
135
    def test_repository_deprecation_warning(self):
120
136
        """Old formats give a warning"""