~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Aaron Bentley
  • Date: 2006-06-21 02:33:40 UTC
  • mto: This revision was merged to the branch mainline in revision 1800.
  • Revision ID: aaron.bentley@utoronto.ca-20060621023340-19364e0e14d66548
Hide TTYProgressBars unless they last more than 1 second

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    def top(self):
27
27
        return self.__top
28
28
 
 
29
class InstrumentedProgress(TTYProgressBar):
 
30
    """TTYProgress variant that tracks outcomes"""
 
31
 
 
32
    def __init__(self, *args, **kwargs):
 
33
        self.always_throttled = True
 
34
        TTYProgressBar.__init__(self, *args, **kwargs)
 
35
 
 
36
    def throttle(self, old_message):
 
37
        result = TTYProgressBar.throttle(self, old_message)
 
38
        if result is False:
 
39
            self.always_throttled = False
 
40
        
 
41
 
29
42
class TestProgress(TestCase):
30
43
    def setUp(self):
31
44
        q = DummyProgress()
90
103
                child.finished()
91
104
        finally:
92
105
            parent.finished()
 
106
 
 
107
    def test_throttling(self):
 
108
        pb = InstrumentedProgress(to_file=StringIO())
 
109
        # instantaneous updates should be squelched
 
110
        pb.update('me', 1, 1)
 
111
        self.assertTrue(pb.always_throttled)
 
112
        pb = InstrumentedProgress(to_file=StringIO())
 
113
        # It's like an instant sleep(1)!
 
114
        pb.start_time -= 1
 
115
        # Updates after a second should not be squelched
 
116
        pb.update('me', 1, 1)
 
117
        self.assertFalse(pb.always_throttled)