~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Aaron Bentley
  • Date: 2012-06-20 14:35:26 UTC
  • mfrom: (6525 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6526.
  • Revision ID: aaron@aaronbentley.com-20120620143526-hn40ezmorrubqphx
Merged dev into config-branchname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
from StringIO import StringIO
 
18
from cStringIO import StringIO
19
19
 
 
20
from bzrlib import (
 
21
    tests,
 
22
    )
20
23
from bzrlib.progress import (
21
24
    ProgressTask,
22
25
    )
23
 
from bzrlib.tests import TestCase
24
26
from bzrlib.ui.text import (
25
27
    TextProgressView,
26
28
    )
27
29
 
28
30
 
29
 
class _TTYStringIO(StringIO):
30
 
    """A helper class which makes a StringIO look like a terminal"""
31
 
 
32
 
    def isatty(self):
33
 
        return True
34
 
 
35
 
 
36
 
class _NonTTYStringIO(StringIO):
37
 
    """Helper that implements isatty() but returns False"""
38
 
 
39
 
    def isatty(self):
40
 
        return False
41
 
 
42
 
 
43
 
class TestTextProgressView(TestCase):
 
31
class TestTextProgressView(tests.TestCase):
44
32
    """Tests for text display of progress bars.
45
33
 
46
34
    These try to exercise the progressview independently of its construction,
49
37
    # The ProgressTask now connects directly to the ProgressView, so we can
50
38
    # check them independently of the factory or of the determination of what
51
39
    # view to use.
52
 
    
 
40
 
 
41
    def make_view_only(self, out, width=79):
 
42
        view = TextProgressView(out)
 
43
        view._avail_width = lambda: width
 
44
        return view
 
45
 
53
46
    def make_view(self):
54
47
        out = StringIO()
55
 
        view = TextProgressView(out)
56
 
        view._avail_width = lambda: 79
57
 
        return out, view
58
 
    
 
48
        return out, self.make_view_only(out)
 
49
 
59
50
    def make_task(self, parent_task, view, msg, curr, total):
60
51
        # would normally be done by UIFactory; is done here so that we don't
61
52
        # have to have one.
168
159
'   123kB   100kB/s \\ start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000',
169
160
           line) 
170
161
        self.assertEqual(len(line), 79)
 
162
 
 
163
    def test_render_progress_unicode_enc_utf8(self):
 
164
        out = tests.StringIOWrapper()
 
165
        out.encoding = "utf-8"
 
166
        view = self.make_view_only(out, 20)
 
167
        task = self.make_task(None, view, u"\xa7", 0, 1)
 
168
        view.show_progress(task)
 
169
        self.assertEqual('\r/ \xc2\xa7 0/1            \r',
 
170
            out.getvalue())
 
171
 
 
172
    def test_render_progress_unicode_enc_missing(self):
 
173
        out = StringIO()
 
174
        self.assertRaises(AttributeError, getattr, out, "encoding")
 
175
        view = self.make_view_only(out, 20)
 
176
        task = self.make_task(None, view, u"\xa7", 0, 1)
 
177
        view.show_progress(task)
 
178
        self.assertEqual('\r/ ? 0/1             \r',
 
179
            out.getvalue())
 
180
 
 
181
    def test_render_progress_unicode_enc_none(self):
 
182
        out = tests.StringIOWrapper()
 
183
        out.encoding = None
 
184
        view = self.make_view_only(out, 20)
 
185
        task = self.make_task(None, view, u"\xa7", 0, 1)
 
186
        view.show_progress(task)
 
187
        self.assertEqual('\r/ ? 0/1             \r',
 
188
            out.getvalue())