/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: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

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
    )
32
 
 
33
 
from bzrlib.tests import TestCaseInTempDir, TestCase
34
 
from bzrlib.errors import NotBranchError
35
 
 
36
 
 
37
 
class TestExceptionReporting(TestCase):
 
31
from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
 
32
 
 
33
 
 
34
class TestExceptionReporting(tests.TestCaseInTempDir):
38
35
 
39
36
    def test_exception_exitcode(self):
40
37
        # we must use a subprocess, because the normal in-memory mechanism
47
44
                r'exceptions\.AssertionError: always fails\n')
48
45
        self.assertContainsRe(err, r'Bazaar has encountered an internal error')
49
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.assertEquals(out, "")
 
62
 
 
63
    def test_utf8_default_fs_enc(self):
 
64
        """In the C locale bzr treats a posix filesystem as UTF-8 encoded"""
 
65
        if os.name != "posix":
 
66
            raise tests.TestNotApplicable("Needs system beholden to C locales")
 
67
        out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
 
68
            env_changes={"LANG": "C", "LC_ALL": "C"})
 
69
        self.assertContainsRe(out, "^Created a standalone tree .*$")
 
70
 
 
71
 
 
72
class TestOptParseBugHandling(tests.TestCase):
 
73
    "Test that we handle http://bugs.python.org/issue2931"
 
74
 
 
75
    def test_nonascii_optparse(self):
 
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'])
 
79
 
 
80
 
 
81
class TestObsoleteRepoFormat(RepositoryFormat2a):
 
82
 
 
83
    @classmethod
 
84
    def get_format_string(cls):
 
85
        return "Test Obsolete Repository Format"
 
86
 
 
87
    def is_deprecated(self):
 
88
        return True
 
89
 
50
90
 
51
91
class TestDeprecationWarning(tests.TestCaseWithTransport):
52
92
    """The deprecation warning is controlled via a global variable:
59
99
 
60
100
    def setUp(self):
61
101
        super(TestDeprecationWarning, self).setUp()
 
102
        self.addCleanup(repository.format_registry.remove,
 
103
            TestObsoleteRepoFormat)
 
104
        repository.format_registry.register(TestObsoleteRepoFormat)
 
105
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
 
106
        bzrdir.register_metadir(controldir.format_registry, "testobsolete",
 
107
            "bzrlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
 
108
            branch_format='bzrlib.branch.BzrBranchFormat7',
 
109
            tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
 
110
            deprecated=True,
 
111
            help='Same as 2a, but with an obsolete repo format.')
62
112
        self.disable_deprecation_warning()
63
113
 
64
114
    def enable_deprecation_warning(self, repo=None):
71
121
 
72
122
    def make_obsolete_repo(self, path):
73
123
        # We don't want the deprecation raising during the repo creation
74
 
        tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
 
124
        format = controldir.format_registry.make_bzrdir("testobsolete")
 
125
        tree = self.make_branch_and_tree(path, format=format)
75
126
        return tree
76
127
 
77
128
    def check_warning(self, present):
79
130
            check = self.assertContainsRe
80
131
        else:
81
132
            check = self.assertNotContainsRe
82
 
        check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
 
133
        check(self.get_log(), 'WARNING.*bzr upgrade')
83
134
 
84
135
    def test_repository_deprecation_warning(self):
85
136
        """Old formats give a warning"""