~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

Move doctest import to increase speed

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 (
20
 
        DummyProgress, ChildProgress,
21
 
        TTYProgressBar,
22
 
        DotsProgressBar,
23
 
        ProgressBarStack,
24
 
        )
 
19
from bzrlib.progress import *
25
20
from bzrlib.tests import TestCase
26
21
 
27
22
class FakeStack:
31
26
    def top(self):
32
27
        return self.__top
33
28
 
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
 
 
47
29
class TestProgress(TestCase):
48
30
    def setUp(self):
49
31
        q = DummyProgress()
108
90
                child.finished()
109
91
        finally:
110
92
            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)