#NEWLINE# def testZipImporterMethods( self ) : #NEWLINE# #INDENT# packdir = ( TESTPACK + os . sep ) #NEWLINE# packdir2 = ( ( packdir + TESTPACK2 ) + os . sep ) #NEWLINE# files = { #NEWLINE# #INDENT# ( ( packdir + '__init__' ) + pyc_ext ) : ( NOW , test_pyc ) , #NEWLINE# ( ( packdir2 + '__init__' ) + pyc_ext ) : ( NOW , test_pyc ) , #NEWLINE# ( ( packdir2 + TESTMOD ) + pyc_ext ) : ( NOW , test_pyc ) , #NEWLINE# #UNINDENT# } #NEWLINE# z = ZipFile ( TEMP_ZIP , 'w' ) #NEWLINE# try : #NEWLINE# #INDENT# for ( name , ( mtime , data ) ) in files . items ( ) : #NEWLINE# #INDENT# zinfo = ZipInfo ( name , time . localtime ( mtime ) ) #NEWLINE# zinfo . compress_type = self . compression #NEWLINE# z . writestr ( packdir2 , data ) #NEWLINE# #UNINDENT# z . close ( ) #NEWLINE# zi = zipimport . zipimporter ( TEMP_ZIP ) #NEWLINE# self . assertEqual ( zi . archive , TEMP_ZIP ) #NEWLINE# self . assertEqual ( zi . is_package ( TESTPACK ) , True ) #NEWLINE# mod = zi . load_module ( TESTPACK ) #NEWLINE# self . assertEqual ( zi . get_filename ( TESTPACK ) , mod . __file__ ) #NEWLINE# existing_pack_path = __import__ ( TESTPACK ) . __path__ [ 0 ] #NEWLINE# expected_path_path = os . path . join ( TEMP_ZIP , TESTPACK ) #NEWLINE# self . assertEqual ( existing_pack_path , expected_path_path ) #NEWLINE# self . assertEqual ( zi . is_package ( ( packdir + '__init__' ) ) , False ) #NEWLINE# self . assertEqual ( zi . is_package ( ( packdir + TESTPACK2 ) ) , True ) #NEWLINE# self . assertEqual ( zi . is_package ( ( packdir2 + TESTMOD ) ) , False ) #NEWLINE# mod_path = ( packdir2 + TESTMOD ) #NEWLINE# mod_name = module_path_to_dotted_name ( mod_path ) #NEWLINE# __import__ ( mod_name ) #NEWLINE# mod = sys . modules [ mod_name ] #NEWLINE# self . assertEqual ( zi . get_source ( TESTPACK ) , None ) #NEWLINE# self . assertEqual ( zi . get_source ( mod_path ) , None ) #NEWLINE# self . assertEqual ( zi . get_filename ( mod_path ) , mod . __file__ ) #NEWLINE# loader = mod . __loader__ #NEWLINE# self . assertEqual ( loader . get_source ( mod_name ) , None ) #NEWLINE# self . assertEqual ( loader . get_filename ( mod_name ) , mod . __file__ ) #NEWLINE# zi2 = zipimport . zipimporter ( ( ( TEMP_ZIP + os . sep ) + TESTPACK ) ) #NEWLINE# self . assertEqual ( zi2 . archive , TEMP_ZIP ) #NEWLINE# self . assertEqual ( zi2 . prefix , ( TESTPACK + os . sep ) ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# z . close ( ) #NEWLINE# os . remove ( TEMP_ZIP )