/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    errors,
30
30
    trace,
31
31
    )
32
 
from bzrlib.tests import TestCaseInTempDir, TestCase
 
32
from bzrlib.tests import features, TestCaseInTempDir, TestCase
33
33
from bzrlib.trace import (
34
34
    mutter, mutter_callsite, report_exception,
35
35
    set_verbosity_level, get_verbosity_level, is_quiet, is_verbose, be_quiet,
104
104
        self.assertContainsRe(msg,
105
105
            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
106
106
 
 
107
    def test_format_pywintypes_error(self):
 
108
        self.requireFeature(features.pywintypes)
 
109
        import pywintypes, win32file
 
110
        try:
 
111
            win32file.RemoveDirectory('nosuchfile22222')
 
112
        except pywintypes.error:
 
113
            pass
 
114
        msg = _format_exception()
 
115
        # GZ 2010-05-03: Formatting for pywintypes.error is basic, a 3-tuple
 
116
        #                with errno, function name, and locale error message
 
117
        self.assertContainsRe(msg,
 
118
            r"^bzr: ERROR: \(2, 'RemoveDirectory[AW]?', .*\)")
 
119
 
107
120
    def test_format_unicode_error(self):
108
121
        try:
109
122
            raise errors.BzrCommandError(u'argument foo\xb5 does not exist')
320
333
        _rollover_trace_maybe(temp_log_name)
321
334
        # should have been rolled over
322
335
        self.assertFalse(os.access(temp_log_name, os.R_OK))
 
336
 
 
337
 
 
338
class TestTraceConfiguration(TestCaseInTempDir):
 
339
 
 
340
    def test_default_config(self):
 
341
        config = trace.DefaultConfig()
 
342
        self.overrideAttr(trace, "_bzr_log_filename", None)
 
343
        trace._bzr_log_filename = None
 
344
        expected_filename = trace._get_bzr_log_filename()
 
345
        self.assertEqual(None, trace._bzr_log_filename)
 
346
        config.__enter__()
 
347
        try:
 
348
            # Should have entered and setup a default filename.
 
349
            self.assertEqual(expected_filename, trace._bzr_log_filename)
 
350
        finally:
 
351
            config.__exit__(None, None, None)
 
352
            # Should have exited and cleaned up.
 
353
            self.assertEqual(None, trace._bzr_log_filename)