~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_uncommit.py

  • Committer: Aaron Bentley
  • Date: 2007-02-16 07:02:19 UTC
  • mfrom: (2292 +trunk)
  • mto: (2255.6.1 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: aaron.bentley@utoronto.ca-20070216070219-b22k0gwnisnxawnk
Merged bzr.dev (17 tests failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
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
 
16
 
 
17
"""Tests for the contract of uncommit on branches.
 
18
 
 
19
Note that uncommit currently is not a branch method; it should be.
 
20
"""
 
21
 
 
22
from bzrlib.branch import Branch
 
23
from bzrlib import errors
 
24
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
25
from bzrlib.uncommit import uncommit
 
26
 
 
27
 
 
28
class TestUncommitHook(TestCaseWithBranch):
 
29
 
 
30
    def setUp(self):
 
31
        self.hook_calls = []
 
32
        TestCaseWithBranch.setUp(self)
 
33
 
 
34
    def capture_post_uncommit_hook(self, local, master, old_revno,
 
35
        old_revid, new_revno, new_revid):
 
36
        """Capture post uncommit hook calls to self.hook_calls.
 
37
        
 
38
        The call is logged, as is some state of the two branches.
 
39
        """
 
40
        if local:
 
41
            local_locked = local.is_locked()
 
42
            local_base = local.base
 
43
        else:
 
44
            local_locked = None
 
45
            local_base = None
 
46
        self.hook_calls.append(
 
47
            ('post_uncommit', local_base, master.base, old_revno, old_revid,
 
48
             new_revno, new_revid, local_locked, master.is_locked()))
 
49
 
 
50
    def test_post_uncommit_to_origin(self):
 
51
        tree = self.make_branch_and_memory_tree('branch')
 
52
        tree.lock_write()
 
53
        tree.add('')
 
54
        revid = tree.commit('a revision')
 
55
        tree.unlock()
 
56
        Branch.hooks.install_hook('post_uncommit',
 
57
            self.capture_post_uncommit_hook)
 
58
        uncommit(tree.branch)
 
59
        # with nothing left we should still get a notification, and
 
60
        # have the branch locked at notification time.
 
61
        self.assertEqual([
 
62
            ('post_uncommit', None, tree.branch.base, 1, revid,
 
63
             0, None, None, True)
 
64
            ],
 
65
            self.hook_calls)
 
66
 
 
67
    def test_post_uncommit_bound(self):
 
68
        master = self.make_branch('master')
 
69
        tree = self.make_branch_and_memory_tree('local')
 
70
        try:
 
71
            tree.branch.bind(master)
 
72
        except errors.UpgradeRequired:
 
73
            # cant bind this format, the test is irrelevant.
 
74
            return
 
75
        tree.lock_write()
 
76
        tree.add('')
 
77
        revid = tree.commit('a revision')
 
78
        tree.unlock()
 
79
        Branch.hooks.install_hook('post_uncommit',
 
80
            self.capture_post_uncommit_hook)
 
81
        uncommit(tree.branch)
 
82
        # with nothing left we should still get a notification, and
 
83
        # have the branch locked at notification time.
 
84
        self.assertEqual([
 
85
            ('post_uncommit', tree.branch.base, master.base, 1, revid,
 
86
             0, None, True, True)
 
87
            ],
 
88
            self.hook_calls)
 
89
 
 
90
    def test_post_uncommit_not_to_origin(self):
 
91
        tree = self.make_branch_and_memory_tree('branch')
 
92
        tree.lock_write()
 
93
        tree.add('')
 
94
        revid = tree.commit('first revision')
 
95
        revid2 = tree.commit('second revision')
 
96
        revid3 = tree.commit('third revision')
 
97
        tree.unlock()
 
98
        Branch.hooks.install_hook('post_uncommit',
 
99
            self.capture_post_uncommit_hook)
 
100
        uncommit(tree.branch, revno=2)
 
101
        # having uncommitted from up the branch, we should get the
 
102
        # before and after revnos and revids correctly.
 
103
        self.assertEqual([
 
104
            ('post_uncommit', None, tree.branch.base, 3, revid3,
 
105
             1, revid, None, True)
 
106
            ],
 
107
            self.hook_calls)
 
108