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

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    def test_unknown_hook(self):
39
39
        error = UnknownHook("branch", "foo")
40
40
        self.assertEqualDiff("The branch hook 'foo' is unknown in this version"
41
 
                             " of breezy.",
42
 
                             str(error))
 
41
            " of breezy.",
 
42
            str(error))
43
43
        error = UnknownHook("tree", "bar")
44
44
        self.assertEqualDiff("The tree hook 'bar' is unknown in this version"
45
 
                             " of breezy.",
46
 
                             str(error))
 
45
            " of breezy.",
 
46
            str(error))
47
47
 
48
48
 
49
49
class TestHooks(tests.TestCase):
55
55
        hooks = MyHooks("breezy.tests.test_hooks", "some_hooks")
56
56
        hooks['legacy'] = []
57
57
        hooks.add_hook('post_tip_change',
58
 
                       "Invoked after the tip of a branch changes. Called with "
59
 
                       "a ChangeBranchTipParams object.", (1, 4))
 
58
            "Invoked after the tip of a branch changes. Called with "
 
59
            "a ChangeBranchTipParams object.", (1, 4))
60
60
        hooks.add_hook('pre_tip_change',
61
 
                       "Invoked before the tip of a branch changes. Called with "
62
 
                       "a ChangeBranchTipParams object. Hooks should raise "
63
 
                       "TipChangeRejected to signal that a tip change is not permitted.",
64
 
                       (1, 6), None)
 
61
            "Invoked before the tip of a branch changes. Called with "
 
62
            "a ChangeBranchTipParams object. Hooks should raise "
 
63
            "TipChangeRejected to signal that a tip change is not permitted.",
 
64
            (1, 6), None)
65
65
        self.assertEqualDiff(
66
66
            "MyHooks\n"
67
67
            "-------\n"
128
128
        hooks = Hooks("breezy.tests.test_hooks", "some_hooks")
129
129
        hooks.add_hook('set_rh', "Set revision hsitory", (2, 0))
130
130
        self.assertRaises(KeyError, hooks.uninstall_named_hook, "set_rh",
131
 
                          "demo")
 
131
            "demo")
132
132
 
133
133
    def test_uninstall_named_hook_raises_unknown_hook(self):
134
134
        hooks = Hooks("breezy.tests.test_hooks", "some_hooks")
139
139
        hooks["set_rh"] = []
140
140
        hooks.install_named_hook('set_rh', None, "demo")
141
141
        self.assertRaises(errors.UnsupportedOperation,
142
 
                          hooks.uninstall_named_hook, "set_rh", "demo")
 
142
            hooks.uninstall_named_hook, "set_rh", "demo")
143
143
 
144
144
    hooks = Hooks("breezy.tests.test_hooks", "TestHooks.hooks")
145
145
 
147
147
        # When the hook points are not yet registered the hook is
148
148
        # added to the _lazy_hooks dictionary in breezy.hooks.
149
149
        self.hooks.add_hook('set_rh', "doc", (0, 15))
150
 
 
151
 
        def set_rh(): return None
 
150
        set_rh = lambda: None
152
151
        install_lazy_named_hook('breezy.tests.test_hooks',
153
 
                                'TestHooks.hooks', 'set_rh', set_rh, "demo")
 
152
            'TestHooks.hooks', 'set_rh', set_rh, "demo")
154
153
        set_rh_lazy_hooks = _mod_hooks._lazy_hooks[
155
154
            ('breezy.tests.test_hooks', 'TestHooks.hooks', 'set_rh')]
156
155
        self.assertEqual(1, len(set_rh_lazy_hooks))
158
157
        self.assertEqual("demo", set_rh_lazy_hooks[0][1])
159
158
        self.assertEqual(list(TestHooks.hooks['set_rh']), [set_rh])
160
159
 
161
 
    def set_rh(): return None
 
160
    set_rh = lambda: None
162
161
 
163
162
    def test_install_named_hook_lazy(self):
164
163
        hooks = Hooks("breezy.tests.hooks", "some_hooks")
165
164
        hooks['set_rh'] = HookPoint("set_rh", "doc", (0, 15), None)
166
165
        hooks.install_named_hook_lazy('set_rh', 'breezy.tests.test_hooks',
167
 
                                      'TestHooks.set_rh', "demo")
 
166
            'TestHooks.set_rh', "demo")
168
167
        self.assertEqual(list(hooks['set_rh']), [TestHooks.set_rh])
169
168
 
170
169
    def test_install_named_hook_lazy_old(self):
173
172
        hooks = Hooks("breezy.tests.hooks", "some_hooks")
174
173
        hooks['set_rh'] = []
175
174
        self.assertRaises(errors.UnsupportedOperation,
176
 
                          hooks.install_named_hook_lazy,
177
 
                          'set_rh', 'breezy.tests.test_hooks', 'TestHooks.set_rh',
178
 
                          "demo")
 
175
            hooks.install_named_hook_lazy,
 
176
            'set_rh', 'breezy.tests.test_hooks', 'TestHooks.set_rh',
 
177
            "demo")
179
178
 
180
179
    def test_valid_lazy_hooks(self):
181
180
        # Make sure that all the registered lazy hooks are referring to existing
193
192
 
194
193
    def test___init__(self):
195
194
        doc = ("Invoked after changing the tip of a branch object. Called with"
196
 
               "a breezy.branch.PostChangeBranchTipParams object")
 
195
            "a breezy.branch.PostChangeBranchTipParams object")
197
196
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
198
197
        self.assertEqual(doc, hook.__doc__)
199
198
        self.assertEqual("post_tip_change", hook.name)
203
202
 
204
203
    def test_docs(self):
205
204
        doc = ("Invoked after changing the tip of a branch object. Called with"
206
 
               " a breezy.branch.PostChangeBranchTipParams object")
 
205
            " a breezy.branch.PostChangeBranchTipParams object")
207
206
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
208
207
        self.assertEqual("post_tip_change\n"
209
 
                         "~~~~~~~~~~~~~~~\n"
210
 
                         "\n"
211
 
                         "Introduced in: 0.15\n"
212
 
                         "\n"
213
 
                         "Invoked after changing the tip of a branch object. Called with a\n"
214
 
                         "breezy.branch.PostChangeBranchTipParams object\n", hook.docs())
 
208
            "~~~~~~~~~~~~~~~\n"
 
209
            "\n"
 
210
            "Introduced in: 0.15\n"
 
211
            "\n"
 
212
            "Invoked after changing the tip of a branch object. Called with a\n"
 
213
            "breezy.branch.PostChangeBranchTipParams object\n", hook.docs())
215
214
 
216
215
    def test_hook(self):
217
216
        hook = HookPoint("foo", "no docs", None, None)
218
 
 
219
217
        def callback():
220
218
            pass
221
219
        hook.hook(callback, "my callback")
247
245
    def test___repr(self):
248
246
        # The repr should list all the callbacks, with names.
249
247
        hook = HookPoint("foo", "no docs", None, None)
250
 
 
251
248
        def callback():
252
249
            pass
253
250
        hook.hook(callback, "my callback")
267
264
        # isolation and prevent tests failing spuriously.
268
265
        for key, factory in known_hooks.items():
269
266
            self.assertTrue(callable(factory),
270
 
                            "The factory(%r) for %r is not callable" % (factory, key))
 
267
                "The factory(%r) for %r is not callable" % (factory, key))
271
268
            obj = known_hooks_key_to_object(key)
272
269
            self.assertIsInstance(obj, Hooks)
273
270
            new_hooks = factory()
277
274
 
278
275
    def test_known_hooks_key_to_object(self):
279
276
        self.assertIs(branch.Branch.hooks,
280
 
                      known_hooks_key_to_object(('breezy.branch', 'Branch.hooks')))
 
277
            known_hooks_key_to_object(('breezy.branch', 'Branch.hooks')))
281
278
 
282
279
    def test_known_hooks_key_to_parent_and_attribute(self):
283
280
        self.assertEqual((branch.Branch, 'hooks'),
284
 
                         known_hooks.key_to_parent_and_attribute(
 
281
            known_hooks.key_to_parent_and_attribute(
285
282
            ('breezy.branch', 'Branch.hooks')))
286
283
        self.assertEqual((branch, 'Branch'),
287
 
                         known_hooks.key_to_parent_and_attribute(
 
284
            known_hooks.key_to_parent_and_attribute(
288
285
            ('breezy.branch', 'Branch')))