/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: Jelmer Vernooij
  • Date: 2010-01-20 23:26:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4977.
  • Revision ID: jelmer@samba.org-20100120232631-b9mz0z55712eaxfa
Cope with ghosts in 'bzr diff'

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
36
36
    pop_log_file,
37
37
    push_log_file,
38
38
    _rollover_trace_maybe,
39
 
    show_error,
40
39
    )
41
40
 
42
41
 
216
215
        # have to do a replaceent here as well.
217
216
        self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8',
218
217
            'replace'))
219
 
        
220
 
    def test_show_error(self):
221
 
        show_error('error1')
222
 
        show_error(u'error2 \xb5 blah')
223
 
        show_error('arg: %s', 'blah')
224
 
        show_error('arg2: %(key)s', {'key':'stuff'})
225
 
        try:
226
 
            raise Exception("oops")
227
 
        except:
228
 
            show_error('kwarg', exc_info=True)
229
 
        log = self.get_log()
230
 
        self.assertContainsRe(log, 'error1')
231
 
        self.assertContainsRe(log, u'error2 \xb5 blah')
232
 
        self.assertContainsRe(log, 'arg: blah')
233
 
        self.assertContainsRe(log, 'arg2: stuff')
234
 
        self.assertContainsRe(log, 'kwarg')
235
 
        self.assertContainsRe(log, 'Traceback \\(most recent call last\\):')
236
 
        self.assertContainsRe(log, 'File ".*test_trace.py", line .*, in test_show_error')
237
 
        self.assertContainsRe(log, 'raise Exception\\("oops"\\)')
238
 
        self.assertContainsRe(log, 'Exception: oops')
239
218
 
240
219
    def test_push_log_file(self):
241
220
        """Can push and pop log file, and this catches mutter messages.
274
253
        # If _open_bzr_log cannot open the file, then we should write the
275
254
        # warning to stderr. Since this is normally happening before logging is
276
255
        # set up.
277
 
        self.overrideAttr(sys, 'stderr', StringIO())
 
256
        self.addCleanup(setattr, sys, 'stderr', sys.stderr)
 
257
        self.addCleanup(setattr, trace, '_bzr_log_filename',
 
258
                        trace._bzr_log_filename)
 
259
        sys.stderr = StringIO()
278
260
        # Set the log file to something that cannot exist
279
 
        # FIXME: A bit dangerous: we are not in an isolated dir here -- vilajam
280
 
        # 20100125
281
261
        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
282
 
        self.overrideAttr(trace, '_bzr_log_filename')
283
262
        logf = trace._open_bzr_log()
284
263
        self.assertIs(None, logf)
285
264
        self.assertContainsRe(sys.stderr.getvalue(),
286
265
                              'failed to open trace file: .*/no-dir/bzr.log')
287
266
 
288
 
 
289
267
class TestVerbosityLevel(TestCase):
290
268
 
291
269
    def test_verbosity_level(self):