def test_import_hooks_importer():
 global myimpCalled
 myimpCalled = None
 class myimp(object, ):
  def find_module(self, fullname, path=None):
   global myimpCalled
   myimpCalled = (fullname, path)
   if (fullname == 'does_not_exist_throw'):
    raise Exception('hello')
 mi = myimp()
 sys.meta_path.append(mi)
 try:
  try:
   import does_not_exist
   AssertUnreachable()
  except ImportError:
   pass
  AreEqual(myimpCalled, ('does_not_exist', None))
  try:
   from testpkg1 import blah
   AssertUnreachable()
  except ImportError:
   pass
  AreEqual(type(myimpCalled[1]), list)
  AreEqual(myimpCalled[0], 'testpkg1.blah')
  AreEqual(myimpCalled[1][0][(-8):], 'testpkg1')
  def f():
   import does_not_exist_throw
  AssertErrorWithMessage(Exception, 'hello', f)
 finally:
  sys.meta_path.remove(mi)

def test_import_hooks_importer ( ) : global myimpCalled myimpCalled = None class myimp ( object , ) : def find_module ( self , fullname , path = None ) : global myimpCalled myimpCalled = ( fullname , path ) if ( fullname == 'does_not_exist_throw' ) : raise Exception ( 'hello' ) mi = myimp ( ) sys . meta_path . append ( mi ) try : try : import does_not_exist AssertUnreachable ( ) except ImportError : pass AreEqual ( myimpCalled , ( 'does_not_exist' , None ) ) try : from testpkg1 import blah AssertUnreachable ( ) except ImportError : pass AreEqual ( type ( myimpCalled [ 1 ] ) , list ) AreEqual ( myimpCalled [ 0 ] , 'testpkg1.blah' ) AreEqual ( myimpCalled [ 1 ] [ 0 ] [ ( - 8 ) : ] , 'testpkg1' ) def f ( ) : import does_not_exist_throw AssertErrorWithMessage ( Exception , 'hello' , f ) finally : sys . meta_path . remove ( mi )
importer tests - verify the importer gets passed correct values .