~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-11 20:03:50 UTC
  • mto: This revision was merged to the branch mainline in revision 2004.
  • Revision ID: john@arbash-meinel.com-20060911200350-e4f917892ea062f2
Test that we can lazy import a module, and its children

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
            import foo => name='foo' module_path='foo',
105
105
                          member=None, children=[]
106
106
            import foo.bar => name='foo' module_path='foo', member=None,
107
 
                              children=[('bar', 'foo.bar', [])]
 
107
                              children=[('bar', ['foo', 'bar'], [])]
108
108
            from foo import bar => name='bar' module_path='foo', member='bar'
109
109
                                   children=[]
110
110
            from foo import bar, baz would get translated into 2 import
139
139
 
140
140
        # Prepare the children to be imported
141
141
        for child_name, child_path, grandchildren in children:
142
 
            ImportReplacer(module.__dict__, name=child_name,
143
 
                           module_path=child_path, member=None,
144
 
                           children=grandchildren)
 
142
            # Using self.__class__, so that children get children classes
 
143
            # instantiated. (This helps with instrumented tests)
 
144
            cls = object.__getattribute__(self, '__class__')
 
145
            cls(module.__dict__, name=child_name,
 
146
                module_path=child_path, member=None,
 
147
                children=grandchildren)
145
148
        return module