/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 breezy/tests/test_progress.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
 
from cStringIO import StringIO
19
 
 
20
 
from bzrlib import (
21
 
    tests,
22
 
    )
23
 
from bzrlib.progress import (
 
17
import codecs
 
18
import io
 
19
 
 
20
from ..progress import (
24
21
    ProgressTask,
25
22
    )
26
 
from bzrlib.ui.text import (
 
23
from ..ui.text import (
27
24
    TextProgressView,
28
25
    )
29
26
 
 
27
from .. import (
 
28
    tests,
 
29
    )
 
30
from . import (
 
31
    ui_testing,
 
32
    )
 
33
 
30
34
 
31
35
class TestTextProgressView(tests.TestCase):
32
36
    """Tests for text display of progress bars.
44
48
        return view
45
49
 
46
50
    def make_view(self):
47
 
        out = StringIO()
 
51
        out = ui_testing.StringIOWithEncoding()
48
52
        return out, self.make_view_only(out)
49
53
 
50
54
    def make_task(self, parent_task, view, msg, curr, total):
63
67
        task = self.make_task(None, view, 'reticulating splines', 5, 20)
64
68
        view.show_progress(task)
65
69
        self.assertEqual(
66
 
'\r/ reticulating splines 5/20                                                    \r'
67
 
            , out.getvalue())
 
70
            '\r/ reticulating splines 5/20                                                    \r', out.getvalue())
68
71
        view.clear()
69
72
        self.assertEqual(
70
 
'\r/ reticulating splines 5/20                                                    \r'
71
 
            + '\r' + 79 * ' ' + '\r',
 
73
            '\r/ reticulating splines 5/20                                                    \r' +
 
74
            '\r' + 79 * ' ' + '\r',
72
75
            out.getvalue())
73
76
 
74
77
    def test_render_progress_no_bar(self):
78
81
        task = self.make_task(None, view, 'reticulating splines', 5, 20)
79
82
        view.show_progress(task)
80
83
        self.assertEqual(
81
 
'\r/ reticulating splines 5/20                                                    \r'
82
 
            , out.getvalue())
 
84
            '\r/ reticulating splines 5/20                                                    \r', out.getvalue())
83
85
 
84
86
    def test_render_progress_easy(self):
85
87
        """Just one task and one quarter done"""
88
90
        task = self.make_task(None, view, 'reticulating splines', 5, 20)
89
91
        view.show_progress(task)
90
92
        self.assertEqual(
91
 
'\r[####/               ] reticulating splines 5/20                               \r'
92
 
            , out.getvalue())
 
93
            '\r[####/               ] reticulating splines 5/20                               \r', out.getvalue())
93
94
 
94
95
    def test_render_progress_nested(self):
95
96
        """Tasks proportionally contribute to overall progress"""
101
102
        # so we're in the first half of the main task, and half way through
102
103
        # that
103
104
        self.assertEqual(
104
 
'[####-               ] reticulating splines:stage2 1/2                         '
105
 
            , view._render_line())
 
105
            '[####-               ] reticulating splines:stage2 1/2                         ', view._render_line())
106
106
        # if the nested task is complete, then we're all the way through the
107
107
        # first half of the overall work
108
108
        task2.update('stage2', 2, 2)
109
109
        self.assertEqual(
110
 
'[#########\          ] reticulating splines:stage2 2/2                         '
111
 
            , view._render_line())
 
110
            '[#########\\          ] reticulating splines:stage2 2/2                         ', view._render_line())
112
111
 
113
112
    def test_render_progress_sub_nested(self):
114
113
        """Intermediate tasks don't mess up calculation."""
124
123
        # progress indication, just a label; and the bottom one is half done,
125
124
        # so the overall fraction is 1/4
126
125
        self.assertEqual(
127
 
'[####|               ] a:b:c 1/2                                               '
128
 
            , view._render_line())
 
126
            '[####|               ] a:b:c 1/2                                               ', view._render_line())
129
127
 
130
128
    def test_render_truncated(self):
131
129
        # when the bar is too long for the terminal, we prefer not to truncate
136
134
        task_a.update('start_' + 'a' * 200 + '_end', 2000, 5000)
137
135
        line = view._render_line()
138
136
        self.assertEqual(
139
 
'- start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000',
140
 
           line) 
 
137
            '- start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000',
 
138
            line)
141
139
        self.assertEqual(len(line), 79)
142
140
 
143
 
 
144
141
    def test_render_with_activity(self):
145
142
        # if the progress view has activity, it's shown before the spinner
146
143
        out, view = self.make_view()
148
145
        view._last_transport_msg = '   123kB   100kB/s '
149
146
        line = view._render_line()
150
147
        self.assertEqual(
151
 
'   123kB   100kB/s /                                                           ',
152
 
           line) 
 
148
            '   123kB   100kB/s /                                                           ',
 
149
            line)
153
150
        self.assertEqual(len(line), 79)
154
151
 
155
152
        task_a.update('start_' + 'a' * 200 + '_end', 2000, 5000)
156
153
        view._last_transport_msg = '   123kB   100kB/s '
157
154
        line = view._render_line()
158
155
        self.assertEqual(
159
 
'   123kB   100kB/s \\ start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000',
160
 
           line) 
 
156
            '   123kB   100kB/s \\ start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000',
 
157
            line)
161
158
        self.assertEqual(len(line), 79)
162
159
 
163
160
    def test_render_progress_unicode_enc_utf8(self):
164
 
        out = tests.StringIOWrapper()
 
161
        out = ui_testing.StringIOWithEncoding()
165
162
        out.encoding = "utf-8"
166
163
        view = self.make_view_only(out, 20)
167
164
        task = self.make_task(None, view, u"\xa7", 0, 1)
168
165
        view.show_progress(task)
169
 
        self.assertEqual('\r/ \xc2\xa7 0/1            \r',
170
 
            out.getvalue())
 
166
        self.assertEqual(u'\r/ \xa7 0/1            \r', out.getvalue())
171
167
 
172
168
    def test_render_progress_unicode_enc_missing(self):
173
 
        out = StringIO()
 
169
        out = codecs.getwriter("ascii")(io.BytesIO())
174
170
        self.assertRaises(AttributeError, getattr, out, "encoding")
175
171
        view = self.make_view_only(out, 20)
176
172
        task = self.make_task(None, view, u"\xa7", 0, 1)
177
173
        view.show_progress(task)
178
 
        self.assertEqual('\r/ ? 0/1             \r',
179
 
            out.getvalue())
 
174
        self.assertEqual(b'\r/ ? 0/1             \r', out.getvalue())
180
175
 
181
176
    def test_render_progress_unicode_enc_none(self):
182
 
        out = tests.StringIOWrapper()
 
177
        out = ui_testing.StringIOWithEncoding()
183
178
        out.encoding = None
184
179
        view = self.make_view_only(out, 20)
185
180
        task = self.make_task(None, view, u"\xa7", 0, 1)
186
181
        view.show_progress(task)
187
 
        self.assertEqual('\r/ ? 0/1             \r',
188
 
            out.getvalue())
 
182
        self.assertEqual(u'\r/ ? 0/1             \r', out.getvalue())