/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/per_workingtree/test_commit.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 09:46:28 UTC
  • mfrom: (5609.33.4 2.3)
  • mto: (5609.33.5 2.3)
  • mto: This revision was merged to the branch mainline in revision 5811.
  • Revision ID: john@arbash-meinel.com-20110420094628-l0bafq1lwb6ib1v2
Merge lp:bzr/2.3 @ 5640 so we can update the release notes (aka NEWS)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
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):
168
120
        tree_a.commit('change n in A')
169
121
 
170
122
        # Merging from A should introduce conflicts because 'n' was modified
171
 
        # and removed, so 'a' needs to be restored.
 
123
        # (in A) and removed (in B), so 'a' needs to be restored.
172
124
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
173
125
        self.assertEqual(3, num_conflicts)
174
126
        paths = [(path, ie.file_id)
505
457
 
506
458
class TestCommitProgress(TestCaseWithWorkingTree):
507
459
 
508
 
    def restoreDefaults(self):
509
 
        ui.ui_factory = self.old_ui_factory
 
460
    def setUp(self):
 
461
        super(TestCommitProgress, self).setUp()
 
462
        ui.ui_factory = ProgressRecordingUIFactory()
510
463
 
511
464
    def test_commit_progress_steps(self):
512
465
        # during commit we one progress update for every entry in the
525
478
        f.close()
526
479
        # set a progress bar that captures the calls so we can see what is
527
480
        # emitted
528
 
        self.old_ui_factory = ui.ui_factory
529
 
        self.addCleanup(self.restoreDefaults)
530
 
        factory = CapturingUIFactory()
 
481
        factory = ProgressRecordingUIFactory()
531
482
        ui.ui_factory = factory
532
483
        # TODO RBC 20060421 it would be nice to merge the reporter output
533
484
        # into the factory for this test - just make the test ui factory
548
499
        tree = self.make_branch_and_tree('.')
549
500
        # set a progress bar that captures the calls so we can see what is
550
501
        # emitted
551
 
        self.old_ui_factory = ui.ui_factory
552
 
        self.addCleanup(self.restoreDefaults)
553
 
        factory = CapturingUIFactory()
 
502
        factory = ProgressRecordingUIFactory()
554
503
        ui.ui_factory = factory
555
504
        def a_hook(_, _2, _3, _4, _5, _6):
556
505
            pass
573
522
        tree = self.make_branch_and_tree('.')
574
523
        # set a progress bar that captures the calls so we can see what is
575
524
        # emitted
576
 
        self.old_ui_factory = ui.ui_factory
577
 
        self.addCleanup(self.restoreDefaults)
578
 
        factory = CapturingUIFactory()
 
525
        factory = ProgressRecordingUIFactory()
579
526
        ui.ui_factory = factory
580
527
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
581
528
            pass
621
568
                mutabletree.MutableTree))
622
569
            open(tree.abspath("newfile"), 'w').write("data")
623
570
            params.mutable_tree.add(["newfile"])
624
 
        def restoreDefaults():
625
 
            mutabletree.MutableTree.hooks['post_commit'] = []
626
 
        self.addCleanup(restoreDefaults)
627
571
        tree = self.make_branch_and_tree('.')
628
572
        mutabletree.MutableTree.hooks.install_named_hook(
629
573
            'post_commit',