~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hooks.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    install_lazy_named_hook,
30
30
    known_hooks,
31
31
    known_hooks_key_to_object,
32
 
    known_hooks_key_to_parent_and_attribute,
33
32
    )
34
33
from bzrlib.symbol_versioning import (
35
34
    deprecated_in,
38
37
 
39
38
class TestHooks(tests.TestCase):
40
39
 
41
 
    def test_create_hook_first(self):
42
 
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
43
 
        doc = ("Invoked after changing the tip of a branch object. Called with"
44
 
            "a bzrlib.branch.PostChangeBranchTipParams object")
45
 
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
46
 
        self.applyDeprecated(deprecated_in((2, 4)), hooks.create_hook, hook)
47
 
        self.assertEqual(hook, hooks['post_tip_change'])
48
 
 
49
 
    def test_create_hook_name_collision_errors(self):
50
 
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
51
 
        doc = ("Invoked after changing the tip of a branch object. Called with"
52
 
            "a bzrlib.branch.PostChangeBranchTipParams object")
53
 
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
54
 
        hook2 = HookPoint("post_tip_change", None, None, None)
55
 
        self.applyDeprecated(deprecated_in((2, 4)), hooks.create_hook, hook)
56
 
        self.assertRaises(errors.DuplicateKey, self.applyDeprecated,
57
 
            deprecated_in((2, 4, 0)), hooks.create_hook, hook2)
58
 
        self.assertEqual(hook, hooks['post_tip_change'])
59
 
 
60
40
    def test_docs(self):
61
41
        """docs() should return something reasonable about the Hooks."""
62
42
        class MyHooks(Hooks):
162
142
            'TestHooks.hooks', 'set_rh', set_rh, "demo")
163
143
        set_rh_lazy_hooks = _mod_hooks._lazy_hooks[
164
144
            ('bzrlib.tests.test_hooks', 'TestHooks.hooks', 'set_rh')]
165
 
        self.assertEquals(1, len(set_rh_lazy_hooks))
166
 
        self.assertEquals(set_rh, set_rh_lazy_hooks[0][0].get_obj())
167
 
        self.assertEquals("demo", set_rh_lazy_hooks[0][1])
 
145
        self.assertEqual(1, len(set_rh_lazy_hooks))
 
146
        self.assertEqual(set_rh, set_rh_lazy_hooks[0][0].get_obj())
 
147
        self.assertEqual("demo", set_rh_lazy_hooks[0][1])
168
148
        self.assertEqual(list(TestHooks.hooks['set_rh']), [set_rh])
169
149
 
170
150
    set_rh = lambda: None
192
172
        for key, callbacks in _mod_hooks._lazy_hooks.iteritems():
193
173
            (module_name, member_name, hook_name) = key
194
174
            obj = pyutils.get_named_object(module_name, member_name)
195
 
            self.assertEquals(obj._module, module_name)
196
 
            self.assertEquals(obj._member_name, member_name)
 
175
            self.assertEqual(obj._module, module_name)
 
176
            self.assertEqual(obj._member_name, member_name)
197
177
            self.assertTrue(hook_name in obj)
198
178
            self.assertIs(callbacks, obj[hook_name]._callbacks)
199
179
 
286
266
        self.assertIs(branch.Branch.hooks,
287
267
            known_hooks_key_to_object(('bzrlib.branch', 'Branch.hooks')))
288
268
 
289
 
    def test_known_hooks_key_to_parent_and_attribute_deprecated(self):
290
 
        self.assertEqual((branch.Branch, 'hooks'),
291
 
            self.applyDeprecated(deprecated_in((2,3)),
292
 
                known_hooks_key_to_parent_and_attribute,
293
 
                ('bzrlib.branch', 'Branch.hooks')))
294
 
        self.assertEqual((branch, 'Branch'),
295
 
            self.applyDeprecated(deprecated_in((2,3)),
296
 
                known_hooks_key_to_parent_and_attribute,
297
 
                ('bzrlib.branch', 'Branch')))
298
 
 
299
269
    def test_known_hooks_key_to_parent_and_attribute(self):
300
270
        self.assertEqual((branch.Branch, 'hooks'),
301
271
            known_hooks.key_to_parent_and_attribute(