~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

  • Committer: Sabin Iacob
  • Date: 2009-03-23 14:59:43 UTC
  • mto: (4189.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4193.
  • Revision ID: iacobs@m0n5t3r.info-20090323145943-3s3p1px5q1rkh2e5
update FSF mailing address

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
18
from StringIO import StringIO
24
24
        TTYProgressBar,
25
25
        DotsProgressBar,
26
26
        ProgressBarStack,
 
27
        InstrumentedProgress,
27
28
        )
28
29
from bzrlib.tests import TestCase
 
30
from bzrlib.symbol_versioning import (
 
31
    deprecated_in,
 
32
    )
29
33
 
30
34
 
31
35
class FakeStack:
 
36
 
32
37
    def __init__(self, top):
33
38
        self.__top = top
34
39
 
35
40
    def top(self):
36
41
        return self.__top
37
42
 
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
 
        
50
43
 
51
44
class _TTYStringIO(StringIO):
52
45
    """A helper class which makes a StringIO look like a terminal"""
63
56
 
64
57
 
65
58
class TestProgress(TestCase):
 
59
 
66
60
    def setUp(self):
 
61
        TestCase.setUp(self)
67
62
        q = DummyProgress()
68
63
        self.top = ChildProgress(_stack=FakeStack(q))
69
64
 
97
92
        self.assertEqual(self.top.child_fraction, 1)
98
93
 
99
94
    def test_implementations(self):
100
 
        for implementation in (TTYProgressBar, DotsProgressBar, 
 
95
        for implementation in (TTYProgressBar, DotsProgressBar,
101
96
                               DummyProgress):
102
97
            self.check_parent_handling(implementation)
103
98
 
115
110
        self.check_stack(DummyProgress, DummyProgress)
116
111
 
117
112
    def check_stack(self, parent_class, child_class):
118
 
        stack = ProgressBarStack(klass=parent_class, to_file=StringIO())
 
113
        stack = self.applyDeprecated(
 
114
            deprecated_in((1, 12, 0)),
 
115
            ProgressBarStack,
 
116
            klass=parent_class, to_file=StringIO())
119
117
        parent = stack.get_nested()
120
118
        try:
121
119
            self.assertIs(parent.__class__, parent_class)
221
219
 
222
220
        self.addCleanup(reset)
223
221
 
224
 
        stack = ProgressBarStack(to_file=outf)
 
222
        stack = self.applyDeprecated(
 
223
            deprecated_in((1, 12, 0)),
 
224
            ProgressBarStack,
 
225
            to_file=outf)
225
226
        pb = stack.get_nested()
226
227
        pb.start_time -= 1 # Make sure it is ready to write
227
228
        pb.width = 20 # And it is of reasonable size