~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_commit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-14 11:09:39 UTC
  • mfrom: (5422.1.5 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100914110939-hvk7xfh39y9hq76a
(mbp) split out ProgressRecordingUIFactory (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from bzrlib.trace import mutter
39
39
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
40
40
                                WorkingTree)
41
 
 
42
 
 
43
 
class CapturingUIFactory(ui.UIFactory):
44
 
    """A UI Factory for testing - capture the updates made through it."""
45
 
 
46
 
    def __init__(self):
47
 
        super(CapturingUIFactory, self).__init__()
48
 
        self._calls = []
49
 
        self.depth = 0
50
 
 
51
 
    def clear(self):
52
 
        """See progress.ProgressTask.clear()."""
53
 
 
54
 
    def clear_term(self):
55
 
        """See progress.ProgressTask.clear_term()."""
56
 
 
57
 
    def finished(self):
58
 
        """See progress.ProgressTask.finished()."""
59
 
        self.depth -= 1
60
 
 
61
 
    def note(self, fmt_string, *args, **kwargs):
62
 
        """See progress.ProgressTask.note()."""
63
 
 
64
 
    def progress_bar(self):
65
 
        return self
66
 
 
67
 
    def nested_progress_bar(self):
68
 
        self.depth += 1
69
 
        return self
70
 
 
71
 
    def update(self, message, count=None, total=None):
72
 
        """See progress.ProgressTask.update()."""
73
 
        if self.depth == 1:
74
 
            self._calls.append(("update", count, total, message))
75
 
 
76
 
 
77
 
class TestCapturingUI(TestCase):
78
 
 
79
 
    def test_nested_ignore_depth_beyond_one(self):
80
 
        # we only want to capture the first level out progress, not
81
 
        # want sub-components might do. So we have nested bars ignored.
82
 
        factory = CapturingUIFactory()
83
 
        pb1 = factory.nested_progress_bar()
84
 
        pb1.update('foo', 0, 1)
85
 
        pb2 = factory.nested_progress_bar()
86
 
        pb2.update('foo', 0, 1)
87
 
        pb2.finished()
88
 
        pb1.finished()
89
 
        self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
 
41
from bzrlib.tests.testui import ProgressRecordingUIFactory
90
42
 
91
43
 
92
44
class TestCommit(TestCaseWithWorkingTree):
507
459
 
508
460
    def setUp(self):
509
461
        super(TestCommitProgress, self).setUp()
510
 
        ui.ui_factory = CapturingUIFactory()
 
462
        ui.ui_factory = ProgressRecordingUIFactory()
511
463
 
512
464
    def test_commit_progress_steps(self):
513
465
        # during commit we one progress update for every entry in the
526
478
        f.close()
527
479
        # set a progress bar that captures the calls so we can see what is
528
480
        # emitted
529
 
        factory = CapturingUIFactory()
 
481
        factory = ProgressRecordingUIFactory()
530
482
        ui.ui_factory = factory
531
483
        # TODO RBC 20060421 it would be nice to merge the reporter output
532
484
        # into the factory for this test - just make the test ui factory
547
499
        tree = self.make_branch_and_tree('.')
548
500
        # set a progress bar that captures the calls so we can see what is
549
501
        # emitted
550
 
        factory = CapturingUIFactory()
 
502
        factory = ProgressRecordingUIFactory()
551
503
        ui.ui_factory = factory
552
504
        def a_hook(_, _2, _3, _4, _5, _6):
553
505
            pass
570
522
        tree = self.make_branch_and_tree('.')
571
523
        # set a progress bar that captures the calls so we can see what is
572
524
        # emitted
573
 
        factory = CapturingUIFactory()
 
525
        factory = ProgressRecordingUIFactory()
574
526
        ui.ui_factory = factory
575
527
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
576
528
            pass