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

  • Committer: Martin Pool
  • Date: 2009-03-13 03:01:14 UTC
  • mfrom: (4138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4144.
  • Revision ID: mbp@sourcefrog.net-20090313030114-y723gefxl8tfynsd
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the core Hooks logic."""
18
18
 
19
 
from bzrlib import errors
 
19
from bzrlib import branch, errors
20
20
from bzrlib.hooks import (
21
21
    HookPoint,
22
22
    Hooks,
 
23
    known_hooks,
 
24
    known_hooks_key_to_object,
 
25
    known_hooks_key_to_parent_and_attribute,
23
26
    )
24
27
from bzrlib.errors import (
25
28
    UnknownHook,
67
70
        hooks.create_hook(hook2)
68
71
        self.assertEqualDiff(
69
72
            "MyHooks\n"
70
 
            "=======\n"
 
73
            "-------\n"
71
74
            "\n"
72
75
            "legacy\n"
73
 
            "------\n"
 
76
            "~~~~~~\n"
74
77
            "\n"
75
78
            "An old-style hook. For documentation see the __init__ method of 'MyHooks'\n"
76
79
            "\n"
77
80
            "post_tip_change\n"
78
 
            "---------------\n"
 
81
            "~~~~~~~~~~~~~~~\n"
79
82
            "\n"
80
83
            "Introduced in: 1.4\n"
81
84
            "Deprecated in: Not deprecated\n"
84
87
            "ChangeBranchTipParams object.\n"
85
88
            "\n"
86
89
            "pre_tip_change\n"
87
 
            "--------------\n"
 
90
            "~~~~~~~~~~~~~~\n"
88
91
            "\n"
89
92
            "Introduced in: 1.6\n"
90
93
            "Deprecated in: Not deprecated\n"
155
158
            " a bzrlib.branch.PostChangeBranchTipParams object")
156
159
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
157
160
        self.assertEqual("post_tip_change\n"
158
 
            "---------------\n"
 
161
            "~~~~~~~~~~~~~~~\n"
159
162
            "\n"
160
163
            "Introduced in: 0.15\n"
161
164
            "Deprecated in: Not deprecated\n"
180
183
        self.assertEqual(
181
184
            '<HookPoint(foo), callbacks=[%s(my callback)]>' %
182
185
            callback_repr, repr(hook))
 
186
 
 
187
 
 
188
class TestHookRegistry(TestCase):
 
189
 
 
190
    def test_items_are_reasonable_keys(self):
 
191
        # All the items in the known_hooks registry need to map from
 
192
        # (module_name, member_name) tuples to the callable used to get an
 
193
        # empty Hooks of for that attribute. This is used to support the test
 
194
        # suite which needs to generate empty hooks (and HookPoints) to ensure
 
195
        # isolation and prevent tests failing spuriously.
 
196
        for key, factory in known_hooks.items():
 
197
            self.assertTrue(callable(factory),
 
198
                "The factory(%r) for %r is not callable" % (factory, key))
 
199
            obj = known_hooks_key_to_object(key)
 
200
            self.assertIsInstance(obj, Hooks)
 
201
            new_hooks = factory()
 
202
            self.assertIsInstance(obj, Hooks)
 
203
            self.assertEqual(type(obj), type(new_hooks))
 
204
 
 
205
    def test_known_hooks_key_to_object(self):
 
206
        self.assertIs(branch.Branch.hooks,
 
207
            known_hooks_key_to_object(('bzrlib.branch', 'Branch.hooks')))
 
208
 
 
209
    def test_known_hooks_key_to_parent_and_attribute(self):
 
210
        self.assertEqual((branch.Branch, 'hooks'),
 
211
            known_hooks_key_to_parent_and_attribute(
 
212
            ('bzrlib.branch', 'Branch.hooks')))
 
213
        self.assertEqual((branch, 'Branch'),
 
214
            known_hooks_key_to_parent_and_attribute(
 
215
            ('bzrlib.branch', 'Branch')))