~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-06-22 18:24:25 UTC
  • mfrom: (1803 +trunk)
  • mto: (1793.3.6 bundle-fixes)
  • mto: This revision was merged to the branch mainline in revision 1806.
  • Revision ID: john@arbash-meinel.com-20060622182425-6f45cb7acd587216
[merge] bzr.dev 1804 and fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from StringIO import StringIO
18
18
 
19
 
from bzrlib.progress import *
 
19
from bzrlib.progress import (
 
20
        DummyProgress, ChildProgress,
 
21
        TTYProgressBar,
 
22
        DotsProgressBar,
 
23
        ProgressBarStack,
 
24
        )
20
25
from bzrlib.tests import TestCase
21
26
 
22
27
class FakeStack:
26
31
    def top(self):
27
32
        return self.__top
28
33
 
 
34
class InstrumentedProgress(TTYProgressBar):
 
35
    """TTYProgress variant that tracks outcomes"""
 
36
 
 
37
    def __init__(self, *args, **kwargs):
 
38
        self.always_throttled = True
 
39
        TTYProgressBar.__init__(self, *args, **kwargs)
 
40
 
 
41
    def throttle(self, old_message):
 
42
        result = TTYProgressBar.throttle(self, old_message)
 
43
        if result is False:
 
44
            self.always_throttled = False
 
45
        
 
46
 
29
47
class TestProgress(TestCase):
30
48
    def setUp(self):
31
49
        q = DummyProgress()
90
108
                child.finished()
91
109
        finally:
92
110
            parent.finished()
 
111
 
 
112
    def test_throttling(self):
 
113
        pb = InstrumentedProgress(to_file=StringIO())
 
114
        # instantaneous updates should be squelched
 
115
        pb.update('me', 1, 1)
 
116
        self.assertTrue(pb.always_throttled)
 
117
        pb = InstrumentedProgress(to_file=StringIO())
 
118
        # It's like an instant sleep(1)!
 
119
        pb.start_time -= 1
 
120
        # Updates after a second should not be squelched
 
121
        pb.update('me', 1, 1)
 
122
        self.assertFalse(pb.always_throttled)