~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

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 that branch classes implement hook callouts correctly."""
 
18
 
 
19
from bzrlib.branch import Branch
 
20
from bzrlib.tests import TestCaseWithMemoryTransport
 
21
 
 
22
 
 
23
class TestSetRevisionHistoryHook(TestCaseWithMemoryTransport):
 
24
 
 
25
    def setUp(self):
 
26
        self.hook_calls = []
 
27
        TestCaseWithMemoryTransport.setUp(self)
 
28
 
 
29
    def capture_set_rh_hook(self, branch, rev_history):
 
30
        """Capture post set-rh hook calls to self.hook_calls.
 
31
        
 
32
        The call is logged, as is some state of the branch.
 
33
        """
 
34
        self.hook_calls.append(
 
35
            ('set_rh', branch, rev_history, branch.is_locked()))
 
36
 
 
37
    def test_set_rh_empty_history(self):
 
38
        branch = self.make_branch('source')
 
39
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
40
        branch.set_revision_history([])
 
41
        self.assertEqual(self.hook_calls,
 
42
            [('set_rh', branch, [], True)])
 
43
 
 
44
    def test_set_rh_nonempty_history(self):
 
45
        tree = self.make_branch_and_memory_tree('source')
 
46
        tree.lock_write()
 
47
        tree.add('')
 
48
        tree.commit('empty commit', rev_id='foo')
 
49
        tree.unlock()
 
50
        branch = tree.branch
 
51
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
52
        branch.set_revision_history(['f\xc2\xb5'])
 
53
        self.assertEqual(self.hook_calls,
 
54
            [('set_rh', branch, ['f\xc2\xb5'], True)])
 
55
 
 
56
    def test_set_rh_branch_is_locked(self):
 
57
        branch = self.make_branch('source')
 
58
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
59
        branch.set_revision_history([])
 
60
        self.assertEqual(self.hook_calls,
 
61
            [('set_rh', branch, [], True)])
 
62
 
 
63
    def test_set_rh_calls_all_hooks_no_errors(self):
 
64
        branch = self.make_branch('source')
 
65
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
66
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
67
        branch.set_revision_history([])
 
68
        self.assertEqual(self.hook_calls,
 
69
            [('set_rh', branch, [], True),
 
70
             ('set_rh', branch, [], True),
 
71
            ])