/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_lazy_import.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Test the lazy_import functionality."""
18
18
 
107
107
 
108
108
    def test_object(self):
109
109
        """ScopeReplacer can create an instance in local scope.
110
 
        
 
110
 
111
111
        An object should appear in globals() by constructing a ScopeReplacer,
112
112
        and it will be replaced with the real object upon the first request.
113
113
        """
351
351
                         object.__getattribute__(test_obj2, '__class__'))
352
352
        self.assertEqual(InstrumentedReplacer,
353
353
                         object.__getattribute__(test_obj3, '__class__'))
354
 
        
 
354
 
355
355
        # The first use of the alternate variable causes test_obj2 to
356
356
        # be replaced.
357
357
        self.assertEqual('foo', test_obj3.foo(1))
369
369
        # because only now are we able to detect the problem.
370
370
        self.assertRaises(errors.IllegalUseOfScopeReplacer,
371
371
                          getattr, test_obj3, 'foo')
372
 
        
 
372
 
373
373
        self.assertEqual([('__getattribute__', 'foo'),
374
374
                          '_replace',
375
375
                          'factory',
452
452
        self.actions = []
453
453
        InstrumentedImportReplacer.use_actions(self.actions)
454
454
 
 
455
        sys.path.append(base_path)
 
456
        self.addCleanup(sys.path.remove, base_path)
 
457
 
455
458
        original_import = __import__
456
459
        def instrumented_import(mod, scope1, scope2, fromlist):
457
460
            self.actions.append(('import', mod, fromlist))
458
461
            return original_import(mod, scope1, scope2, fromlist)
459
 
 
460
462
        def cleanup():
461
 
            if base_path in sys.path:
462
 
                sys.path.remove(base_path)
463
463
            __builtins__['__import__'] = original_import
464
464
        self.addCleanup(cleanup)
465
 
        sys.path.append(base_path)
466
465
        __builtins__['__import__'] = instrumented_import
467
466
 
468
467
    def create_modules(self):