~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: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
26
26
import tempfile
27
27
 
28
28
from bzrlib import (
 
29
    debug,
29
30
    errors,
30
31
    trace,
31
32
    )
32
 
from bzrlib.tests import TestCaseInTempDir, TestCase
 
33
from bzrlib.tests import features, TestCaseInTempDir, TestCase
33
34
from bzrlib.trace import (
34
35
    mutter, mutter_callsite, report_exception,
35
36
    set_verbosity_level, get_verbosity_level, is_quiet, is_verbose, be_quiet,
81
82
            pass
82
83
        msg = _format_exception()
83
84
        self.assertEquals(msg,
84
 
            "bzr: out of memory\n")
 
85
            "bzr: out of memory\nUse -Dmem_dump to dump memory to a file.\n")
 
86
 
 
87
    def test_format_mem_dump(self):
 
88
        self.requireFeature(features.meliae)
 
89
        debug.debug_flags.add('mem_dump')
 
90
        try:
 
91
            raise MemoryError()
 
92
        except MemoryError:
 
93
            pass
 
94
        msg = _format_exception()
 
95
        self.assertStartsWith(msg,
 
96
            "bzr: out of memory\nMemory dumped to ")
85
97
 
86
98
    def test_format_os_error(self):
87
99
        try:
104
116
        self.assertContainsRe(msg,
105
117
            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
106
118
 
 
119
    def test_format_pywintypes_error(self):
 
120
        self.requireFeature(features.pywintypes)
 
121
        import pywintypes, win32file
 
122
        try:
 
123
            win32file.RemoveDirectory('nosuchfile22222')
 
124
        except pywintypes.error:
 
125
            pass
 
126
        msg = _format_exception()
 
127
        # GZ 2010-05-03: Formatting for pywintypes.error is basic, a 3-tuple
 
128
        #                with errno, function name, and locale error message
 
129
        self.assertContainsRe(msg,
 
130
            r"^bzr: ERROR: \(2, 'RemoveDirectory[AW]?', .*\)")
 
131
 
107
132
    def test_format_unicode_error(self):
108
133
        try:
109
134
            raise errors.BzrCommandError(u'argument foo\xb5 does not exist')
276
301
        # set up.
277
302
        self.overrideAttr(sys, 'stderr', StringIO())
278
303
        # 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
 
        os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
 
304
        self.overrideEnv('BZR_LOG', os.getcwd() + '/no-dir/bzr.log')
282
305
        self.overrideAttr(trace, '_bzr_log_filename')
283
306
        logf = trace._open_bzr_log()
284
307
        self.assertIs(None, logf)
320
343
        _rollover_trace_maybe(temp_log_name)
321
344
        # should have been rolled over
322
345
        self.assertFalse(os.access(temp_log_name, os.R_OK))
 
346
 
 
347
 
 
348
class TestTraceConfiguration(TestCaseInTempDir):
 
349
 
 
350
    def test_default_config(self):
 
351
        config = trace.DefaultConfig()
 
352
        self.overrideAttr(trace, "_bzr_log_filename", None)
 
353
        trace._bzr_log_filename = None
 
354
        expected_filename = trace._get_bzr_log_filename()
 
355
        self.assertEqual(None, trace._bzr_log_filename)
 
356
        config.__enter__()
 
357
        try:
 
358
            # Should have entered and setup a default filename.
 
359
            self.assertEqual(expected_filename, trace._bzr_log_filename)
 
360
        finally:
 
361
            config.__exit__(None, None, None)
 
362
            # Should have exited and cleaned up.
 
363
            self.assertEqual(None, trace._bzr_log_filename)