/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_progress.py

Got stack handling under test

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from bzrlib.progress import *
20
20
from bzrlib.tests import TestCase
21
21
 
 
22
class FakeStack:
 
23
    def __init__(self, top):
 
24
        self.__top = top
 
25
 
 
26
    def top(self):
 
27
        return self.__top
 
28
 
22
29
class TestProgress(TestCase):
23
30
    def setUp(self):
24
 
        self.top = ChildProgress(stack=[DummyProgress()])
 
31
        q = DummyProgress()
 
32
        self.top = ChildProgress(_stack=FakeStack(q))
25
33
 
26
34
    def test_propogation(self):
27
35
        self.top.update('foobles', 1, 2)
29
37
        self.assertEqual(self.top.current, 1)
30
38
        self.assertEqual(self.top.total, 2)
31
39
        self.assertEqual(self.top.child_fraction, 0)
32
 
        child = ChildProgress(stack=[self.top])
 
40
        child = ChildProgress(_stack=FakeStack(self.top))
33
41
        child.update('baubles', 2, 4)
34
42
        self.assertEqual(self.top.message, 'foobles')
35
43
        self.assertEqual(self.top.current, 1)
36
44
        self.assertEqual(self.top.total, 2)
37
45
        self.assertEqual(self.top.child_fraction, 0.5)
38
 
        grandchild = ChildProgress(stack=[child])
 
46
        grandchild = ChildProgress(_stack=FakeStack(child))
39
47
        grandchild.update('barbells', 1, 2)
40
48
        self.assertEqual(self.top.child_fraction, 0.625)
41
49
        self.assertEqual(child.child_fraction, 0.5)
60
68
    def check_parent_handling(self, parentclass):
61
69
        top = parentclass(to_file=StringIO())
62
70
        top.update('foobles', 1, 2)
63
 
        child = ChildProgress(stack=[top])
 
71
        child = ChildProgress(_stack=FakeStack(top))
64
72
        child.update('baubles', 4, 4)
65
73
        top.update('lala', 2, 2)
66
74
        child.update('baubles', 4, 4)
 
75
 
 
76
    def test_stacking(self):
 
77
        self.check_stack(TTYProgressBar, ChildProgress)
 
78
        self.check_stack(DotsProgressBar, ChildProgress)
 
79
        self.check_stack(DummyProgress, DummyProgress)
 
80
 
 
81
    def check_stack(self, parent_class, child_class):
 
82
        stack = ProgressBarStack(klass=parent_class, to_file=StringIO())
 
83
        parent = stack.get_nested()
 
84
        try:
 
85
            self.assertIs(parent.__class__, parent_class)
 
86
            child = stack.get_nested()
 
87
            try:
 
88
                self.assertIs(child.__class__, child_class)
 
89
            finally:
 
90
                child.finished()
 
91
        finally:
 
92
            parent.finished()