/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test_progress.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

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):
161
165
        self.assertEqual(len(line), 79)
162
166
 
163
167
    def test_render_progress_unicode_enc_utf8(self):
164
 
        out = tests.StringIOWrapper()
 
168
        out = ui_testing.StringIOWithEncoding()
165
169
        out.encoding = "utf-8"
166
170
        view = self.make_view_only(out, 20)
167
171
        task = self.make_task(None, view, u"\xa7", 0, 1)
168
172
        view.show_progress(task)
169
 
        self.assertEqual('\r/ \xc2\xa7 0/1            \r',
170
 
            out.getvalue())
 
173
        self.assertEqual(u'\r/ \xa7 0/1            \r', out.getvalue())
171
174
 
172
175
    def test_render_progress_unicode_enc_missing(self):
173
 
        out = StringIO()
 
176
        out = codecs.getwriter("ascii")(io.BytesIO())
174
177
        self.assertRaises(AttributeError, getattr, out, "encoding")
175
178
        view = self.make_view_only(out, 20)
176
179
        task = self.make_task(None, view, u"\xa7", 0, 1)
177
180
        view.show_progress(task)
178
 
        self.assertEqual('\r/ ? 0/1             \r',
179
 
            out.getvalue())
 
181
        self.assertEqual(b'\r/ ? 0/1             \r', out.getvalue())
180
182
 
181
183
    def test_render_progress_unicode_enc_none(self):
182
 
        out = tests.StringIOWrapper()
 
184
        out = ui_testing.StringIOWithEncoding()
183
185
        out.encoding = None
184
186
        view = self.make_view_only(out, 20)
185
187
        task = self.make_task(None, view, u"\xa7", 0, 1)
186
188
        view.show_progress(task)
187
 
        self.assertEqual('\r/ ? 0/1             \r',
188
 
            out.getvalue())
 
189
        self.assertEqual(u'\r/ ? 0/1             \r', out.getvalue())