~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_library_state.py

  • Committer: Robert Collins
  • Date: 2010-06-26 01:07:16 UTC
  • mto: This revision was merged to the branch mainline in revision 5324.
  • Revision ID: robertc@robertcollins.net-20100626010716-jowzrldm4ntsaki2
Make bzrlib startup use a trace context manager.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    tests,
23
23
    ui as _mod_ui
24
24
    )
 
25
from bzrlib.tests import fixtures
25
26
 
26
27
 
27
28
# TODO: once sufficiently cleaned up this should be able to be TestCase.
29
30
 
30
31
    def test_ui_is_used(self):
31
32
        ui = _mod_ui.SilentUIFactory()
32
 
        state = library_state.BzrLibraryState(ui=ui)
 
33
        state = library_state.BzrLibraryState(
 
34
            ui=ui, trace=fixtures.RecordingContextManager())
33
35
        orig_ui = _mod_ui.ui_factory
34
36
        state.__enter__()
35
37
        try:
37
39
        finally:
38
40
            state.__exit__(None, None, None)
39
41
            self.assertEqual(orig_ui, _mod_ui.ui_factory)
 
42
 
 
43
    def test_trace_context(self):
 
44
        tracer = fixtures.RecordingContextManager()
 
45
        ui = _mod_ui.SilentUIFactory()
 
46
        state = library_state.BzrLibraryState(ui=ui, trace=tracer)
 
47
        state.__enter__()
 
48
        try:
 
49
            self.assertEqual(['__enter__'], tracer._calls)
 
50
        finally:
 
51
            state.__exit__(None, None, None)
 
52
            self.assertEqual(['__enter__', '__exit__'], tracer._calls)