~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-10-15 11:29:38 UTC
  • mfrom: (5499.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101015112938-8585tdgvnin38kfv
(vila) Add bzrlib/pyutils.py,
        and replace uses of __import__ with calls to pyutils.get_named_object
        (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
    lock as _mod_lock,
72
72
    memorytree,
73
73
    osutils,
 
74
    pyutils,
74
75
    ui,
75
76
    urlutils,
76
77
    registry,
897
898
 
898
899
    def _clear_hooks(self):
899
900
        # prevent hooks affecting tests
 
901
        known_hooks = hooks.known_hooks
900
902
        self._preserved_hooks = {}
901
 
        for key, factory in hooks.known_hooks.items():
902
 
            parent, name = hooks.known_hooks_key_to_parent_and_attribute(key)
903
 
            current_hooks = hooks.known_hooks_key_to_object(key)
 
903
        for key, (parent, name) in known_hooks.iter_parent_objects():
 
904
            current_hooks = getattr(parent, name)
904
905
            self._preserved_hooks[parent] = (name, current_hooks)
905
906
        self.addCleanup(self._restoreHooks)
906
 
        for key, factory in hooks.known_hooks.items():
907
 
            parent, name = hooks.known_hooks_key_to_parent_and_attribute(key)
 
907
        for key, (parent, name) in known_hooks.iter_parent_objects():
 
908
            factory = known_hooks.get(key)
908
909
            setattr(parent, name, factory())
909
910
        # this hook should always be installed
910
911
        request._install_hook()
3761
3762
        'bzrlib.tests.test_permissions',
3762
3763
        'bzrlib.tests.test_plugins',
3763
3764
        'bzrlib.tests.test_progress',
 
3765
        'bzrlib.tests.test_pyutils',
3764
3766
        'bzrlib.tests.test_read_bundle',
3765
3767
        'bzrlib.tests.test_reconcile',
3766
3768
        'bzrlib.tests.test_reconfigure',
3845
3847
        'bzrlib.lockdir',
3846
3848
        'bzrlib.merge3',
3847
3849
        'bzrlib.option',
 
3850
        'bzrlib.pyutils',
3848
3851
        'bzrlib.symbol_versioning',
3849
3852
        'bzrlib.tests',
3850
3853
        'bzrlib.tests.fixtures',
4100
4103
        the module is available.
4101
4104
    """
4102
4105
 
4103
 
    py_module = __import__(py_module_name, {}, {}, ['NO_SUCH_ATTRIB'])
 
4106
    py_module = pyutils.get_named_object(py_module_name)
4104
4107
    scenarios = [
4105
4108
        ('python', {'module': py_module}),
4106
4109
    ]
4259
4262
            symbol_versioning.warn(depr_msg + use_msg, DeprecationWarning)
4260
4263
            # Import the new feature and use it as a replacement for the
4261
4264
            # deprecated one.
4262
 
            mod = __import__(self._replacement_module, {}, {},
4263
 
                             [self._replacement_name])
4264
 
            self._feature = getattr(mod, self._replacement_name)
 
4265
            self._feature = pyutils.get_named_object(
 
4266
                self._replacement_module, self._replacement_name)
4265
4267
 
4266
4268
    def _probe(self):
4267
4269
        self._ensure()