/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/test_trace.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-05 04:30:07 UTC
  • mfrom: (4932 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4934.
  • Revision ID: john@arbash-meinel.com-20100105043007-ehgbldqd3q0gtyws
Merge bzr.dev, resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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
27
27
 
28
28
from bzrlib import (
29
29
    errors,
30
 
    trace,
31
30
    )
32
 
from bzrlib.tests import TestCaseInTempDir, TestCase, ModuleAvailableFeature
 
31
from bzrlib.tests import TestCaseInTempDir, TestCase
33
32
from bzrlib.trace import (
34
33
    mutter, mutter_callsite, report_exception,
35
34
    set_verbosity_level, get_verbosity_level, is_quiet, is_verbose, be_quiet,
36
35
    pop_log_file,
37
36
    push_log_file,
38
37
    _rollover_trace_maybe,
39
 
    show_error,
40
38
    )
41
39
 
42
40
 
104
102
        self.assertContainsRe(msg,
105
103
            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
106
104
 
107
 
    def test_format_pywintypes_error(self):
108
 
        self.requireFeature(ModuleAvailableFeature("pywintypes"))
109
 
        import pywintypes, win32file
110
 
        try:
111
 
            win32file.RemoveDirectory('nosuchfile22222')
112
 
        except pywintypes.error:
113
 
            pass
114
 
        msg = _format_exception()
115
 
        # GZ 2010-05-03: Formatting for pywintypes.error is basic, a 3-tuple
116
 
        #                with errno, function name, and locale error message
117
 
        self.assertContainsRe(msg,
118
 
            r"^bzr: ERROR: \(2, 'RemoveDirectory', .*\)")
119
 
 
120
105
    def test_format_unicode_error(self):
121
106
        try:
122
107
            raise errors.BzrCommandError(u'argument foo\xb5 does not exist')
229
214
        # have to do a replaceent here as well.
230
215
        self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8',
231
216
            'replace'))
232
 
        
233
 
    def test_show_error(self):
234
 
        show_error('error1')
235
 
        show_error(u'error2 \xb5 blah')
236
 
        show_error('arg: %s', 'blah')
237
 
        show_error('arg2: %(key)s', {'key':'stuff'})
238
 
        try:
239
 
            raise Exception("oops")
240
 
        except:
241
 
            show_error('kwarg', exc_info=True)
242
 
        log = self.get_log()
243
 
        self.assertContainsRe(log, 'error1')
244
 
        self.assertContainsRe(log, u'error2 \xb5 blah')
245
 
        self.assertContainsRe(log, 'arg: blah')
246
 
        self.assertContainsRe(log, 'arg2: stuff')
247
 
        self.assertContainsRe(log, 'kwarg')
248
 
        self.assertContainsRe(log, 'Traceback \\(most recent call last\\):')
249
 
        self.assertContainsRe(log, 'File ".*test_trace.py", line .*, in test_show_error')
250
 
        self.assertContainsRe(log, 'raise Exception\\("oops"\\)')
251
 
        self.assertContainsRe(log, 'Exception: oops')
252
217
 
253
218
    def test_push_log_file(self):
254
219
        """Can push and pop log file, and this catches mutter messages.
283
248
            tmp1.close()
284
249
            tmp2.close()
285
250
 
286
 
    def test__open_bzr_log_uses_stderr_for_failures(self):
287
 
        # If _open_bzr_log cannot open the file, then we should write the
288
 
        # warning to stderr. Since this is normally happening before logging is
289
 
        # set up.
290
 
        self.overrideAttr(sys, 'stderr', StringIO())
291
 
        # Set the log file to something that cannot exist
292
 
        # FIXME: A bit dangerous: we are not in an isolated dir here -- vilajam
293
 
        # 20100125
294
 
        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
295
 
        self.overrideAttr(trace, '_bzr_log_filename')
296
 
        logf = trace._open_bzr_log()
297
 
        self.assertIs(None, logf)
298
 
        self.assertContainsRe(sys.stderr.getvalue(),
299
 
                              'failed to open trace file: .*/no-dir/bzr.log')
300
 
 
301
251
 
302
252
class TestVerbosityLevel(TestCase):
303
253