~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-21 03:14:59 UTC
  • mfrom: (1793.1.1 progress-flicker)
  • Revision ID: pqm@pqm.ubuntu.com-20060621031459-5f06bd6e74982326
Hide TTYProgressBars unless they last more than 1 second

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    def top(self):
32
32
        return self.__top
33
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
 
34
47
class TestProgress(TestCase):
35
48
    def setUp(self):
36
49
        q = DummyProgress()
95
108
                child.finished()
96
109
        finally:
97
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)