~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hooks.py

  • Committer: Jelmer Vernooij
  • Date: 2011-03-03 03:06:48 UTC
  • mto: (5622.4.1 uninstall-hook)
  • mto: This revision was merged to the branch mainline in revision 5747.
  • Revision ID: jelmer@samba.org-20110303030648-06dllv908l39me1b
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
class TestHooks(tests.TestCase):
40
40
 
41
41
    def test_create_hook_first(self):
42
 
        hooks = Hooks()
 
42
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
43
43
        doc = ("Invoked after changing the tip of a branch object. Called with"
44
44
            "a bzrlib.branch.PostChangeBranchTipParams object")
45
45
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
47
47
        self.assertEqual(hook, hooks['post_tip_change'])
48
48
 
49
49
    def test_create_hook_name_collision_errors(self):
50
 
        hooks = Hooks()
 
50
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
51
51
        doc = ("Invoked after changing the tip of a branch object. Called with"
52
52
            "a bzrlib.branch.PostChangeBranchTipParams object")
53
53
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
60
60
        """docs() should return something reasonable about the Hooks."""
61
61
        class MyHooks(Hooks):
62
62
            pass
63
 
        hooks = MyHooks()
 
63
        hooks = MyHooks("bzrlib.tests.test_hooks", "some_hooks")
64
64
        hooks['legacy'] = []
65
65
        hook1 = HookPoint('post_tip_change',
66
66
            "Invoked after the tip of a branch changes. Called with "
99
99
            "signal that a tip change is not permitted.\n", hooks.docs())
100
100
 
101
101
    def test_install_named_hook_raises_unknown_hook(self):
102
 
        hooks = Hooks()
 
102
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
103
103
        self.assertRaises(errors.UnknownHook, hooks.install_named_hook, 'silly',
104
104
                          None, "")
105
105
 
106
106
    def test_install_named_hook_appends_known_hook(self):
107
 
        hooks = Hooks()
 
107
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
108
108
        hooks['set_rh'] = []
109
109
        hooks.install_named_hook('set_rh', None, "demo")
110
110
        self.assertEqual(hooks['set_rh'], [None])
111
111
 
112
112
    def test_install_named_hook_and_retrieve_name(self):
113
 
        hooks = Hooks()
 
113
        hooks = Hooks("bzrlib.tests.test_hooks", "somehooks")
114
114
        hooks['set_rh'] = []
115
115
        hooks.install_named_hook('set_rh', None, "demo")
116
116
        self.assertEqual("demo", hooks.get_hook_name(None))
134
134
    set_rh = lambda: None
135
135
 
136
136
    def test_install_named_hook_lazy(self):
137
 
        hooks = Hooks()
 
137
        hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
138
138
        hooks['set_rh'] = HookPoint("set_rh", "doc", (0, 15), None)
139
139
        hooks.install_named_hook_lazy('set_rh', 'bzrlib.tests.test_hooks',
140
140
            'TestHooks.set_rh', "demo")
143
143
    def test_install_named_hook_lazy_old(self):
144
144
        # An exception is raised if a lazy hook is raised for
145
145
        # an old style hook point.
146
 
        hooks = Hooks()
 
146
        hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
147
147
        hooks['set_rh'] = []
148
148
        self.assertRaises(errors.UnsupportedOperation,
149
149
            hooks.install_named_hook_lazy,
228
228
                "The factory(%r) for %r is not callable" % (factory, key))
229
229
            obj = known_hooks_key_to_object(key)
230
230
            self.assertIsInstance(obj, Hooks)
231
 
            new_hooks = factory()
 
231
            new_hooks = factory(key[0], key[1])
232
232
            self.assertIsInstance(obj, Hooks)
233
233
            self.assertEqual(type(obj), type(new_hooks))
234
234
            self.assertEqual("No hook name", new_hooks.get_hook_name(None))