/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/branch_implementations/test_hooks.py

  • Committer: James Henstridge
  • Date: 2008-04-09 03:09:58 UTC
  • mto: (3360.2.2 prepare-1.4)
  • mto: This revision was merged to the branch mainline in revision 3361.
  • Revision ID: james@jamesh.id.au-20080409030958-rzc9aplft44hpq35
Adjust my tests to pass with Ian's API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
            ])
76
76
 
77
77
 
78
 
class TestSetLastRevisionInfoHook(TestCaseWithMemoryTransport):
 
78
class TestPostChangeBranchTip(TestCaseWithMemoryTransport):
79
79
 
80
80
    def setUp(self):
81
81
        self.hook_calls = []
82
82
        TestCaseWithMemoryTransport.setUp(self)
83
83
 
84
 
    def capture_set_last_revision_info_hook(self, branch, revno, revid):
85
 
        """Capture set_last_revision_info hook calls to self.hook_calls.
 
84
    def capture_post_change_branch_tip_hook(self, branch, result):
 
85
        """Capture post_change_branch_tip hook calls to self.hook_calls.
86
86
 
87
87
        The call is logged, as is some state of the branch.
88
88
        """
89
 
        self.hook_calls.append(
90
 
            ('set_last_revision_info', branch, revno, revid,
91
 
             branch.is_locked()))
 
89
        self.hook_calls.append((branch, result, branch.is_locked()))
92
90
 
93
 
    def test_set_last_revision_info_empty_history(self):
 
91
    def test_post_change_branch_tip_empty_history(self):
94
92
        branch = self.make_branch('source')
95
 
        Branch.hooks.install_hook('set_last_revision_info',
96
 
                                  self.capture_set_last_revision_info_hook)
 
93
        Branch.hooks.install_hook('post_change_branch_tip',
 
94
                                  self.capture_post_change_branch_tip_hook)
97
95
        branch.set_last_revision_info(0, NULL_REVISION)
98
 
        self.assertEqual(self.hook_calls,
99
 
            [('set_last_revision_info', branch, 0, NULL_REVISION, True)])
 
96
        self.assertEqual(len(self.hook_calls), 1)
 
97
        self.assertEqual(self.hook_calls[0][0], branch)
 
98
        self.assertEqual(self.hook_calls[0][1].old_revid, NULL_REVISION)
 
99
        self.assertEqual(self.hook_calls[0][1].old_revno, 0)
 
100
        self.assertEqual(self.hook_calls[0][1].new_revid, NULL_REVISION)
 
101
        self.assertEqual(self.hook_calls[0][1].new_revno, 0)
100
102
 
101
 
    def test_set_last_revision_info_nonempty_history(self):
 
103
    def test_post_change_branch_tip_nonempty_history(self):
102
104
        tree = self.make_branch_and_memory_tree('source')
103
105
        tree.lock_write()
104
106
        tree.add('')
106
108
        tree.commit('empty commit', rev_id='foo')
107
109
        tree.unlock()
108
110
        branch = tree.branch
109
 
        Branch.hooks.install_hook('set_last_revision_info',
110
 
                                  self.capture_set_last_revision_info_hook)
 
111
        Branch.hooks.install_hook('post_change_branch_tip',
 
112
                                  self.capture_post_change_branch_tip_hook)
111
113
        # some branches require that their history be set to a revision in the
112
114
        # repository
113
115
        branch.set_last_revision_info(1, 'f\xc2\xb5')
114
 
        self.assertEqual(self.hook_calls,
115
 
            [('set_last_revision_info', branch, 1, 'f\xc2\xb5', True)])
116
 
 
117
 
    def test_set_last_revision_info_branch_is_locked(self):
118
 
        branch = self.make_branch('source')
119
 
        Branch.hooks.install_hook('set_last_revision_info',
120
 
                                  self.capture_set_last_revision_info_hook)
121
 
        branch.set_last_revision_info(0, NULL_REVISION)
122
 
        self.assertEqual(self.hook_calls,
123
 
            [('set_last_revision_info', branch, 0, NULL_REVISION, True)])
124
 
 
125
 
    def test_set_last_revision_info_calls_all_hooks_no_errors(self):
126
 
        branch = self.make_branch('source')
127
 
        Branch.hooks.install_hook('set_last_revision_info',
128
 
                                  self.capture_set_last_revision_info_hook)
129
 
        Branch.hooks.install_hook('set_last_revision_info',
130
 
                                  self.capture_set_last_revision_info_hook)
131
 
        branch.set_last_revision_info(0, NULL_REVISION)
132
 
        self.assertEqual(self.hook_calls,
133
 
            [('set_last_revision_info', branch, 0, NULL_REVISION, True),
134
 
             ('set_last_revision_info', branch, 0, NULL_REVISION, True),
135
 
            ])
 
116
        self.assertEqual(len(self.hook_calls), 1)
 
117
        self.assertEqual(self.hook_calls[0][0], branch)
 
118
        self.assertEqual(self.hook_calls[0][1].old_revid, 'foo')
 
119
        self.assertEqual(self.hook_calls[0][1].old_revno, 2)
 
120
        self.assertEqual(self.hook_calls[0][1].new_revid, 'f\xc2\xb5')
 
121
        self.assertEqual(self.hook_calls[0][1].new_revno, 1)
 
122
 
 
123
    def test_post_change_branch_tip_branch_is_locked(self):
 
124
        branch = self.make_branch('source')
 
125
        Branch.hooks.install_hook('post_change_branch_tip',
 
126
                                  self.capture_post_change_branch_tip_hook)
 
127
        branch.set_last_revision_info(0, NULL_REVISION)
 
128
        self.assertEqual(len(self.hook_calls), 1)
 
129
        self.assertEqual(self.hook_calls[0][0], branch)
 
130
        self.assertEqual(self.hook_calls[0][2], True)
 
131
 
 
132
    def test_post_change_branch_tip_calls_all_hooks_no_errors(self):
 
133
        branch = self.make_branch('source')
 
134
        Branch.hooks.install_hook('post_change_branch_tip',
 
135
                                  self.capture_post_change_branch_tip_hook)
 
136
        Branch.hooks.install_hook('post_change_branch_tip',
 
137
                                  self.capture_post_change_branch_tip_hook)
 
138
        branch.set_last_revision_info(0, NULL_REVISION)
 
139
        self.assertEqual(len(self.hook_calls), 2)
 
140
        self.assertEqual(self.hook_calls[0][0], branch)
 
141
        self.assertEqual(self.hook_calls[1][0], branch)