~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
from bzrlib import (
29
29
    errors,
 
30
    trace,
30
31
    )
31
32
from bzrlib.tests import TestCaseInTempDir, TestCase
32
33
from bzrlib.trace import (
248
249
            tmp1.close()
249
250
            tmp2.close()
250
251
 
 
252
    def test__open_bzr_log_uses_stderr_for_failures(self):
 
253
        # If _open_bzr_log cannot open the file, then we should write the
 
254
        # warning to stderr. Since this is normally happening before logging is
 
255
        # 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()
 
260
        # Set the log file to something that cannot exist
 
261
        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
 
262
        logf = trace._open_bzr_log()
 
263
        self.assertIs(None, logf)
 
264
        self.assertContainsRe(sys.stderr.getvalue(),
 
265
                              'failed to open trace file: .*/no-dir/bzr.log')
251
266
 
252
267
class TestVerbosityLevel(TestCase):
253
268