~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.tests import TestCaseWithMemoryTransport
21
21
 
22
22
 
23
 
class TestPushHook(TestCaseWithMemoryTransport):
 
23
class TestSetRevisionHistoryHook(TestCaseWithMemoryTransport):
24
24
 
25
25
    def setUp(self):
26
26
        self.hook_calls = []
27
27
        TestCaseWithMemoryTransport.setUp(self)
28
28
 
29
29
    def capture_set_rh_hook(self, branch, rev_history):
30
 
        """Capture post push hook calls to self.hook_calls.
 
30
        """Capture post set-rh hook calls to self.hook_calls.
31
31
        
32
 
        The call is logged, as is some state of the two branches.
 
32
        The call is logged, as is some state of the branch.
33
33
        """
34
34
        self.hook_calls.append(
35
35
            ('set_rh', branch, rev_history, branch.is_locked()))
36
36
 
37
37
    def test_set_rh_empty_history(self):
38
38
        branch = self.make_branch('source')
39
 
        Branch.hooks['set_rh'].append(self.capture_set_rh_hook)
 
39
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
40
40
        branch.set_revision_history([])
41
41
        self.assertEqual(self.hook_calls,
42
42
            [('set_rh', branch, [], True)])
43
43
 
44
44
    def test_set_rh_nonempty_history(self):
45
45
        branch = self.make_branch('source')
46
 
        Branch.hooks['set_rh'].append(self.capture_set_rh_hook)
 
46
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
47
47
        branch.set_revision_history([u'foo'])
48
48
        self.assertEqual(self.hook_calls,
49
49
            [('set_rh', branch, [u'foo'], True)])
50
50
 
51
51
    def test_set_rh_branch_is_locked(self):
52
52
        branch = self.make_branch('source')
53
 
        Branch.hooks['set_rh'].append(self.capture_set_rh_hook)
 
53
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
54
54
        branch.set_revision_history([])
55
55
        self.assertEqual(self.hook_calls,
56
56
            [('set_rh', branch, [], True)])
57
57
 
58
58
    def test_set_rh_calls_all_hooks_no_errors(self):
59
59
        branch = self.make_branch('source')
60
 
        Branch.hooks['set_rh'].append(self.capture_set_rh_hook)
61
 
        Branch.hooks['set_rh'].append(self.capture_set_rh_hook)
 
60
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
61
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
62
62
        branch.set_revision_history([])
63
63
        self.assertEqual(self.hook_calls,
64
64
            [('set_rh', branch, [], True),
65
65
             ('set_rh', branch, [], True),
66
66
            ])
67