~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

(mbp) Refuse to build with pyrex 0.9.4*

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