~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

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 cStringIO import StringIO
 
18
from StringIO import StringIO
19
19
 
20
 
from bzrlib import (
21
 
    tests,
22
 
    )
23
20
from bzrlib.progress import (
24
21
    ProgressTask,
25
22
    )
 
23
from bzrlib.tests import TestCase
26
24
from bzrlib.ui.text import (
27
25
    TextProgressView,
28
26
    )
29
27
 
30
28
 
31
 
class TestTextProgressView(tests.TestCase):
 
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):
32
44
    """Tests for text display of progress bars.
33
45
 
34
46
    These try to exercise the progressview independently of its construction,
37
49
    # The ProgressTask now connects directly to the ProgressView, so we can
38
50
    # check them independently of the factory or of the determination of what
39
51
    # view to use.
40
 
 
41
 
    def make_view_only(self, out, width=79):
 
52
    
 
53
    def make_view(self):
 
54
        out = StringIO()
42
55
        view = TextProgressView(out)
43
 
        view._avail_width = lambda: width
44
 
        return view
45
 
 
46
 
    def make_view(self):
47
 
        out = StringIO()
48
 
        return out, self.make_view_only(out)
49
 
 
 
56
        view._avail_width = lambda: 79
 
57
        return out, view
 
58
    
50
59
    def make_task(self, parent_task, view, msg, curr, total):
51
60
        # would normally be done by UIFactory; is done here so that we don't
52
61
        # have to have one.
159
168
'   123kB   100kB/s \\ start_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.. 2000/5000',
160
169
           line) 
161
170
        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())