~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

  • Committer: John Arbash Meinel
  • Date: 2010-01-06 17:46:15 UTC
  • mto: (4634.119.1 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: john@arbash-meinel.com-20100106174615-cq1nckxhbuyemgjx
Fix bug #503886, errors setting up logging go to stderr.

The basic issue is that we were using logging to describe failures
to set up logging. However, those fail with bad error messages
rather than giving us the output we want. This was especially bad
when the failure was occuring on the server. Since 'ssh' will pass
back the stderr stream without bzr handling it at all.

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 (
238
239
            tmp1.close()
239
240
            tmp2.close()
240
241
 
 
242
    def test__open_bzr_log_uses_stderr_for_failures(self):
 
243
        # If _open_bzr_log cannot open the file, then we should write the
 
244
        # warning to stderr. Since this is normally happening before logging is
 
245
        # set up.
 
246
        self.addCleanup(setattr, sys, 'stderr', sys.stderr)
 
247
        self.addCleanup(setattr, trace, '_bzr_log_filename',
 
248
                        trace._bzr_log_filename)
 
249
        sys.stderr = StringIO()
 
250
        # Set the log file to something that cannot exist
 
251
        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
 
252
        logf = trace._open_bzr_log()
 
253
        self.assertIs(None, logf)
 
254
        self.assertContainsRe(sys.stderr.getvalue(),
 
255
                              'failed to open trace file: .*/no-dir/bzr.log')
241
256
 
242
257
class TestVerbosityLevel(TestCase):
243
258