/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_ui.py

  • Committer: Martin Pool
  • Date: 2010-09-14 04:13:48 UTC
  • mto: This revision was merged to the branch mainline in revision 5423.
  • Revision ID: mbp@sourcefrog.net-20100914041348-sf8atjm5smvmeprs
Delete deprecated _BaseProgressBar

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from StringIO import StringIO
25
25
 
26
26
from bzrlib import (
 
27
    config,
27
28
    errors,
28
29
    remote,
29
30
    repository,
33
34
from bzrlib.symbol_versioning import (
34
35
    deprecated_in,
35
36
    )
36
 
from bzrlib.tests import test_progress
 
37
from bzrlib.tests import (
 
38
    fixtures,
 
39
    test_progress,
 
40
    )
37
41
from bzrlib.ui import text as _mod_ui_text
 
42
from bzrlib.ui.testsupport import (
 
43
    CapturingUIFactory,
 
44
    )
 
45
 
 
46
 
 
47
class TestUIConfiguration(tests.TestCaseWithTransport):
 
48
 
 
49
    def test_output_encoding_configuration(self):
 
50
        enc = fixtures.generate_unicode_encodings().next()
 
51
        config.GlobalConfig().set_user_option('output_encoding',
 
52
            enc)
 
53
        ui = tests.TestUIFactory(stdin=None,
 
54
            stdout=tests.StringIOWrapper(),
 
55
            stderr=tests.StringIOWrapper())
 
56
        os = ui.make_output_stream()
 
57
        self.assertEquals(os.encoding, enc)
38
58
 
39
59
 
40
60
class TestTextUIFactory(tests.TestCase):
83
103
        finally:
84
104
            pb.finished()
85
105
 
86
 
    def test_progress_note(self):
87
 
        stderr = tests.StringIOWrapper()
88
 
        stdout = tests.StringIOWrapper()
89
 
        ui_factory = _mod_ui_text.TextUIFactory(stdin=tests.StringIOWrapper(''),
90
 
                                                stderr=stderr,
91
 
                                                stdout=stdout)
92
 
        pb = ui_factory.nested_progress_bar()
93
 
        try:
94
 
            result = self.applyDeprecated(deprecated_in((2, 1, 0)),
95
 
                pb.note,
96
 
                't')
97
 
            self.assertEqual(None, result)
98
 
            self.assertEqual("t\n", stdout.getvalue())
99
 
            # Since there was no update() call, there should be no clear() call
100
 
            self.failIf(re.search(r'^\r {10,}\r$',
101
 
                                  stderr.getvalue()) is not None,
102
 
                        'We cleared the stderr without anything to put there')
103
 
        finally:
104
 
            pb.finished()
105
 
 
106
 
    def test_progress_note_clears(self):
107
 
        stderr = test_progress._TTYStringIO()
108
 
        stdout = test_progress._TTYStringIO()
109
 
        # so that we get a TextProgressBar
110
 
        os.environ['TERM'] = 'xterm'
111
 
        ui_factory = _mod_ui_text.TextUIFactory(
112
 
            stdin=tests.StringIOWrapper(''),
113
 
            stdout=stdout, stderr=stderr)
114
 
        self.assertIsInstance(ui_factory._progress_view,
115
 
                              _mod_ui_text.TextProgressView)
116
 
        pb = ui_factory.nested_progress_bar()
117
 
        try:
118
 
            # Create a progress update that isn't throttled
119
 
            pb.update('x', 1, 1)
120
 
            result = self.applyDeprecated(deprecated_in((2, 1, 0)),
121
 
                pb.note, 't')
122
 
            self.assertEqual(None, result)
123
 
            self.assertEqual("t\n", stdout.getvalue())
124
 
            # the exact contents will depend on the terminal width and we don't
125
 
            # care about that right now - but you're probably running it on at
126
 
            # least a 10-character wide terminal :)
127
 
            self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$')
128
 
        finally:
129
 
            pb.finished()
130
 
 
131
106
    def test_text_ui_get_boolean(self):
132
107
        stdin = tests.StringIOWrapper("y\n" # True
133
108
                                      "n\n" # False
176
151
        factory = _mod_ui_text.TextUIFactory(
177
152
            stdin=tests.StringIOWrapper("yada\ny\n"),
178
153
            stdout=out, stderr=out)
 
154
        factory._avail_width = lambda: 79
179
155
        pb = factory.nested_progress_bar()
180
156
        pb.show_bar = False
181
157
        pb.show_spinner = False
187
163
                                               factory.get_boolean,
188
164
                                               "what do you want"))
189
165
        output = out.getvalue()
190
 
        self.assertContainsRe(factory.stdout.getvalue(),
191
 
            "foo *\r\r  *\r*")
192
 
        self.assertContainsRe(factory.stdout.getvalue(),
 
166
        self.assertContainsRe(output,
 
167
            "| foo *\r\r  *\r*")
 
168
        self.assertContainsRe(output,
193
169
            r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
194
170
        # stdin should have been totally consumed
195
171
        self.assertEqual('', factory.stdin.readline())
385
361
 
386
362
    def test_test_ui_factory_progress(self):
387
363
        # there's no output; we just want to make sure this doesn't crash -
388
 
        # see https://bugs.edge.launchpad.net/bzr/+bug/408201
 
364
        # see https://bugs.launchpad.net/bzr/+bug/408201
389
365
        ui = tests.TestUIFactory()
390
366
        pb = ui.nested_progress_bar()
391
367
        pb.update('hello')
459
435
        self.assertIsNone('0', av)
460
436
        self.assertIsNone('on', av)
461
437
        self.assertIsNone('off', av)
 
438
 
 
439
 
 
440
class TestCapturingUI(tests.TestCase):
 
441
    """Test test-oriented UIFactory that records progress updates"""
 
442
 
 
443
    def test_nested_ignore_depth_beyond_one(self):
 
444
        # we only want to capture the first level out progress, not
 
445
        # want sub-components might do. So we have nested bars ignored.
 
446
        factory = CapturingUIFactory()
 
447
        pb1 = factory.nested_progress_bar()
 
448
        pb1.update('foo', 0, 1)
 
449
        pb2 = factory.nested_progress_bar()
 
450
        pb2.update('foo', 0, 1)
 
451
        pb2.finished()
 
452
        pb1.finished()
 
453
        self.assertEqual([("update", 0, 1, 'foo')], factory._calls)