~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Robey Pointer
  • Date: 2006-07-01 19:03:33 UTC
  • mfrom: (1829 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1830.
  • Revision ID: robey@lag.net-20060701190333-f58465aec4bd3412
merge from bzr.dev

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)