~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hooks.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-20 09:28:27 UTC
  • mfrom: (5050.78.2 2.2)
  • mto: (5609.48.8 2.3)
  • mto: This revision was merged to the branch mainline in revision 6090.
  • Revision ID: v.ladeuil+lp@free.fr-20110820092827-9dyakfslp0r3hb1k
Merge 2.2 into 2.3 (including fix for #614713, #609187 and #812928)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
16
16
 
17
17
"""Tests for the core Hooks logic."""
18
18
 
19
 
from bzrlib import branch, errors
 
19
from bzrlib import (
 
20
    branch,
 
21
    errors,
 
22
    tests,
 
23
    )
20
24
from bzrlib.hooks import (
21
25
    HookPoint,
22
26
    Hooks,
24
28
    known_hooks_key_to_object,
25
29
    known_hooks_key_to_parent_and_attribute,
26
30
    )
27
 
from bzrlib.errors import (
28
 
    UnknownHook,
 
31
from bzrlib.symbol_versioning import (
 
32
    deprecated_in,
29
33
    )
30
34
 
31
 
from bzrlib.tests import TestCase
32
 
 
33
 
 
34
 
class TestHooks(TestCase):
 
35
 
 
36
class TestHooks(tests.TestCase):
35
37
 
36
38
    def test_create_hook_first(self):
37
39
        hooks = Hooks()
80
82
            "~~~~~~~~~~~~~~~\n"
81
83
            "\n"
82
84
            "Introduced in: 1.4\n"
83
 
            "Deprecated in: Not deprecated\n"
84
85
            "\n"
85
86
            "Invoked after the tip of a branch changes. Called with a\n"
86
87
            "ChangeBranchTipParams object.\n"
89
90
            "~~~~~~~~~~~~~~\n"
90
91
            "\n"
91
92
            "Introduced in: 1.6\n"
92
 
            "Deprecated in: Not deprecated\n"
93
93
            "\n"
94
94
            "Invoked before the tip of a branch changes. Called with a\n"
95
95
            "ChangeBranchTipParams object. Hooks should raise TipChangeRejected to\n"
97
97
 
98
98
    def test_install_named_hook_raises_unknown_hook(self):
99
99
        hooks = Hooks()
100
 
        self.assertRaises(UnknownHook, hooks.install_named_hook, 'silly',
 
100
        self.assertRaises(errors.UnknownHook, hooks.install_named_hook, 'silly',
101
101
                          None, "")
102
102
 
103
103
    def test_install_named_hook_appends_known_hook(self):
113
113
        self.assertEqual("demo", hooks.get_hook_name(None))
114
114
 
115
115
 
116
 
class TestHook(TestCase):
 
116
class TestHook(tests.TestCase):
117
117
 
118
118
    def test___init__(self):
119
119
        doc = ("Invoked after changing the tip of a branch object. Called with"
133
133
            "~~~~~~~~~~~~~~~\n"
134
134
            "\n"
135
135
            "Introduced in: 0.15\n"
136
 
            "Deprecated in: Not deprecated\n"
137
136
            "\n"
138
137
            "Invoked after changing the tip of a branch object. Called with a\n"
139
138
            "bzrlib.branch.PostChangeBranchTipParams object\n", hook.docs())
157
156
            callback_repr, repr(hook))
158
157
 
159
158
 
160
 
class TestHookRegistry(TestCase):
 
159
class TestHookRegistry(tests.TestCase):
161
160
 
162
161
    def test_items_are_reasonable_keys(self):
163
162
        # All the items in the known_hooks registry need to map from
173
172
            new_hooks = factory()
174
173
            self.assertIsInstance(obj, Hooks)
175
174
            self.assertEqual(type(obj), type(new_hooks))
 
175
            self.assertEqual("No hook name", new_hooks.get_hook_name(None))
176
176
 
177
177
    def test_known_hooks_key_to_object(self):
178
178
        self.assertIs(branch.Branch.hooks,
179
179
            known_hooks_key_to_object(('bzrlib.branch', 'Branch.hooks')))
180
180
 
 
181
    def test_known_hooks_key_to_parent_and_attribute_deprecated(self):
 
182
        self.assertEqual((branch.Branch, 'hooks'),
 
183
            self.applyDeprecated(deprecated_in((2,3)),
 
184
                known_hooks_key_to_parent_and_attribute,
 
185
                ('bzrlib.branch', 'Branch.hooks')))
 
186
        self.assertEqual((branch, 'Branch'),
 
187
            self.applyDeprecated(deprecated_in((2,3)),
 
188
                known_hooks_key_to_parent_and_attribute,
 
189
                ('bzrlib.branch', 'Branch')))
 
190
 
181
191
    def test_known_hooks_key_to_parent_and_attribute(self):
182
192
        self.assertEqual((branch.Branch, 'hooks'),
183
 
            known_hooks_key_to_parent_and_attribute(
 
193
            known_hooks.key_to_parent_and_attribute(
184
194
            ('bzrlib.branch', 'Branch.hooks')))
185
195
        self.assertEqual((branch, 'Branch'),
186
 
            known_hooks_key_to_parent_and_attribute(
 
196
            known_hooks.key_to_parent_and_attribute(
187
197
            ('bzrlib.branch', 'Branch')))