/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3948.2.6 by Martin Pool
ProgressBarStack is deprecated
1
# Copyright (C) 2005, 2008, 2009 Canonical Ltd
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
16
17
"""Tests for the bzrlib ui
18
"""
19
20
import os
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
21
from StringIO import StringIO
1704.2.9 by Martin Pool
Make text_factory test not depend on 80-col terminal
22
import re
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
23
import sys
4017.1.1 by John Arbash Meinel
Get a pb.tick() to work after calling pb.update()
24
import time
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
25
1681.1.2 by Robert Collins
* bzrlib.ui.text.TextUIFactory now accepts a bar_type parameter which
26
import bzrlib
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
27
import bzrlib.errors as errors
3948.2.6 by Martin Pool
ProgressBarStack is deprecated
28
from bzrlib.symbol_versioning import (
29
    deprecated_in,
30
    )
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
31
from bzrlib.tests import (
2363.4.10 by Vincent Ladeuil
Complete tests.
32
    TestCase,
2294.4.4 by Vincent Ladeuil
Provide a better implementation for testing passwords.
33
    TestUIFactory,
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
34
    StringIOWrapper,
35
    )
1843.3.10 by John Arbash Meinel
ui tests were failing when output was redirected to a file. (thus blocked by the pqm)
36
from bzrlib.tests.test_progress import _TTYStringIO
2363.4.10 by Vincent Ladeuil
Complete tests.
37
from bzrlib.ui import (
38
    CLIUIFactory,
39
    SilentUIFactory,
40
    )
4110.2.15 by Martin Pool
Fix bug in showing task progress and add a test
41
from bzrlib.ui.text import (
4449.2.4 by Martin Pool
Add tests for BZR_PROGRESS_BAR
42
    NullProgressView,
4110.2.15 by Martin Pool
Fix bug in showing task progress and add a test
43
    TextProgressView,
44
    TextUIFactory,
45
    )
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
46
1681.1.2 by Robert Collins
* bzrlib.ui.text.TextUIFactory now accepts a bar_type parameter which
47
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
48
class UITests(TestCase):
49
50
    def test_silent_factory(self):
51
        ui = SilentUIFactory()
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
52
        stdout = StringIO()
53
        self.assertEqual(None,
54
                         self.apply_redirected(None, stdout, stdout,
55
                                               ui.get_password))
56
        self.assertEqual('', stdout.getvalue())
57
        self.assertEqual(None,
58
                         self.apply_redirected(None, stdout, stdout,
59
                                               ui.get_password,
60
                                               u'Hello\u1234 %(user)s',
61
                                               user=u'some\u1234'))
62
        self.assertEqual('', stdout.getvalue())
63
64
    def test_text_factory_ascii_password(self):
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
65
        ui = TestUIFactory(stdin='secret\n', stdout=StringIOWrapper(),
66
                           stderr=StringIOWrapper())
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
67
        pb = ui.nested_progress_bar()
68
        try:
69
            self.assertEqual('secret',
70
                             self.apply_redirected(ui.stdin, ui.stdout,
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
71
                                                   ui.stderr,
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
72
                                                   ui.get_password))
73
            # ': ' is appended to prompt
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
74
            self.assertEqual(': ', ui.stderr.getvalue())
75
            self.assertEqual('', ui.stdout.readline())
2363.4.3 by Vincent Ladeuil
Tidy-up tests.
76
            # stdin should be empty
2363.4.6 by Vincent Ladeuil
Fix tests around stdin emptyness.
77
            self.assertEqual('', ui.stdin.readline())
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
78
        finally:
79
            pb.finished()
80
81
    def test_text_factory_utf8_password(self):
82
        """Test an utf8 password.
83
84
        We can't predict what encoding users will have for stdin, so we force
85
        it to utf8 to test that we transport the password correctly.
86
        """
2294.4.4 by Vincent Ladeuil
Provide a better implementation for testing passwords.
87
        ui = TestUIFactory(stdin=u'baz\u1234'.encode('utf8'),
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
88
                           stdout=StringIOWrapper(),
89
                           stderr=StringIOWrapper())
90
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
91
        pb = ui.nested_progress_bar()
92
        try:
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
93
            password = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
94
                                             ui.get_password,
95
                                             u'Hello \u1234 %(user)s',
96
                                             user=u'some\u1234')
97
            # We use StringIO objects, we need to decode them
98
            self.assertEqual(u'baz\u1234', password.decode('utf8'))
99
            self.assertEqual(u'Hello \u1234 some\u1234: ',
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
100
                             ui.stderr.getvalue().decode('utf8'))
101
            # stdin and stdout should be empty
2363.4.6 by Vincent Ladeuil
Fix tests around stdin emptyness.
102
            self.assertEqual('', ui.stdin.readline())
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
103
            self.assertEqual('', ui.stdout.readline())
2294.4.1 by Vincent Ladeuil
Add a UIFactory.get_login method, fix tests.
104
        finally:
105
            pb.finished()
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
106
4449.2.4 by Martin Pool
Add tests for BZR_PROGRESS_BAR
107
    def test_progress_construction(self):
108
        """TextUIFactory constructs the right progress view.
109
        """
110
        os.environ['BZR_PROGRESS_BAR'] = 'none'
111
        self.assertIsInstance(TextUIFactory()._progress_view,
112
            NullProgressView)
113
114
        os.environ['BZR_PROGRESS_BAR'] = 'text'
115
        self.assertIsInstance(TextUIFactory()._progress_view,
116
            TextProgressView)
117
118
        os.environ['BZR_PROGRESS_BAR'] = 'text'
119
        self.assertIsInstance(TextUIFactory()._progress_view,
120
            TextProgressView)
121
122
        del os.environ['BZR_PROGRESS_BAR']
123
        self.assertIsInstance(TextUIFactory()._progress_view,
124
            TextProgressView)
125
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
126
    def test_progress_note(self):
127
        stderr = StringIO()
128
        stdout = StringIO()
3882.8.11 by Martin Pool
Choose the UIFactory class depending on the terminal capabilities
129
        ui_factory = TextUIFactory(stdin=StringIO(''),
130
            stderr=stderr,
131
            stdout=stdout)
1558.8.5 by Aaron Bentley
Pass note up the stack instead of using bzrlib.ui_factory
132
        pb = ui_factory.nested_progress_bar()
1558.8.4 by Aaron Bentley
Fixed test case for pb.note
133
        try:
4471.2.2 by Martin Pool
Deprecate ProgressTask.note
134
            result = self.applyDeprecated(deprecated_in((1, 17, 0)),
135
                pb.note,
136
                't')
1558.8.4 by Aaron Bentley
Fixed test case for pb.note
137
            self.assertEqual(None, result)
138
            self.assertEqual("t\n", stdout.getvalue())
1843.3.2 by John Arbash Meinel
Fix a ui test that depended on clearing
139
            # Since there was no update() call, there should be no clear() call
2363.4.4 by Vincent Ladeuil
More tidying-up.
140
            self.failIf(re.search(r'^\r {10,}\r$',
141
                                  stderr.getvalue()) is not None,
1843.3.2 by John Arbash Meinel
Fix a ui test that depended on clearing
142
                        'We cleared the stderr without anything to put there')
143
        finally:
144
            pb.finished()
145
146
    def test_progress_note_clears(self):
147
        stderr = StringIO()
148
        stdout = StringIO()
1843.3.10 by John Arbash Meinel
ui tests were failing when output was redirected to a file. (thus blocked by the pqm)
149
        # The PQM redirects the output to a file, so it
150
        # defaults to creating a Dots progress bar. we
151
        # need to force it to believe we are a TTY
3882.8.8 by Martin Pool
Progress and UI test cleanups
152
        ui_factory = TextUIFactory(
3882.8.11 by Martin Pool
Choose the UIFactory class depending on the terminal capabilities
153
            stdin=StringIO(''),
3882.8.4 by Martin Pool
All UI factories should support note()
154
            stdout=stdout, stderr=stderr)
1843.3.2 by John Arbash Meinel
Fix a ui test that depended on clearing
155
        pb = ui_factory.nested_progress_bar()
156
        try:
157
            # Create a progress update that isn't throttled
158
            pb.update('x', 1, 1)
4471.2.2 by Martin Pool
Deprecate ProgressTask.note
159
            result = self.applyDeprecated(deprecated_in((1, 17, 0)),
160
                pb.note, 't')
1843.3.2 by John Arbash Meinel
Fix a ui test that depended on clearing
161
            self.assertEqual(None, result)
162
            self.assertEqual("t\n", stdout.getvalue())
1558.8.4 by Aaron Bentley
Fixed test case for pb.note
163
            # the exact contents will depend on the terminal width and we don't
164
            # care about that right now - but you're probably running it on at
165
            # least a 10-character wide terminal :)
1843.3.2 by John Arbash Meinel
Fix a ui test that depended on clearing
166
            self.assertContainsRe(stderr.getvalue(), r'\r {10,}\r$')
1558.8.4 by Aaron Bentley
Fixed test case for pb.note
167
        finally:
1558.8.5 by Aaron Bentley
Pass note up the stack instead of using bzrlib.ui_factory
168
            pb.finished()
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
169
170
    def test_progress_nested(self):
171
        # test factory based nested and popping.
3882.8.11 by Martin Pool
Choose the UIFactory class depending on the terminal capabilities
172
        ui = TextUIFactory(None, None, None)
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
173
        pb1 = ui.nested_progress_bar()
174
        pb2 = ui.nested_progress_bar()
3948.2.2 by Martin Pool
Corrections to finishing progress bars
175
        # You do get a warning if the outermost progress bar wasn't finished
176
        # first - it's not clear if this is really useful or if it should just
177
        # become orphaned -- mbp 20090120
3882.8.12 by Martin Pool
Give a warning, not an error, if a progress bar is not finished in order
178
        warnings, _ = self.callCatchWarnings(pb1.finished)
3948.2.2 by Martin Pool
Corrections to finishing progress bars
179
        if len(warnings) != 1:
180
            self.fail("unexpected warnings: %r" % (warnings,))
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
181
        pb2.finished()
182
        pb1.finished()
183
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
184
    def assert_get_bool_acceptance_of_user_input(self, factory):
2363.4.4 by Vincent Ladeuil
More tidying-up.
185
        factory.stdin = StringIO("y\nyes with garbage\n"
186
                                 "yes\nn\nnot an answer\n"
187
                                 "no\nfoo\n")
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
188
        factory.stdout = StringIO()
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
189
        factory.stderr = StringIO()
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
190
        # there is no output from the base factory
191
        self.assertEqual(True, factory.get_boolean(""))
192
        self.assertEqual(True, factory.get_boolean(""))
193
        self.assertEqual(False, factory.get_boolean(""))
194
        self.assertEqual(False, factory.get_boolean(""))
195
        self.assertEqual("foo\n", factory.stdin.read())
2363.4.4 by Vincent Ladeuil
More tidying-up.
196
        # stdin should be empty
2363.4.6 by Vincent Ladeuil
Fix tests around stdin emptyness.
197
        self.assertEqual('', factory.stdin.readline())
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
198
199
    def test_silent_ui_getbool(self):
2363.4.10 by Vincent Ladeuil
Complete tests.
200
        factory = SilentUIFactory()
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
201
        self.assert_get_bool_acceptance_of_user_input(factory)
202
203
    def test_silent_factory_prompts_silently(self):
2363.4.10 by Vincent Ladeuil
Complete tests.
204
        factory = SilentUIFactory()
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
205
        stdout = StringIO()
206
        factory.stdin = StringIO("y\n")
2363.4.4 by Vincent Ladeuil
More tidying-up.
207
        self.assertEqual(True,
208
                         self.apply_redirected(None, stdout, stdout,
209
                                               factory.get_boolean, "foo"))
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
210
        self.assertEqual("", stdout.getvalue())
2363.4.4 by Vincent Ladeuil
More tidying-up.
211
        # stdin should be empty
2363.4.6 by Vincent Ladeuil
Fix tests around stdin emptyness.
212
        self.assertEqual('', factory.stdin.readline())
2363.4.4 by Vincent Ladeuil
More tidying-up.
213
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
214
    def test_text_ui_getbool(self):
3882.8.11 by Martin Pool
Choose the UIFactory class depending on the terminal capabilities
215
        factory = TextUIFactory(None, None, None)
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
216
        self.assert_get_bool_acceptance_of_user_input(factory)
217
4300.3.1 by Martin Pool
Fix string expansion in TextUIFactory.prompt
218
    def test_text_factory_prompt(self):
219
        # see <https://launchpad.net/bugs/365891>
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
220
        factory = TextUIFactory(None, StringIO(), StringIO(), StringIO())
4300.3.1 by Martin Pool
Fix string expansion in TextUIFactory.prompt
221
        factory.prompt('foo %2e')
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
222
        self.assertEqual('', factory.stdout.getvalue())
223
        self.assertEqual('foo %2e', factory.stderr.getvalue())
4300.3.1 by Martin Pool
Fix string expansion in TextUIFactory.prompt
224
1687.1.4 by Robert Collins
Add bzrlib.ui.ui_factory.get_boolean().
225
    def test_text_factory_prompts_and_clears(self):
226
        # a get_boolean call should clear the pb before prompting
3882.8.10 by Martin Pool
Fix up test_ui for new progress bars
227
        out = _TTYStringIO()
3882.8.11 by Martin Pool
Choose the UIFactory class depending on the terminal capabilities
228
        factory = TextUIFactory(stdin=StringIO("yada\ny\n"), stdout=out, stderr=out)
3882.8.10 by Martin Pool
Fix up test_ui for new progress bars
229
        pb = factory.nested_progress_bar()
230
        pb.show_bar = False
231
        pb.show_spinner = False
232
        pb.show_count = False
233
        pb.update("foo", 0, 1)
2363.4.4 by Vincent Ladeuil
More tidying-up.
234
        self.assertEqual(True,
235
                         self.apply_redirected(None, factory.stdout,
236
                                               factory.stdout,
237
                                               factory.get_boolean,
238
                                               "what do you want"))
3882.8.10 by Martin Pool
Fix up test_ui for new progress bars
239
        output = out.getvalue()
240
        self.assertContainsRe(factory.stdout.getvalue(),
241
            "foo *\r\r  *\r*")
242
        self.assertContainsRe(factory.stdout.getvalue(),
243
            r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
244
        # stdin should have been totally consumed
2363.4.6 by Vincent Ladeuil
Fix tests around stdin emptyness.
245
        self.assertEqual('', factory.stdin.readline())
4017.1.1 by John Arbash Meinel
Get a pb.tick() to work after calling pb.update()
246
247
    def test_text_tick_after_update(self):
248
        ui_factory = TextUIFactory(stdout=StringIO(), stderr=StringIO())
249
        pb = ui_factory.nested_progress_bar()
250
        try:
251
            pb.update('task', 0, 3)
252
            # Reset the clock, so that it actually tries to repaint itself
253
            ui_factory._progress_view._last_repaint = time.time() - 1.0
254
            pb.tick()
255
        finally:
256
            pb.finished()
4110.2.15 by Martin Pool
Fix bug in showing task progress and add a test
257
4222.2.1 by Jelmer Vernooij
Add get_username() call to the UIFactory.
258
    def test_silent_ui_getusername(self):
259
        factory = SilentUIFactory()
260
        factory.stdin = StringIO("someuser\n\n")
261
        factory.stdout = StringIO()
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
262
        factory.stderr = StringIO()
263
        self.assertEquals(None,
4222.2.1 by Jelmer Vernooij
Add get_username() call to the UIFactory.
264
            factory.get_username(u'Hello\u1234 %(host)s', host=u'some\u1234'))
265
        self.assertEquals("", factory.stdout.getvalue())
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
266
        self.assertEquals("", factory.stderr.getvalue())
4222.2.1 by Jelmer Vernooij
Add get_username() call to the UIFactory.
267
        self.assertEquals("someuser\n\n", factory.stdin.getvalue())
268
269
    def test_text_ui_getusername(self):
270
        factory = TextUIFactory(None, None, None)
271
        factory.stdin = StringIO("someuser\n\n")
272
        factory.stdout = StringIO()
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
273
        factory.stderr = StringIO()
4222.2.6 by Jelmer Vernooij
Remove use of NotATerminal.
274
        factory.stdout.encoding = "utf8"
4222.2.1 by Jelmer Vernooij
Add get_username() call to the UIFactory.
275
        # there is no output from the base factory
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
276
        self.assertEqual("someuser",
277
                         factory.get_username('Hello %(host)s', host='some'))
278
        self.assertEquals("Hello some: ", factory.stderr.getvalue())
279
        self.assertEquals('', factory.stdout.getvalue())
4222.2.1 by Jelmer Vernooij
Add get_username() call to the UIFactory.
280
        self.assertEqual("", factory.get_username("Gebruiker"))
281
        # stdin should be empty
282
        self.assertEqual('', factory.stdin.readline())
283
4222.2.2 by Jelmer Vernooij
Review from vila: Deal with UTF8 strings in prompts, fix typo.
284
    def test_text_ui_getusername_utf8(self):
4222.2.3 by Jelmer Vernooij
Also check for unicode usernames.
285
        ui = TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
286
                           stdout=StringIOWrapper(), stderr=StringIOWrapper())
287
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
4222.2.3 by Jelmer Vernooij
Also check for unicode usernames.
288
        pb = ui.nested_progress_bar()
289
        try:
290
            # there is no output from the base factory
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
291
            username = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
4222.2.12 by Jelmer Vernooij
Redirect to fix utf8 test with LC_ALL=C.
292
                ui.get_username, u'Hello\u1234 %(host)s', host=u'some\u1234')
4222.2.8 by Jelmer Vernooij
Fix copy-n-paste error.
293
            self.assertEquals(u"someuser\u1234", username.decode('utf8'))
4368.3.1 by Vincent Ladeuil
Use stderr for UI prompt to address bug #376582.
294
            self.assertEquals(u"Hello\u1234 some\u1234: ",
295
                              ui.stderr.getvalue().decode("utf8"))
296
            self.assertEquals('', ui.stdout.getvalue())
4222.2.3 by Jelmer Vernooij
Also check for unicode usernames.
297
        finally:
298
            pb.finished()
4222.2.2 by Jelmer Vernooij
Review from vila: Deal with UTF8 strings in prompts, fix typo.
299
4110.2.15 by Martin Pool
Fix bug in showing task progress and add a test
300
301
class TestTextProgressView(TestCase):
302
    """Tests for text display of progress bars.
303
    """
304
    # XXX: These might be a bit easier to write if the rendering and
305
    # state-maintaining parts of TextProgressView were more separate, and if
306
    # the progress task called back directly to its own view not to the ui
307
    # factory. -- mbp 20090312
4110.2.16 by Martin Pool
Refactor TextProgressView a bit and add another test
308
    
309
    def _make_factory(self):
4110.2.15 by Martin Pool
Fix bug in showing task progress and add a test
310
        out = StringIO()
311
        uif = TextUIFactory(stderr=out)
312
        uif._progress_view._width = 80
4110.2.16 by Martin Pool
Refactor TextProgressView a bit and add another test
313
        return out, uif
314
315
    def test_render_progress_easy(self):
316
        """Just one task and one quarter done"""
317
        out, uif = self._make_factory()
4110.2.15 by Martin Pool
Fix bug in showing task progress and add a test
318
        task = uif.nested_progress_bar()
319
        task.update('reticulating splines', 5, 20)
320
        self.assertEqual(
321
'\r[####/               ] reticulating splines 5/20                               \r'
322
            , out.getvalue())
4110.2.16 by Martin Pool
Refactor TextProgressView a bit and add another test
323
4110.2.17 by Martin Pool
If one ProgressTask has no count, it passes through that of its child
324
    def test_render_progress_nested(self):
325
        """Tasks proportionally contribute to overall progress"""
4110.2.16 by Martin Pool
Refactor TextProgressView a bit and add another test
326
        out, uif = self._make_factory()
327
        task = uif.nested_progress_bar()
328
        task.update('reticulating splines', 0, 2)
329
        task2 = uif.nested_progress_bar()
330
        task2.update('stage2', 1, 2)
331
        # so we're in the first half of the main task, and half way through
332
        # that
333
        self.assertEqual(
4110.2.18 by Martin Pool
Progress bars always repaint when task structure is changed
334
r'[####\               ] reticulating splines:stage2 1/2'
4110.2.16 by Martin Pool
Refactor TextProgressView a bit and add another test
335
            , uif._progress_view._render_line())
4110.2.17 by Martin Pool
If one ProgressTask has no count, it passes through that of its child
336
        # if the nested task is complete, then we're all the way through the
337
        # first half of the overall work
338
        task2.update('stage2', 2, 2)
339
        self.assertEqual(
4110.2.18 by Martin Pool
Progress bars always repaint when task structure is changed
340
r'[#########|          ] reticulating splines:stage2 2/2'
4110.2.17 by Martin Pool
If one ProgressTask has no count, it passes through that of its child
341
            , uif._progress_view._render_line())
342
343
    def test_render_progress_sub_nested(self):
344
        """Intermediate tasks don't mess up calculation."""
345
        out, uif = self._make_factory()
346
        task_a = uif.nested_progress_bar()
347
        task_a.update('a', 0, 2)
348
        task_b = uif.nested_progress_bar()
349
        task_b.update('b')
350
        task_c = uif.nested_progress_bar()
351
        task_c.update('c', 1, 2)
352
        # the top-level task is in its first half; the middle one has no
353
        # progress indication, just a label; and the bottom one is half done,
354
        # so the overall fraction is 1/4
355
        self.assertEqual(
4110.2.18 by Martin Pool
Progress bars always repaint when task structure is changed
356
            r'[####|               ] a:b:c 1/2'
4110.2.17 by Martin Pool
If one ProgressTask has no count, it passes through that of its child
357
            , uif._progress_view._render_line())
358