~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    pop_log_file,
37
37
    push_log_file,
38
38
    _rollover_trace_maybe,
 
39
    show_error,
39
40
    )
40
41
 
41
42
 
215
216
        # have to do a replaceent here as well.
216
217
        self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8',
217
218
            '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')
218
239
 
219
240
    def test_push_log_file(self):
220
241
        """Can push and pop log file, and this catches mutter messages.
253
274
        # If _open_bzr_log cannot open the file, then we should write the
254
275
        # warning to stderr. Since this is normally happening before logging is
255
276
        # set up.
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()
 
277
        self.overrideAttr(sys, 'stderr', StringIO())
260
278
        # 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
261
281
        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
 
282
        self.overrideAttr(trace, '_bzr_log_filename')
262
283
        logf = trace._open_bzr_log()
263
284
        self.assertIs(None, logf)
264
285
        self.assertContainsRe(sys.stderr.getvalue(),
265
286
                              'failed to open trace file: .*/no-dir/bzr.log')
266
287
 
 
288
 
267
289
class TestVerbosityLevel(TestCase):
268
290
 
269
291
    def test_verbosity_level(self):