ó {G_Tc@søddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZmZmZmZmZmZmZddlmZddlmZd„Zd„Zd„Zde jfd „ƒYZd e jfd „ƒYZd e jfd „ƒYZde jfd„ƒYZde jfd„ƒYZ e!d„Z"e#dkr“ddl$m"Z"e"ƒndS(i’’’’N(tunlinktTESTFNtunloadt run_unittesttrmtreet is_jythontcheck_warningstEnvironmentVarGuard(tsymlink_support(t script_helpercCsC|tjd|tjd|tjd|tjd|dfS(Ntpytpyctpyotpyws $py.class(tostextsep(tname((s,/usr/local/lib/python2.7/test/test_import.pyt_filess cCs]xVt|ƒD]H}ytj|dƒWq tk rT}|jtjkrU‚qUq Xq WdS(Ni€(RRtchmodtOSErrorterrnotENOENT(Rtftexc((s,/usr/local/lib/python2.7/test/test_import.pyt chmod_filess cCs%xt|ƒD]}t|ƒq WdS(N(RR(RR((s,/usr/local/lib/python2.7/test/test_import.pyt remove_files"st ImportTestscBsųeZd„ZeZd„Zd„Zd„Zeje j dkdƒej e j dƒd„ƒƒZej e j dƒd„ƒZd „Zd d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsttƒdS(N(RR(tself((s,/usr/local/lib/python2.7/test/test_import.pyttearDown)scCs5yddl}Wntk r#nX|jdƒdS(Ni’’’’s3import of RAnDoM should have failed (case mismatch)(tRAnDoMt ImportErrortfail(RR((s,/usr/local/lib/python2.7/test/test_import.pyttest_case_sensitivity-s  cCsddlm}dS(Ni’’’’(t double_const(ttestR!(RR!((s,/usr/local/lib/python2.7/test/test_import.pyttest_double_const7scsއfd†}tjjdtjƒzW|tjdƒtjjdƒr{x-ddddd d gD]}||ƒqdWnWdtjd=XdS( Nc s™t|}ttjd}tr.td}nttjd}t|dƒX}|d|dfIJtjdƒ}tjdƒ}|dI|IJ|d I|IJWdQXzuyttƒ}Wn*tk rē}ˆj d ||fƒn5Xˆj |j |d |ƒˆj |j |d |ƒWdt |ƒXzHytjsJtj|ƒnWn$tk rq}ˆj d |ƒnXWdt |ƒt |ƒttƒXdS( NR s $py.classR tws)# This tests Python's ability to import asfile.ičsa =sb =simport from %s failed: %ss'module loaded (%s) but contents invalids import from .pyc/.pyo failed: %s(RRRRtopentrandomt randranget __import__RRt assertEqualtatbRtsystdont_write_bytecodetimptreloadR( texttsourceR R RR*R+tmodterr(R(s,/usr/local/lib/python2.7/test/test_import.pyttest_with_extension=s>         iR twins.PYs.Pys.pYs.pyws.PYWs.pYw(R,tpathtinsertRtcurdirRtplatformt startswith(RR4R0((Rs,/usr/local/lib/python2.7/test/test_import.pyt test_import<s'tposixs%test meaningful only on posix systemss*test meaningful only when writing bytecodecCsItjdƒ}tjjdtjƒzńttjd}t|dƒj ƒ}tj |t j t j Bt jBt jBt jBt jBƒttƒ|d}tjj|ƒsŁ|d}tjj|ƒsŁ|jdƒqŁntj |ƒ}|jt j|jƒt j t j Bt jBƒWdtj|ƒttƒttƒtjd=XdS(NiiR R$tctosC__import__ did not result in creation of either a .pyc or .pyo file(RtumaskR,R6R7R8RRR%tcloseRtstattS_IRUSRtS_IRGRPtS_IROTHtS_IXUSRtS_IXGRPtS_IXOTHR(texistsRR)tS_IMODEtst_modeRR(RtoldmasktfnameRtfnts((s,/usr/local/lib/python2.7/test/test_import.pyttest_execute_bit_not_copiedms( -      cCsotjjdtjƒttjd}zt|dƒ}|jdƒWdQXtj |ƒ}tj ||j |j dfƒtj |dƒttƒ}|j|jdƒtj |dƒt|dƒ}|jd ƒWdQXttƒttƒ}|j|jd ƒt|ƒttƒttƒ}|j|jd ƒWdttƒttƒttƒtjd=XdS( NiR R$sx = 'original' iįõitoriginali€sx = 'rewritten' t rewritten(R,R6R7RR8RRR%twriteRAtutimetst_atimetst_mtimeRR(R)txRRRR(RRLRRNtm1tm2tm3((s,/usr/local/lib/python2.7/test/test_import.pyt&test_rewrite_pyc_with_read_only_source‹s0          cCs}tj}tj}tƒ\tjdƒ}tjd|Œ}|jt|ƒ|j||jƒ|j||jƒWdQXdS(NR( RR6tgetenvRR.t find_modulet load_moduletassertIst assertIsNot(Rt orig_patht orig_getenvRVtnew_os((s,/usr/local/lib/python2.7/test/test_import.pyttest_imp_moduleÆs   tlonglistcBsÜ|ejd}e|dƒE}|jdƒx!edƒD]}|jdƒq=W|jdƒWdQXe|dƒ}ej|ƒWdQXe|ƒej j dƒd |dUej d =e|d ƒe|d ƒdS( NR sw+sd = [ ičżs"", t]trtsimport i’’’’R=R>( RRR%RRtranget py_compiletcompileRR,R6tappend(RtmoduletfilenameRti((s,/usr/local/lib/python2.7/test/test_import.pyttest_module_with_large_stackĀs    cCs°ttjd}t|dƒ}|dIJWdQXtjjdtjƒzKxDdddgD]3}|jt t tƒ|j ttj d|ƒq\WWdtjd=t tƒXdS( NR R$s a = 1 // 0iiiis'damaged module in sys.modules on %i try(RRRR%R,R6R7R8t assertRaisestZeroDivisionErrorR(t assertNotIntmodulesR(RR1RRn((s,/usr/local/lib/python2.7/test/test_import.pyttest_failing_import_sticksŻs cCsettjd}t|dƒ}|dIJ|dIJWdQXtjjdtjƒzģttƒ}|j ttj ƒ|j |j ddƒ|j |j ddƒttƒt|dƒ}|d IJ|d IJWdQX|jttj|ƒtj jtƒ}|j|dd ƒ|j |j d dƒ|j |j ddƒWdtjd=ttƒttƒXdS( NR R$sa = 1sb = 2iis!module has wrong attribute valuesisa = 10s b = 20//0s$expected module to be in sys.modulesi (RRRR%R,R6R7R8R(tassertInRsR)R*R+RRpRqR.R/tgetR_tNoneR(RR1RR2((s,/usr/local/lib/python2.7/test/test_import.pyttest_failing_reloadīs,      cCsAtjjdtjjtƒƒzddl}Wdtjd=XdS(Nii’’’’(R,R6R7Rtdirnamet__file__tinfinite_reload(RR{((s,/usr/local/lib/python2.7/test/test_import.pyttest_infinite_reloadscCssddl}ddl}|j|||jƒ|jt|jdƒƒddlj}|j||j|jƒdS(Ni’’’’Rz(R"ttest.test_supportR^t__name__t assertTruethasattrt test_support(RRVR"ty((s,/usr/local/lib/python2.7/test/test_import.pyttest_import_name_binding!s   cCs0tdtfƒ|jttdƒWdQXdS(NRgs site-packages(Rt ImportWarningRpRR((R((s,/usr/local/lib/python2.7/test/test_import.pyt&test_import_initless_directory_warning,scCsRtjjtƒ}|jtƒ}t|ƒWdQX|jd|jj dƒdS(Ns$Import by filename is not supported.i( RR6tabspathRRpRR(R)t exceptiontargs(RR6R=((s,/usr/local/lib/python2.7/test/test_import.pyttest_import_by_filename2s  cCsAtjdttjdƒƒ}ztj|ƒWdt|ƒXdS(NRgs› import sys class C: def __del__(self): import imp sys.argv.insert(0, C()) (R t make_scriptRttextwraptdedenttassert_python_okR(Rttestfn((s,/usr/local/lib/python2.7/test/test_import.pyt!test_import_in_del_does_not_crash9s  cCsRtd}tj|ƒz&|jttftjtdgƒWdtj|ƒXdS(Ns.pyt.( RRtmkdirRpRtIOErrorR.R\trmdir(RR1((s,/usr/local/lib/python2.7/test/test_import.pyt test_bug7732Gs   cCs tjjdtjƒz×td}|tr2dnd}t|dƒ}WdQXytj|d dfƒWngt k r‹|j d ƒnJt k rŌ}|j t t d dƒkr»‚n|j d j|ƒƒnXttƒtj|ƒWdtjd=ttƒXdS(Nis.pyR=R>R$ii!is-cannot set modification time to large integert EOVERFLOWs2cannot set modification time to large integer ({})IIū’’’IIū’’’(R,R6R7RR8Rt __debug__R%RSt OverflowErrortskipTestRRtgetattrRwtformatR(RAR(RR1tcompiledRte((s,/usr/local/lib/python2.7/test/test_import.pyttest_timestamp_overflowPs$    c CsvtjjdtjƒzHd}d}x5t||ƒD]$\}}t|}|d}|trddnd}t|d ƒ}|j d ƒWdQXtj |||fƒt |ƒ} tjj |ƒsŽt |ƒ|jd ƒnttj|ƒjƒd @} t|d ƒ*}tjd|jdƒdƒd} WdQXt |ƒt |ƒ|j| | ƒq5WWdtjjdƒXdS(Nii¢’Ni“ļOtspamteggss.pyR=R>R$s# Just testing x=1, 2, 3 sCouldn't create .pyc/.pyo file.I’’’’trbscCs}tj|_tjj|jdƒ|_tj |j ƒt |j dƒ}|j |jƒWdQXtjjd|j ƒdS(NR$i(R,R6tsys_pathRsR¦t module_nameRwt orig_moduleRR‘tdir_nameR%t file_nameRRt module_sourceR7(RR((s,/usr/local/lib/python2.7/test/test_import.pyR°¤s  cCsj|jtj(|jdk r2|jtj|jexplicit relative import triggered an implicit absolute import(RpRRRR(RR((s,/usr/local/lib/python2.7/test/test_import.pyt#test_absolute_import_without_futureHs(R~RÆRR°RūRR(((s,/usr/local/lib/python2.7/test/test_import.pyRłs    "tTestSymbolicallyLinkedPackagecBsoeZdZd„Zed„ƒZejee dƒ pIe j ƒd kdƒe j d„ƒƒZ d„ZRS( tsamplecCs²tjj|jƒr(tj|jƒntjj|jƒrPtj|jƒnt j|_ tj |jƒtjj |jdƒ}t |dƒjƒtj|j|jƒdS(Ns __init__.pyR$(RR6RHttaggedtshutilRt package_nameRtremove_symlinkR,t orig_sys_pathR‘RčR%R@tsymlink(Rt init_file((s,/usr/local/lib/python2.7/test/test_import.pyR°Us cCs |jdS(Ns-tagged(R (R((s,/usr/local/lib/python2.7/test/test_import.pyR jstgetwindowsversioniisWindows Vista or later requiredcCsdgtj(t|jƒdS(NR(R,R6R(R (R((s,/usr/local/lib/python2.7/test/test_import.pyttest_symlinked_dir_importableos cCsatjj|jƒr(tj|jƒntjj|jƒrPtj|jƒn|j t j(dS(N( RR6RHR RR R R RRR,(R((s,/usr/local/lib/python2.7/test/test_import.pyR{s (ii(R~RÆR R°tpropertyR R±R²R€R,RRtskip_unless_symlinkRR(((s,/usr/local/lib/python2.7/test/test_import.pyRRs cCsttttttƒdS(N(RRR“RéRłR(tverbose((s,/usr/local/lib/python2.7/test/test_import.pyR΃s t__main__(RĪ(%RR.RŹRRiR&RAR£R,R±R‹R R}RRRRRRRRR"RR RRRtTestCaseRR“RéRłRRwRĪR~ttest.test_import(((s,/usr/local/lib/python2.7/test/test_import.pyts6            :   ’k[/71