~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-20 22:32:33 UTC
  • mto: This revision was merged to the branch mainline in revision 2025.
  • Revision ID: john@arbash-meinel.com-20060920223233-8ec5b9c560295b60
When a weave file is empty, we should get WeaveFormatError, not StopIteration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
18
from StringIO import StringIO
19
19
 
20
20
from bzrlib import errors
21
21
from bzrlib.progress import (
22
 
        DummyProgress,
23
 
        ChildProgress,
 
22
        DummyProgress, ChildProgress,
24
23
        TTYProgressBar,
25
24
        DotsProgressBar,
26
25
        ProgressBarStack,
27
 
        InstrumentedProgress,
28
26
        )
29
27
from bzrlib.tests import TestCase
30
 
from bzrlib.symbol_versioning import (
31
 
    deprecated_in,
32
 
    )
33
28
 
34
29
 
35
30
class FakeStack:
36
 
 
37
31
    def __init__(self, top):
38
32
        self.__top = top
39
33
 
40
34
    def top(self):
41
35
        return self.__top
42
36
 
 
37
class InstrumentedProgress(TTYProgressBar):
 
38
    """TTYProgress variant that tracks outcomes"""
 
39
 
 
40
    def __init__(self, *args, **kwargs):
 
41
        self.always_throttled = True
 
42
        TTYProgressBar.__init__(self, *args, **kwargs)
 
43
 
 
44
    def throttle(self, old_message):
 
45
        result = TTYProgressBar.throttle(self, old_message)
 
46
        if result is False:
 
47
            self.always_throttled = False
 
48
        
43
49
 
44
50
class _TTYStringIO(StringIO):
45
51
    """A helper class which makes a StringIO look like a terminal"""
56
62
 
57
63
 
58
64
class TestProgress(TestCase):
59
 
 
60
65
    def setUp(self):
61
 
        TestCase.setUp(self)
62
66
        q = DummyProgress()
63
67
        self.top = ChildProgress(_stack=FakeStack(q))
64
68
 
92
96
        self.assertEqual(self.top.child_fraction, 1)
93
97
 
94
98
    def test_implementations(self):
95
 
        for implementation in (TTYProgressBar, DotsProgressBar,
 
99
        for implementation in (TTYProgressBar, DotsProgressBar, 
96
100
                               DummyProgress):
97
101
            self.check_parent_handling(implementation)
98
102
 
110
114
        self.check_stack(DummyProgress, DummyProgress)
111
115
 
112
116
    def check_stack(self, parent_class, child_class):
113
 
        stack = self.applyDeprecated(
114
 
            deprecated_in((1, 12, 0)),
115
 
            ProgressBarStack,
116
 
            klass=parent_class, to_file=StringIO())
 
117
        stack = ProgressBarStack(klass=parent_class, to_file=StringIO())
117
118
        parent = stack.get_nested()
118
119
        try:
119
120
            self.assertIs(parent.__class__, parent_class)
219
220
 
220
221
        self.addCleanup(reset)
221
222
 
222
 
        stack = self.applyDeprecated(
223
 
            deprecated_in((1, 12, 0)),
224
 
            ProgressBarStack,
225
 
            to_file=outf)
 
223
        stack = ProgressBarStack(to_file=outf)
226
224
        pb = stack.get_nested()
227
225
        pb.start_time -= 1 # Make sure it is ready to write
228
226
        pb.width = 20 # And it is of reasonable size
245
243
                         '\r                   \r',
246
244
                         out.getvalue())
247
245
 
248
 
    def test_noninteractive_progress(self):
249
 
        out = _NonTTYStringIO()
250
 
        pb = self.get_nested(out, 'xterm')
251
 
        self.assertIsInstance(pb, DummyProgress)
252
 
        try:
253
 
            pb.update('foo', 1, 2)
254
 
            pb.update('bar', 2, 2)
255
 
        finally:
256
 
            pb.finished()
257
 
        self.assertEqual('', out.getvalue())
258
 
 
259
246
    def test_dots_progress(self):
260
 
        # make sure we get the right progress bar when not on a terminal
 
247
        # Make sure the ProgressBarStack thinks it is
 
248
        # not writing out to a terminal, and thus uses a 
 
249
        # DotsProgressBar
261
250
        out = _NonTTYStringIO()
262
 
        pb = self.get_nested(out, 'xterm', 'dots')
 
251
        pb = self.get_nested(out, 'xterm')
263
252
        self.assertIsInstance(pb, DotsProgressBar)
264
253
        try:
265
254
            pb.update('foo', 1, 2)
266
255
            pb.update('bar', 2, 2)
267
256
        finally:
268
257
            pb.finished()
 
258
 
269
259
        self.assertEqual('foo: .'
270
260
                         '\nbar: .'
271
261
                         '\n',
277
267
        out = cStringIO.StringIO()
278
268
        pb = self.get_nested(out, 'xterm')
279
269
        pb.finished()
280
 
        self.assertIsInstance(pb, DummyProgress)
 
270
        self.assertIsInstance(pb, DotsProgressBar)
281
271
 
282
272
    def test_dumb_progress(self):
283
 
        # using a terminal that can't do cursor movement
 
273
        # Make sure the ProgressBarStack thinks it is writing out to a 
 
274
        # terminal, but it is the emacs 'dumb' terminal, so it uses
 
275
        # Dots
284
276
        out = _TTYStringIO()
285
277
        pb = self.get_nested(out, 'dumb')
286
278
        pb.finished()
287
 
        self.assertIsInstance(pb, DummyProgress)
 
279
        self.assertIsInstance(pb, DotsProgressBar)
288
280
 
289
281
    def test_progress_env_tty(self):
290
282
        # The environ variable BZR_PROGRESS_BAR controls what type of
298
290
        # Even though we are not a tty, the env_var will override
299
291
        self.assertIsInstance(pb, TTYProgressBar)
300
292
 
 
293
    def test_progress_env_dots(self):
 
294
        # Even though we are in a tty, the env_var will override
 
295
        out = _TTYStringIO()
 
296
        pb = self.get_nested(out, 'xterm', 'dots')
 
297
        pb.finished()
 
298
        self.assertIsInstance(pb, DotsProgressBar)
 
299
 
301
300
    def test_progress_env_none(self):
302
301
        # Even though we are in a valid tty, no progress
303
302
        out = _TTYStringIO()