~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hooks.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    known_hooks_key_to_object,
29
29
    known_hooks_key_to_parent_and_attribute,
30
30
    )
 
31
from bzrlib.symbol_versioning import (
 
32
    deprecated_in,
 
33
    )
31
34
 
32
35
 
33
36
class TestHooks(tests.TestCase):
175
178
        self.assertIs(branch.Branch.hooks,
176
179
            known_hooks_key_to_object(('bzrlib.branch', 'Branch.hooks')))
177
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
 
178
191
    def test_known_hooks_key_to_parent_and_attribute(self):
179
192
        self.assertEqual((branch.Branch, 'hooks'),
180
 
            known_hooks_key_to_parent_and_attribute(
 
193
            known_hooks.key_to_parent_and_attribute(
181
194
            ('bzrlib.branch', 'Branch.hooks')))
182
195
        self.assertEqual((branch, 'Branch'),
183
 
            known_hooks_key_to_parent_and_attribute(
 
196
            known_hooks.key_to_parent_and_attribute(
184
197
            ('bzrlib.branch', 'Branch')))