~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Aaron Bentley
  • Date: 2007-08-16 00:54:00 UTC
  • mto: This revision was merged to the branch mainline in revision 2711.
  • Revision ID: aaron.bentley@utoronto.ca-20070816005400-oxxtqiy310wx10h9
Fix typo

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
18
from StringIO import StringIO
24
24
        TTYProgressBar,
25
25
        DotsProgressBar,
26
26
        ProgressBarStack,
27
 
        InstrumentedProgress,
28
27
        )
29
28
from bzrlib.tests import TestCase
30
 
from bzrlib.symbol_versioning import (
31
 
    deprecated_in,
32
 
    )
33
29
 
34
30
 
35
31
class FakeStack:
36
 
 
37
32
    def __init__(self, top):
38
33
        self.__top = top
39
34
 
40
35
    def top(self):
41
36
        return self.__top
42
37
 
 
38
class InstrumentedProgress(TTYProgressBar):
 
39
    """TTYProgress variant that tracks outcomes"""
 
40
 
 
41
    def __init__(self, *args, **kwargs):
 
42
        self.always_throttled = True
 
43
        TTYProgressBar.__init__(self, *args, **kwargs)
 
44
 
 
45
    def throttle(self, old_message):
 
46
        result = TTYProgressBar.throttle(self, old_message)
 
47
        if result is False:
 
48
            self.always_throttled = False
 
49
        
43
50
 
44
51
class _TTYStringIO(StringIO):
45
52
    """A helper class which makes a StringIO look like a terminal"""
56
63
 
57
64
 
58
65
class TestProgress(TestCase):
59
 
 
60
66
    def setUp(self):
61
 
        TestCase.setUp(self)
62
67
        q = DummyProgress()
63
68
        self.top = ChildProgress(_stack=FakeStack(q))
64
69
 
92
97
        self.assertEqual(self.top.child_fraction, 1)
93
98
 
94
99
    def test_implementations(self):
95
 
        for implementation in (TTYProgressBar, DotsProgressBar,
 
100
        for implementation in (TTYProgressBar, DotsProgressBar, 
96
101
                               DummyProgress):
97
102
            self.check_parent_handling(implementation)
98
103
 
110
115
        self.check_stack(DummyProgress, DummyProgress)
111
116
 
112
117
    def check_stack(self, parent_class, child_class):
113
 
        stack = self.applyDeprecated(
114
 
            deprecated_in((1, 12, 0)),
115
 
            ProgressBarStack,
116
 
            klass=parent_class, to_file=StringIO())
 
118
        stack = ProgressBarStack(klass=parent_class, to_file=StringIO())
117
119
        parent = stack.get_nested()
118
120
        try:
119
121
            self.assertIs(parent.__class__, parent_class)
219
221
 
220
222
        self.addCleanup(reset)
221
223
 
222
 
        stack = self.applyDeprecated(
223
 
            deprecated_in((1, 12, 0)),
224
 
            ProgressBarStack,
225
 
            to_file=outf)
 
224
        stack = ProgressBarStack(to_file=outf)
226
225
        pb = stack.get_nested()
227
226
        pb.start_time -= 1 # Make sure it is ready to write
228
227
        pb.width = 20 # And it is of reasonable size