~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Martin Pool
  • Date: 2006-03-10 06:29:53 UTC
  • mfrom: (1608 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060310062953-bc1c7ade75c89a7a
[merge] bzr.dev; pycurl not updated for readv yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from StringIO import StringIO
22
22
import sys
23
23
 
24
 
from bzrlib.progress import TTYProgressBar
 
24
 
 
25
import bzrlib.errors as errors
 
26
from bzrlib.progress import TTYProgressBar, ProgressBarStack
25
27
from bzrlib.tests import TestCase
26
28
from bzrlib.ui import SilentUIFactory
27
29
from bzrlib.ui.text import TextUIFactory
31
33
    def test_silent_factory(self):
32
34
 
33
35
        ui = SilentUIFactory()
34
 
        pb = ui.progress_bar()
35
 
        # TODO: Test that there is no output from SilentUIFactory
36
 
 
37
 
        self.assertEquals(ui.get_password(), None)
38
 
        self.assertEquals(ui.get_password(u'Hello There \u1234 %(user)s',
39
 
                                          user=u'some\u1234')
40
 
                         , None)
 
36
        pb = ui.nested_progress_bar()
 
37
        try:
 
38
            # TODO: Test that there is no output from SilentUIFactory
 
39
    
 
40
            self.assertEquals(ui.get_password(), None)
 
41
            self.assertEquals(ui.get_password(u'Hello There \u1234 %(user)s',
 
42
                                              user=u'some\u1234')
 
43
                             , None)
 
44
        finally:
 
45
            pb.finished()
41
46
 
42
47
    def test_text_factory(self):
43
48
        ui = TextUIFactory()
44
 
        pb = ui.progress_bar()
 
49
        pb = ui.nested_progress_bar()
 
50
        pb.finished()
45
51
        # TODO: Test the output from TextUIFactory, perhaps by overriding sys.stdout
46
52
 
47
53
        # Unfortunately we can't actually test the ui.get_password() because 
56
62
    def test_progress_note(self):
57
63
        stderr = StringIO()
58
64
        stdout = StringIO()
59
 
        ui = TextUIFactory()
60
65
        pb = TTYProgressBar(to_file=stderr, to_messages_file=stdout)
61
66
        result = pb.note('t')
62
67
        self.assertEqual(None, result)
65
70
        # care about that right now - but you're probably running it on at
66
71
        # least a 10-character wide terminal :)
67
72
        self.assertContainsRe(stderr.getvalue(), r'^\r {10,}\r$')
 
73
 
 
74
    def test_progress_nested(self):
 
75
        # test factory based nested and popping.
 
76
        ui = TextUIFactory()
 
77
        pb1 = ui.nested_progress_bar()
 
78
        pb2 = ui.nested_progress_bar()
 
79
        self.assertRaises(errors.MissingProgressBarFinish, pb1.finished)
 
80
        pb2.finished()
 
81
        pb1.finished()
 
82
 
 
83
    def test_progress_stack(self):
 
84
        # test the progress bar stack which the default text factory 
 
85
        # uses.
 
86
        stderr = StringIO()
 
87
        stdout = StringIO()
 
88
        # make a stack, which accepts parameters like a pb.
 
89
        stack = ProgressBarStack(to_file=stderr, to_messages_file=stdout)
 
90
        # but is not one
 
91
        self.assertFalse(getattr(stack, 'note', False))
 
92
        pb1 = stack.get_nested()
 
93
        pb2 = stack.get_nested()
 
94
        self.assertRaises(errors.MissingProgressBarFinish, pb1.finished)
 
95
        pb2.finished()
 
96
        pb1.finished()
 
97
        # the text ui factory never actually removes the stack once its setup.
 
98
        # we need to be able to nest again correctly from here.
 
99
        pb1 = stack.get_nested()
 
100
        pb2 = stack.get_nested()
 
101
        self.assertRaises(errors.MissingProgressBarFinish, pb1.finished)
 
102
        pb2.finished()
 
103
        pb1.finished()