<s> import os <EOL> import sys <EOL> from zipimport import zipimporter <EOL> from django . utils import unittest <EOL> from django . utils . importlib import import_module <EOL> from django . utils . module_loading import module_has_submodule <EOL> class DefaultLoader ( unittest . TestCase ) : <EOL> def test_loader ( self ) : <EOL> "<STR_LIT>" <EOL> test_module = import_module ( '<STR_LIT>' ) <EOL> self . assertTrue ( module_has_submodule ( test_module , '<STR_LIT>' ) ) <EOL> mod = import_module ( '<STR_LIT>' ) <EOL> self . assertEqual ( mod . content , '<STR_LIT>' ) <EOL> self . assertTrue ( module_has_submodule ( test_module , '<STR_LIT>' ) ) <EOL> self . assertRaises ( ImportError , import_module , '<STR_LIT>' ) <EOL> self . assertFalse ( module_has_submodule ( test_module , '<STR_LIT>' ) ) <EOL> self . assertRaises ( ImportError , import_module , '<STR_LIT>' ) <EOL> import types <EOL> self . assertFalse ( module_has_submodule ( sys . modules [ '<STR_LIT>' ] , '<STR_LIT>' ) ) <EOL> class EggLoader ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . old_path = sys . path [ : ] <EOL> self . egg_dir = '<STR_LIT>' % os . path . dirname ( __file__ ) <EOL> def tearDown ( self ) : <EOL> sys . path = self . old_path <EOL> sys . path_importer_cache . clear ( ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> sys . modules . pop ( '<STR_LIT>' , None ) <EOL> def test_shallow_loader ( self ) : <EOL> "<STR_LIT>" <EOL> egg_name = '<STR_LIT>' % self . egg_dir <EOL> sys . path . append ( egg_name ) <EOL> egg_module = import_module ( '<STR_LIT>' ) <EOL> self . assertTrue ( module_has_submodule ( egg_module , '<STR_LIT>' ) ) <EOL> mod = import_module ( '<STR_LIT>' ) <EOL> self . assertEqual ( mod . content , '<STR_LIT>' ) <EOL> self . assertTrue ( module_has_submodule ( egg_module , '<STR_LIT>' ) ) <EOL> self . assertRaises ( ImportError , import_module , '<STR_LIT>' ) <EOL> self . assertFalse ( module_has_submodule ( egg_module , '<STR_LIT>' ) ) <EOL> self . assertRaises ( ImportError , import_module , '<STR_LIT>' ) <EOL> def test_deep_loader ( self ) : <EOL> "<STR_LIT>" <EOL> egg_name = '<STR_LIT>' % self . egg_dir <EOL> sys . path . append ( egg_name ) <EOL> egg_module = import_module ( '<STR_LIT>' ) <EOL> self . assertTrue ( module_has_submodule ( egg_module , '<STR_LIT>' ) ) <EOL> mod = import_module ( '<STR_LIT>' ) <EOL> self . assertEqual ( mod . content , '<STR_LIT>' ) <EOL> self . assertTrue ( module_has_submodule ( egg_module , '<STR_LIT>' ) ) <EOL> self . assertRaises ( ImportError , import_module , '<STR_LIT>' ) <EOL> self . assertFalse ( module_has_submodule ( egg_module , '<STR_LIT>' ) ) <EOL> self . assertRaises ( ImportError , import_module , '<STR_LIT>' ) <EOL> class TestFinder ( object ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . importer = zipimporter ( * args , ** kwargs ) <EOL> def find_module ( self , path ) : <EOL> importer = self . importer . find_module ( path ) <EOL> if importer is None : <EOL> return <EOL> return TestLoader ( importer ) <EOL> class TestLoader ( object ) : <EOL> def __init__ ( self , importer ) : <EOL> self . importer = importer <EOL> def load_module ( self , name ) : <EOL> mod = self . importer . load_module ( name ) <EOL> mod . __loader__ = self <EOL> return mod <EOL> class CustomLoader ( EggLoader ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( CustomLoader , self ) . setUp ( ) <EOL> sys . path_hooks . insert ( <NUM_LIT:0> , TestFinder ) <EOL> sys . path_importer_cache . clear ( ) <EOL> def tearDown ( self ) : <EOL> super ( CustomLoader , self ) . tearDown ( ) <EOL> sys . path_hooks . pop ( <NUM_LIT:0> ) </s>
