~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_exceptions.py

merge trunk

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
 
import os
21
19
import sys
22
20
 
23
21
from bzrlib import (
24
22
    bzrdir,
25
23
    config,
 
24
    controldir,
26
25
    errors,
27
26
    osutils,
28
27
    repository,
29
28
    tests,
30
 
    trace,
31
29
    )
 
30
from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
32
31
 
33
 
from bzrlib.tests import TestCaseInTempDir, TestCase
34
 
from bzrlib.errors import NotBranchError
 
32
from bzrlib.tests import TestCase
35
33
 
36
34
 
37
35
class TestExceptionReporting(TestCase):
48
46
        self.assertContainsRe(err, r'Bazaar has encountered an internal error')
49
47
 
50
48
 
 
49
class TestOptParseBugHandling(TestCase):
 
50
    "Test that we handle http://bugs.python.org/issue2931"
 
51
 
 
52
    def test_nonascii_optparse(self):
 
53
        """Reasonable error raised when non-ascii in option name"""
 
54
        if sys.version_info < (2,5):
 
55
            error_re = 'no such option'
 
56
        else:
 
57
            error_re = 'Only ASCII permitted in option names'
 
58
        out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
 
59
 
 
60
 
 
61
class TestObsoleteRepoFormat(RepositoryFormat2a):
 
62
 
 
63
    @classmethod
 
64
    def get_format_string(cls):
 
65
        return "Test Obsolete Repository Format"
 
66
 
 
67
    def is_deprecated(self):
 
68
        return True
 
69
 
 
70
 
51
71
class TestDeprecationWarning(tests.TestCaseWithTransport):
52
72
    """The deprecation warning is controlled via a global variable:
53
73
    repository._deprecation_warning_done. As such, it can be emitted only once
59
79
 
60
80
    def setUp(self):
61
81
        super(TestDeprecationWarning, self).setUp()
 
82
        self.addCleanup(repository.format_registry.remove,
 
83
            TestObsoleteRepoFormat)
 
84
        repository.format_registry.register(TestObsoleteRepoFormat)
 
85
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
 
86
        bzrdir.register_metadir(controldir.format_registry, "testobsolete",
 
87
            "bzrlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
 
88
            branch_format='bzrlib.branch.BzrBranchFormat7',
 
89
            tree_format='bzrlib.workingtree.WorkingTreeFormat6',
 
90
            deprecated=True,
 
91
            help='Same as 2a, but with an obsolete repo format.')
62
92
        self.disable_deprecation_warning()
63
93
 
64
94
    def enable_deprecation_warning(self, repo=None):
71
101
 
72
102
    def make_obsolete_repo(self, path):
73
103
        # We don't want the deprecation raising during the repo creation
74
 
        tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
 
104
        format = controldir.format_registry.make_bzrdir("testobsolete")
 
105
        tree = self.make_branch_and_tree(path, format=format)
75
106
        return tree
76
107
 
77
108
    def check_warning(self, present):