~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
18
18
 
19
19
"""Tests for trace library"""
20
20
 
 
21
from cStringIO import StringIO
21
22
import errno
22
23
import os
23
24
import sys
24
 
from StringIO import StringIO
25
25
 
 
26
from bzrlib import (
 
27
    errors,
 
28
    )
26
29
from bzrlib.tests import TestCaseInTempDir, TestCase
27
30
from bzrlib.trace import mutter, report_exception
28
 
from bzrlib.errors import NotBranchError
29
31
 
30
32
 
31
33
def _format_exception():
66
68
        msg = _format_exception()
67
69
        self.assertContainsRe(msg, r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
68
70
 
 
71
    def test_format_unicode_error(self):
 
72
        try:
 
73
            raise errors.BzrCommandError(u'argument foo\xb5 does not exist')
 
74
        except errors.BzrCommandError:
 
75
            pass
 
76
        msg = _format_exception()
69
77
 
70
78
    def test_format_exception(self):
71
79
        """Short formatting of bzr exceptions"""
72
80
        try:
73
 
            raise NotBranchError, 'wibble'
74
 
        except NotBranchError:
 
81
            raise errors.NotBranchError, 'wibble'
 
82
        except errors.NotBranchError:
75
83
            pass
76
84
        msg = _format_exception()
77
85
        self.assertTrue(len(msg) > 0)
80
88
    def test_trace_unicode(self):
81
89
        """Write Unicode to trace log"""
82
90
        self.log(u'the unicode character for benzene is \N{BENZENE RING}')
83
 
        self.assertContainsRe('the unicode character',
84
 
                self._get_log())
 
91
        self.assertContainsRe(self._get_log(keep_log_file=True),
 
92
                              "the unicode character for benzene is")
 
93
    
 
94
    def test_trace_argument_unicode(self):
 
95
        """Write a Unicode argument to the trace log"""
 
96
        mutter(u'the unicode character for benzene is %s', u'\N{BENZENE RING}')
 
97
        self.assertContainsRe(self._get_log(keep_log_file=True),
 
98
                              'the unicode character')
 
99
 
 
100
    def test_trace_argument_utf8(self):
 
101
        """Write a Unicode argument to the trace log"""
 
102
        mutter(u'the unicode character for benzene is %s',
 
103
               u'\N{BENZENE RING}'.encode('utf-8'))
 
104
        self.assertContainsRe(self._get_log(keep_log_file=True),
 
105
                              'the unicode character')
85
106
 
86
107
    def test_report_broken_pipe(self):
87
108
        try:
97
118
        # raise an exception
98
119
        mutter(u'Writing a greek mu (\xb5) works in a unicode string')
99
120
        mutter('But fails in an ascii string \xb5')
100
 
        # TODO: jam 20051227 mutter() doesn't flush the log file, and
101
 
        #       self._get_log() opens the file directly and reads it.
102
 
        #       So we need to manually flush the log file
103
 
        import bzrlib.trace
104
 
        bzrlib.trace._trace_file.flush()
105
 
        log = self._get_log()
 
121
        mutter('and in an ascii argument: %s', '\xb5')
 
122
        log = self._get_log(keep_log_file=True)
106
123
        self.assertContainsRe(log, 'Writing a greek mu')
107
 
        self.assertContainsRe(log, 'UnicodeError')
108
 
        self.assertContainsRe(log, "'But fails in an ascii string")
 
124
        self.assertContainsRe(log, "But fails in an ascii string")
 
125
        self.assertContainsRe(log, u"ascii argument: \xb5")