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
18
from cStringIO import StringIO
23
from breezy.progress import (
20
from ..progress import (
26
from breezy.ui.text import (
23
from ..ui.text import (
31
35
class TestTextProgressView(tests.TestCase):
32
36
"""Tests for text display of progress bars.
46
50
def make_view(self):
51
out = ui_testing.StringIOWithEncoding()
48
52
return out, self.make_view_only(out)
50
54
def make_task(self, parent_task, view, msg, curr, total):
161
165
self.assertEqual(len(line), 79)
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',
173
self.assertEqual(u'\r/ \xa7 0/1 \r', out.getvalue())
172
175
def test_render_progress_unicode_enc_missing(self):
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',
181
self.assertEqual(b'\r/ ? 0/1 \r', out.getvalue())
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',
189
self.assertEqual(u'\r/ ? 0/1 \r', out.getvalue())