a  zeM@s,ddlZddlZddlZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlmZddlZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddlm%Z%ddl&m'Z'ddl(m)Z)e*ej+dZ,d d Z-ej.d'd d Z/Gdddej0Z1e,Gdddej0Z2Gdddej0Z3Gdddej0Z4Gdddej0Z5Gdddej0Z6Gdddej0Z7Gdddej0Z8e!Gdddej0Z9e!Gd d!d!ej0Z:Gd"d#d#ej0Z;Gd$d%d%ej0ZdS)(N)_get_sourcefile)mock)TESTFNforget is_jythonmake_legacy_pycrmtree swap_attr swap_item temp_umaskunlinkunload cpython_onlyTESTFN_UNENCODABLEtemp_dir DirsOnSysPath) script_helper)uncache) ModuleTypez*test meaningful only when writing bytecodecCs6|d|d|d|dfD] }t|qtddS)N.py.pyc.pyw $py.class __pycache__)r r)namefrM/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_import/__init__.py remove_files$s rc cs|pd}t}t|||}tj|d}zNtjd|||fVtj|W|durh|tj|<q|tjvrtj|=n(|dur|tj|<n|tjvrtj|=0Wdn1s0YdS)Nspamr) rr make_scriptsysmodulespoppathinsertremove)rsourcetempdirr%Z old_modulerrr_ready_to_import-s       r*c@s$eZdZddZddZddZddZd d Zd d Ze d dZ ddZ ddZ ddZ ddZddZddZdAddZddZd d!Zd"d#Zd$d%Zed&d'Zd(d)Zd*d+Zed,d-Zd.d/Ze d0d1Zd2d3Zd4d5Zd6d7Ze d8d9Z d:d;Z!e"#e$j%dd?Z&d@S)B ImportTestscCstttdSN)rr importlibinvalidate_cachesselfrrrsetUpDszImportTests.setUpcCs ttdSr,)r rr/rrrtearDownHszImportTests.tearDowncCs6|tddl}Wdn1s(0YdSNr) assertRaisesModuleNotFoundError(something_that_should_not_exist_anywherer0r6rrr&test_import_raises_ModuleNotFoundErrorKs z2ImportTests.test_import_raises_ModuleNotFoundErrorcCs:|tddlm}Wdn1s,0YdS)Nr)blah)r4r5r6r9)r0r9rrr:test_from_import_missing_module_raises_ModuleNotFoundErrorOs zFImportTests.test_from_import_missing_module_raises_ModuleNotFoundErrorcCs:|tddlm}Wdn1s,0YdS)Nr)r6)r4 ImportErrorr-r6r7rrr0test_from_import_missing_attr_raises_ImportErrorSs z assertEqual exceptionrr%__file__ assertRegexstrr0cmr>rrr/test_from_import_missing_attr_has_name_and_pathWs  *z;ImportTests.test_from_import_missing_attr_has_name_and_pathcCsvddl}|t}ddlm}Wdn1s40Y||jjd||jj|j| t |jddS)Nrr= _testcapizCcannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\)) rHr4r;r>r@rArr%rBrCrD)r0rHrFr>rrr2test_from_import_missing_attr_has_name_and_so_path^s  *z>ImportTests.test_from_import_missing_attr_has_name_and_so_pathcCsX|t}ddlm}Wdn1s,0Y||jjd||jjdS)Nrr=_warning) r4r;rJr>r@rArZ assertIsNoner%rErrr&test_from_import_missing_attr_has_namegs *z2ImportTests.test_from_import_missing_attr_has_namecCsZ|t}ddlm}Wdn1s,0Y||jjddh||jdS)Nrr= posixpathntpath)r4r;Zos.pathr>assertInrArassertIsNotNonerErrr/test_from_import_missing_attr_path_is_canonicalns *z;ImportTests.test_from_import_missing_attr_path_is_canonicalc Csddl}t\}}t|d}|dWdn1s>0Yi}|t||d"td|d|Wdn1s0Y|d|Wdn1s0Yt\}}t|d}|dWdn1s0Yi}|t||d "td|d|Wdn1sF0Y|d|Wdn1sr0YdS) Nrwz__all__ = [b'invalid_type']z\.__all__ must be strzfrom z import *s invalid_typez%globals()[b'invalid_type'] = object()z\.__dict__ must be str) rer*openwriteassertRaisesRegex TypeErrorescapeexec assertNotIn)r0rRrr%rglobalsrrr"test_from_import_star_invalid_typets&  (0*  (2z.ImportTests.test_from_import_star_invalid_typecCs6|tddl}Wdn1s(0YdSr3)r4r;RAnDoM)r0r\rrrtest_case_sensitivitys z!ImportTests.test_case_sensitivitycCsddlm}dS)Nr) double_const)testr^)r0r^rrrtest_double_constszImportTests.test_double_constcs^fdd}tjdtjz2|dtjdrDdD] }||q6Wtjd=n tjd=0dS)Nc sJt|}trtd}ntd}t|dP}td|d|dtd}td}td||dtd ||dWdn1s~0Yttjvrtjt=t zz t t}Wn6t y}z d ||fWYd}~n d}~00 |j|d | |j|d |Wttt|t|nttt|t|0dS) NrrrQz)# This tests Python's ability to import azfile.fileiza =zb =zimport from %s failed: %sz'module loaded (%s) but contents invalid)rrrSprintrandom randranger"r#r-r. __import__r;failr@abrr )extr(Zpycrrhrimoderrr/rrtest_with_extensions@    ,  (   z4ImportTests.test_import..test_with_extensionrrwin)z.PYz.Pyz.pYrz.PYWz.pYw)r"r%r&r?curdirplatform startswith)r0rmrjrr/r test_imports "  zImportTests.test_importlonglistcCsN|d}t|d<}|dtdD]}|dq&|dWdn1sT0Yzt|Wt|n t|0tjdt i}zdt |t d|d|Wtjd =t|d t|d | z tj|=WntyYn0nLtjd =t|d t|d | z tj|=WntyFYn00dS) NrrQzd = [ iz"", ]rzimport co)rSrTrange py_compilecompiler r"r%appendr-r.rrXclearr#KeyError)r0modulefilenameri namespacerrrtest_module_with_large_stacks>    (         z(ImportTests.test_module_with_large_stackcCstd}t|d}td|dWdn1s40Ytjdtjt ttj vrhtj t=z@dD]&}| t t t|ttj d|qnWtjd=ttntjd=tt0dS)NrrQza = 1/0rar)z'damaged module in sys.modules on %i try)rrSrcr"r%r&r?ror-r.r#r4ZeroDivisionErrorrfrYr)r0r(rrrrrtest_failing_import_stickss" *   z&ImportTests.test_failing_import_stickscCsTddl}ddl}||||j|t|jdddlm}|||j|jdS)NrrB)r_ test.supportassertIs__name__ assertTruehasattrsupport)r0xr_yrrrtest_import_name_bindings  z$ImportTests.test_import_name_bindingcCs|zd}Wddlmm}nddlmm}0d}|dkrXddlmm}|d7}q4tdD]}ddlmm}q`dS)N.r rr)Ztest.support.script_helperrrrx)r0rrrrrtest_issue31286s(  zImportTests.test_issue31286cCsHttjd}t|d}|dWdn1s80Ytjdtjzt t}| ttj | |j dd| |jddttt|d}|dWdn1s0Y|ttj|tj t}||d | |j d d| |jddWtjd=ttttntjd=tttt0dS) NpyrQz a = 1 b=2 rrz!module has wrong attribute valuesrza = 10 b=20//0 z$expected module to be in sys.modulesr)rr?extseprSrTr"r%r&rorfrNr#r@rhrirr4rr-reloadgetrOr )r0r(rrkrrrtest_failing_reloads. ( (   zImportTests.test_failing_reloadcCstd}t|d}|dWdn1s20Ytjdtjztt}| |j dt |tj t=t|ttt}tj|j \}}||dWtjd=ttttj vrtj t=n$tjd=ttttj vrtj t=0dS)NrrQz test = None rr)rrSrTr"r%r&r?rorfrrBendswithr'r#rr-r.splitextr@r)r0r(rrkbaserjrrrtest_file_to_source>s, (    zImportTests.test_file_to_sourcecCs|tjt}t}z||Wn"tyD|d |Yn0| t }t |Wdn1sn0YdS)Nzpath is not encodable to {}) r?r%abspathrr"getfilesystemencodingencodeUnicodeEncodeErrorskipTestformatr4r;rf)r0r%encodingrvrrrtest_import_by_filenameVs   z#ImportTests.test_import_by_filenamecCs"tdttd}t|dS)Nrz import sys class C: def __del__(self): import importlib sys.argv.insert(0, C()) )rr!rtextwrapdedentassert_python_ok)r0Ztestfnrrr!test_import_in_del_does_not_crash`sz-ImportTests.test_import_in_del_does_not_crashc Cs tjdtjztd}tj|}t |d}Wdn1sF0Yzt |dWnnt y|| dYnTt y}z<|jttddttddfvr| d|WYd}~n d}~00ttt|Wtjd=ttntjd=tt0dS) NrrrQ)rz-cannot set modification time to large integerZ EOVERFLOWEINVALz2cannot set modification time to large integer ({}))r"r%r&r?rorr-utilcache_from_sourcerSutime OverflowErrorrOSErrorerrnogetattrrrfstatr)r0r(Zcompiledrerrrtest_timestamp_overflowks,    &  z#ImportTests.test_timestamp_overflowcCs4ztddgdWnty.|dYn0dS)Nhttpr9)fromlistzfromlist must allow bogus names)rfr;rgr/rrrtest_bogus_fromlists zImportTests.test_bogus_fromlistcCs.ddg}tj|}|\}}|d|dS)N-cz&del __builtins__.__import__; import oss ImportError)rZ spawn_python communicaterN)r0argspopenstdoutstderrrrrtest_delete_builtins_imports  z'ImportTests.test_delete_builtins_importcCs<|tdddlm}Wdn1s.0YdS)Nz^No module named 'bogus'r)foo)rUr;bogusr)r0rrrr/test_from_import_message_for_nonexistent_modulesz;ImportTests.test_from_import_message_for_nonexistent_modulecCs<|tdddlm}Wdn1s.0YdS)Nz^cannot import name 'bogus'r)r)rUr;rRr)r0rrrr,test_from_import_message_for_existing_modulesz8ImportTests.test_from_import_message_for_existing_modulecCsvGddd}d}|t||tj|<|t}ddlm}Wdn1sV0Y|t |j ddS)Nc@seZdZddZdS)zIImportTests.test_from_import_AttributeError..AlwaysAttributeErrorcSstdSr,)AttributeError)r0_rrr __getattr__szUImportTests.test_from_import_AttributeError..AlwaysAttributeError.__getattr__N)r __module__ __qualname__rrrrrAlwaysAttributeErrorsrtest_from_import_AttributeErrorrdoes_not_existzScannot import name 'does_not_exist' from '' (unknown location)) addCleanupr r"r#r4r;rrr@rDrA)r0r module_namerFrrrrrs   * z+ImportTests.test_from_import_AttributeErrorc Csttddv|tddlm}Wdn1s:0Y|ttjWdn1sj0YWdn1s0YdS)Nrrr)r r?r4r;rr)r0rrrrtest_issue31492s  * zImportTests.test_issue31492c s ddtjdtjtjtdzdfddtdD]}t fdd td D}zZt j |j tdWdn1s0YWtjd dtjd dntjd dtjd d0durFqFWtjd=n tjd=0dS) NcSs"|dkr|jjdkrtddS)Ncall has_deadlockg?)f_codeco_nametimesleep)frameeventargrrrdelay_has_deadlocksz8ImportTests.test_concurrency..delay_has_deadlockrdatac sVtz ddl}Wn(tyF}z|WYd}~n d}~00tddSr3)r"settracewaitpackage BaseException)rr)rrexcrrruns  z)ImportTests.test_concurrency..runrcsg|]}tjdqS))target) threadingThread).0r)rrr z0ImportTests.test_concurrency..rrzpackage.submodule)r"r%r&r?joindirnamerBrxrEventr_rZ start_threadssetrrr#r$)r0rthreadsr)rrrrrtest_concurrencys$  *zImportTests.test_concurrencywin32Windows-specificc Csddlm}|tj}tjdj}tj tj |d d|vrDdnd}t j.}tj |d}t|tj |tj tj}ttj|t||ttj ttjdD]}t||qt||d} d d tjD} |d tj tj| d <tj|d d dd tj |ddggtj| tj |dt||tj|d dgtj| tj |dWdn1s0YdS)Nr)GetModuleFileNameZ_sqlite3z sqlite3{}.dllZ_drZDLLszvcruntime*.dllcSsi|]}|tj|qSr)upperr?environ)rkrrr rz:ImportTests.test_dll_dependency_import..;Z PYTHONPATHz-Scz import oszp = os.add_dll_directory({!r})zimport _sqlite3zp.close)renvcwd)_winapirr"Z dllhandler-r find_specoriginr?r%rrrr_rrmkdirbasename executableshutilcopyglobrWprefixrrB subprocess check_callSTDOUT) r0rZdllnameZpydnameZdepnametmpZtmp2Zpyexerrrrrtest_dll_dependency_importsN            z&ImportTests.test_dll_dependency_importN)rs)'rrrr1r2r8r:r<rGrrIrKrPr[r]r`rrrrrrrskip_if_dont_write_bytecoderrrrrrrrrrrunittest skipUnlessr"rprrrrrr+BsH , ( &      "r+c@sbeZdZeejdkdddZeejdkdddZeejdkdddZ d d Z d S) FilePermissionTestsposix%test meaningful only on posix systemsc Csd}t|ntH\}}tj|}t|}tj|sD| dt |}Wdn1sb0YWdn1s0Y| t t |jt d|@dS)N4__import__ did not result in creation of a .pyc filei)r r*r-rrrfr?r%existsrgrr@octS_IMODEst_mode)r0maskrr% cached_pathr~ stat_inforrrtest_creation_mode s   F z&FilePermissionTests.test_creation_modec Csd}tdztT\}}tj|}t||t|tj |sP| dt |}Wdn1sn0YWdn1s0Y| t t |jt |dS)Nr r r r*r-rrr?chmodrfr%r rgrr@r rr)r0moderr%rrrrrtest_cached_mode_issue_2051s    Fz/FilePermissionTests.test_cached_mode_issue_2051c Csd}tdztT\}}tj|}t||t|tj |sP| dt |}Wdn1sn0YWdn1s0Y|dB}| t t |jt |dS)Nr r r)r0rrr%rrZexpectedrrrtest_cached_readonly+s    Fz(FilePermissionTests.test_cached_readonlyc CsZt<\}}t|d}|dWdn1s80Yt|}t||j|jdft|dt |}| |j dt|dt|d}|dWdn1s0Yt |t t |}| |j dt|t |t |d }tt j||t |}| |j dWdn1sL0YdS) NrQzx = 'original' irZoriginalrzx = 'rewritten' Z rewrittenrv)r*rSrTr?rrst_atimest_mtimerrfr@rr r-r.r renamerr)r0rr%rsmZ bytecode_onlyrrrtest_pyc_always_writable;s, (    (z,FilePermissionTests.test_pyc_always_writableN) rrrrrr?rrrrr!rrrrrs      rc@s|eZdZdZdZejeZ ej e eej dZ e je ZddZddZdd Zd d Zd d ZddZddZdS)PycRewritingTestsZunlikely_module_namez import sys code_filename = sys._getframe().f_code.co_filename module_filename = __file__ constant = 1 def func(): pass func_filename = func.__code__.co_filename rcCstjdd|_tj|jd|_t|j t |j d}| |j Wdn1s\0Ytjd|j tdS)NrQr)r"r%sys_pathr#r$r orig_moduler?rdir_namerS file_namerT module_sourcer&r-r.)r0rrrrr1ms *zPycRewritingTests.setUpcCsV|jtjdd<|jdur*|jtj|j<n t|jt|jt|j t |j dSr,) r#r"r%r$r#rr r r& compiled_namerr%r/rrrr2vs    zPycRewritingTests.tearDowncCs t}t|j||tj|jSr,)rZrfrr"r#)r0nsrrr import_moduleszPycRewritingTests.import_modulecCs~|}||j|j||j|j||j|jtj|j=|}||j|j||j|j||j|jdSr,) r*r@module_filenamer& code_filename func_filenamer"r#rr0rkrrr test_basicss zPycRewritingTests.test_basicscCsLtj|jdd|}||j|j||j|j||j|jdSNzanother_module.py)dfile)ryrzr&r*r@r+r,r-r.rrrtest_incorrect_code_names z*PycRewritingTests.test_incorrect_code_namecCshd}tj|j|dt|jt|j}t|}| |j || |j || |j |dSr0) ryrzr&r?r'rr-r.r*r@r+r,r-)r0rpyc_filerkrrrtest_module_without_sources  z,PycRewritingTests.test_module_without_sourcecCst|jt|jd$}|d}t|}Wdn1sB0Yt|j }t j j }| d}|||<|jt|d}t|jd&}||t||Wdn1s0Y| }||jj|jdS)Nrbr) co_constswb)ryrzr&rSr(readmarshalloadlistr7r-r*__code__indexreplacetuplerTdumpr@Zconstant co_filename)r0rheadercodeZ constantsZ foreign_codeposrkrrrtest_foreign_codes  (   *z#PycRewritingTests.test_foreign_codeN)rrrrr'r?r%rrr%rrr&r-rrr(r1r2r*r/r2r4rFrrrrr"Zs      r"c@sFeZdZdZeZddZddZddZe e j dkd d d Z d S) PathsTests)r_u testäöüßutestéèu test°³²cCs t|jtjdd|_dSr,)r?rr%r"syspathr/rrrr1s zPathsTests.setUpcCst|j|jtjdd<dSr,)rr%rHr"r/rrrr2s zPathsTests.tearDowncCstttj|jdd}|dWdn1s60Ytj|jdtd}||j dt ddS)Nztest_trailing_slash.pyrQz testdata = 'test_trailing_slash'/test_trailing_slash) rSr?r%rrTr"r{rfr@testdatar )r0rrkrrrrJs (zPathsTests.test_trailing_slashrrc Csjttj|jdd}|dWdn1s60Yttj|j}ddl}| }|d}d||f}||dd7}zt |WnLt y}z4|j t j t jt jfvr|d|fWYd}~n d}~00tjd|z td}Wn8ty8}z|d ||fWYd}~n d}~00||jd||j||jtddS) Nztest_unc_path.pyrQztestdata = 'test_unc_path'rz\\%s\%s$rz%cannot access administrative share %rZ test_unc_pathz,could not import 'test_unc_path' from %r: %r)rSr?r%rrTr-r.rsocket gethostnamelistdirrrEPERMZEACCESENOENTrr"r&rfr;rgr@rKrrBrqr ) r0rr%rLZhndriveZuncrrkrrr test_UNC_paths2(  zPathsTests.test_UNC_pathN)rrrZSAMPLESrr%r1r2rJrrr"rprRrrrrrGs rGc@sHeZdZddZeZddZddZddZd d Zd d Z d dZ dS)RelativeImportTestscCs tddS)Nztest.relimport)r r/rrrr2szRelativeImportTests.tearDowncCs ddlm}|t|ddS)Nr) relimportrS)rrTrr)r0rTrrrtest_relimport_stars z'RelativeImportTests.test_relimport_starcs|fdd}tddd|tddd|tddd|t|tddd|t|ttd|t|dS) NcstddS)Nzfrom . import relimport)rXrr)rrcheck_relativesz:RelativeImportTests.test_issue3221..check_relativer_ztest.notarealmodule) __package__rznotarealpkg.notarealmoduler)rX)dictr4r5objectrV)r0rWrrVrtest_issue3221s        z"RelativeImportTests.test_issue3221cCstdddddS)Nz-Wignorerzfoo = 1; from . import foo)rZassert_python_failurer/rrr)test_parentless_import_shadowed_by_globals z=RelativeImportTests.test_parentless_import_shadowed_by_globalcCsD|t&ddlm}|dWdn1s60YdS)Nr)sepz>explicit relative import triggered an implicit absolute import)r4r;r?r^rg)r0r^rrr#test_absolute_import_without_futures  z7RelativeImportTests.test_absolute_import_without_futurec Cstjtjtdd}tddt|^|tddl }Wdn1sV0Y| dt j | dt j Wdn1s0YWdn1s0YdS)Nrpackage2 submodule1 submodule2r) r?r%rrrBrrr4r;rarYr"r#)r0r%rarrrtest_import_from_non_packages  &z0RelativeImportTests.test_import_from_non_packagec CsztdddZttjtjtd ddl}|jj Wdn1sN0YWdn1sl0YdS)Nr`zpackage2.submodule1zpackage2.submodule2rr) rrr?r%rrrBZpackage2.submodule1rarb)r0r`rrr!test_import_from_unloaded_package&s z5RelativeImportTests.test_import_from_unloaded_packageN) rrrr2r1rUr[r]r_rcrdrrrrrSs rSc@seZdZddZdS)OverridingImportBuiltinTestscCsddl}dd}|||ttddd||dWdn1sR0Yttddd|||Wdn1s0YdS) NrcSs ddl}|Sr3r?rfrrrr2sz?OverridingImportBuiltinTests.test_override_builtin..foorfcWsdSNrrrrr7rzDOverridingImportBuiltinTests.test_override_builtin..rhcWsdSrgrrirrrrj=r)r?r@r builtinsr rZ)r0r?rrrrtest_override_builtin.s,z2OverridingImportBuiltinTests.test_override_builtinN)rrrrlrrrrre-srec@seZdZddZddZddZeddZe e j d kd e e e d oTe d kd eddZeddZeddZddZeddZeddZddZddZdS) PycacheTestscCstttdt|jdS)Nr)rrrr r(r/rrr_cleanDszPycacheTests._cleancCsftd|_|t|jd}td|dWdn1s@0Ytjdtj t dS)NrrQz/# This is a test file written by test_import.pyrar) rr(rnrSrcr"r%r&r?ror-r.)r0fprrrr1Is  *zPycacheTests.setUpcCs,tjdtjksJdtjd=|dS)NrzUnexpected sys.path[0])r"r%r?rornr/rrrr2QszPycacheTests.tearDowncCsZ|tjdtt|tjdtj |j }|tj|d |tdS)Nrz*bytecode file {!r} for {!r} does not exist) assertFalser?r%r rfrrr-rrr(rr0Zpyc_pathrrrtest_import_pyc_pathVsz!PycacheTests.test_import_pyc_pathrr geteuidrz=due to varying filesystem permission semantics (issue #11956)cCsptdttWdn1s&0Y|tjdtj |j }| tj|d |tdS)Nrz"bytecode file {!r} for {!r} exists) r rfrrr?r%r r-rrr(rprrqrrrtest_unwritable_directory`s &z&PycacheTests.test_unwritable_directorycCsVtttj|j}|tj |t |jt tt | tttdSr,)rfrr-rrr(rr?r%r r'rr.r4r;)r0r3rrrtest_missing_sourceps z PycacheTests.test_missing_sourcec Cs~ttt|j}t|jttttt}z6| |j tj t tjtj |Wt|n t|0dSr,)rfrrr(r?r'r r-r.r@rBr%rgetcwdrorelpathr0r3r rrrtest_missing_source_legacy|s  z'PycacheTests.test_missing_source_legacycCs<tt}tjtd}||jtj t tj |dS)Nr) rfrr-rrr@ __cached__r?r%rrwro)r0r r3rrrtest___cached__szPycacheTests.test___cached__c Csbttt|j}t|jttttt}| |j tj t tjtj |dSr,)rfrrr(r?r'r r-r.r@r{r%rrwrorxryrrrtest___cached___legacy_pycs  z'PycacheTests.test___cached___legacy_pyccCs dd}td||ttjdddWdn1sF0YttjdddWdn1sz0Yttd}tj tjdd}| |j tjt tj|tj tjdd}| tjdj tjt tj|dS)NcSstdtdtddSNpep3147 pep3147.foorr rrrrcleanupsz5PycacheTests.test_package___cached__..cleanupr __init__.pyrQfoo.pyr)r?rrrSr%rr-r.rfrrr@r{rwror"r#r0rr Zinit_pycZfoo_pycrrrtest_package___cached__s"    z$PycacheTests.test_package___cached__cCs*dd}td||ttjdddWdn1sF0YttjdddWdn1sz0Yttd}t dt dttd}tj tjdd}| |j tjttj|tj tjdd}| tjdj tjttj|dS)NcSstdtdtddSr~rrrrrrsz>PycacheTests.test_package___cached___from_pyc..cleanuprrrQrr)r?rrrSr%rr-r.rfr rrr@r{rwror"r#rrrr test_package___cached___from_pycs*    z-PycacheTests.test_package___cached___from_pyccCsbttttt|jd}td|dWdn1s>0Ytt}||jddS)Nrhzx = 5rarh)rfrr rSr(rcr@r)r0ror rrrtest_recompute_pyc_same_seconds *z+PycacheTests.test_recompute_pyc_same_secondN)rrrrnr1r2rrrrrr?rskipIfrrsrurvrzr|r}rrrrrrrrmAs0      rmc@sXeZdZdZedZddZddZee e d p>e dkd e j jd d Zd S) TestSymbolicallyLinkedPackagesamplez-taggedcCstj|jtj|jtjdd|_t |j| tjj|jtj |jd}tj |tj |svJtj|j|jdd| tjj|jt|tj|jdtjtj |jdsJdS)NrT)target_is_directory)r_rrtagged package_namer"r% orig_sys_pathr?rrrZcreate_empty_filer symlinkr r-r.r@isdirisfile)r0Z init_filerrrr1s  z#TestSymbolicallyLinkedPackage.setUpcCs|jtjdd<dSr,)rr"r%r/rrrr2sz&TestSymbolicallyLinkedPackage.tearDowngetwindowsversion)rzWindows Vista or later requiredcCsNdgtjdd<tj|js"Jtjtj|jds>Jt|jdS)N.r)r"r%r?r rrr-r*r/rrrtest_symlinked_dir_importablesz;TestSymbolicallyLinkedPackage.test_symlinked_dir_importableN)rrrrrr1r2rrrr"rr_rZskip_unless_symlinkrrrrrrs  rc@s,eZdZddZddZddZddZd S) ImportlibBootstrapTestscCstjd}||dS)N_frozen_importlib)r"r#rr.rrrtest_frozen_importlibs z-ImportlibBootstrapTests.test_frozen_importlibcCsXddlm}tjd}|||||jd||jd||j d|j dS)Nr) _bootstraprzimportlib._bootstrapr-z _bootstrap.py) r-rr"r#rr@rrXrrBr)r0rrkrrr"test_frozen_importlib_is_bootstraps    z:ImportlibBootstrapTests.test_frozen_importlib_is_bootstrapcCsXddlm}tjd}|||||jd||jd||j d|j dS)Nr)_bootstrap_external_frozen_importlib_externalzimportlib._bootstrap_externalr-z_bootstrap_external.py) r-rr"r#rr@rrXrrBr)r0rrkrrr4test_frozen_importlib_external_is_bootstrap_external s    zLImportlibBootstrapTests.test_frozen_importlib_external_is_bootstrap_externalcCs*ddlm}tjd}||j|jdS)Nr) machineryr)r-rr"r#r ModuleSpec)r0rrkrrrtest_there_can_be_only_one(s  z2ImportlibBootstrapTests.test_there_can_be_only_oneN)rrrrrrrrrrrrsrc@s(eZdZdZddZddZddZdS) GetSourcefileTestszTest importlib._bootstrap_external._get_sourcefile() as used by the C API. Because of the peculiarities of the need of this function, the tests are knowingly whitebox tests. cCsTtd6}d|_td}td}|t||Wdn1sF0YdS)N*importlib._bootstrap_external._path_isfileTrrrZpatchZ return_valuerr@r)r0 _path_isfiler%expectrrrtest_get_sourcefile;s  z&GetSourcefileTests.test_get_sourcefilecCsLtd.}d|_td}|t||Wdn1s>0YdS)NrFrr)r0rr%rrrtest_get_sourcefile_no_sourceDs z0GetSourcefileTests.test_get_sourcefile_no_sourcecCstd}|t||dS)Nz.bad_ext)rr@r)r0r%rrrtest_get_sourcefile_bad_extLsz.GetSourcefileTests.test_get_sourcefile_bad_extN)rrr__doc__rrrrrrrr1s rc@seZdZddZddZd$ddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZeddZeed d!d"Zd#S)%ImportTracebackTestscCs,tttjdd|_tjdtdSr3)r?rrr"r%old_pathr&r/rrrr1Us zImportTracebackTests.setUpcCs|jtjdd<ttdSr,)rr"r%rrr/rrrr2ZszImportTracebackTests.tearDownrcCs^tjt||}t|d}||Wdn1s<0Y|t|t |S)NrQ) r?r%rrrSrTrr r-r.)r0rkcontentsrjZfnamerrrr create_module^s  ( z"ImportTracebackTests.create_modulecCsrg}|r8|jj}|j}|r&||dkr0|||j}q|t|t||t||D]\}}|||qXdS)Nru) tb_framerrBr{tb_nextr@lenziprN)r0tbfilesZ deduped_filesrDfnpatrrrassert_tracebackfs z%ImportTracebackTests.assert_tracebackc CsTz ddl}Wn*ty6}z|j}WYd}~nd}~00|d||tgdS)Nr#ImportError should have been raised)nonexistent_xyzzyr; __traceback__rgrrB)r0rrrrrrtest_nonexistent_modulers   z,ImportTracebackTests.test_nonexistent_modulec Csb|ddz ddl}Wn*tyB}z|j}WYd}~nd}~00|d||tdgdS)Nrzimport nonexistent_xyzzyrrr)rrr;rrgrrBr0rrrrrrtest_nonexistent_module_nested|s   z3ImportTracebackTests.test_nonexistent_module_nestedc Csb|ddz ddl}Wn*tyB}z|j}WYd}~nd}~00|d||tdgdS)Nr1/0r)ZeroDivisionError should have been raisedrrrrrrgrrBrrrrtest_exec_failures   z&ImportTracebackTests.test_exec_failurec Csp|dd|ddz ddl}Wn*tyN}z|j}WYd}~nd}~00|d||tddgdS) Nrz import barbarrrrrbar.pyrrrrrtest_exec_failure_nesteds    z-ImportTracebackTests.test_exec_failure_nestedc Cs`|ddz ddl}Wn*tyB}z|j}WYd}~nd}~00|d||tgdS)Nrzinvalid syntax is invalidrz#SyntaxError should have been raised)rr SyntaxErrorrrgrrBrrrrtest_syntax_errors   z&ImportTracebackTests.test_syntax_errorcCsd}|t|tjt|}t|tj|d}t|d}||Wdn1s`0Ytj|d}t|d}||Wdn1s0Yt ||fS)N _parent_foorrQr) rr r?r%rrrrSrTr-r.)r0parentchildZpkg_nameZpkg_path init_pathrbar_pathrrr_setup_broken_packages   ( (z*ImportTracebackTests._setup_broken_packagec Csf|dd\}}z ddl}Wn*tyF}z|j}WYd}~nd}~00|d||t|gdS)NrrrrrZ_parent_foo.barrrrgrrBr0rrrrrrrrtest_broken_submodules  z*ImportTracebackTests.test_broken_submodulec Csj|dd\}}zddlm}Wn*tyJ}z|j}WYd}~nd}~00|d||t|gdS)NrrrrrrrrrrrgrrBr0rrrrrrrrtest_broken_froms z%ImportTracebackTests.test_broken_fromc Csf|dd\}}z ddl}Wn*tyF}z|j}WYd}~nd}~00|d||t|gdS)Nrrrrrrrrrtest_broken_parents  z'ImportTracebackTests.test_broken_parentc Csj|dd\}}zddlm}Wn*tyJ}z|j}WYd}~nd}~00|d||t|gdS)Nrrrrrrrrrrtest_broken_parent_froms z,ImportTracebackTests.test_broken_parent_fromc Cs|ddtjd}dt|jvr.|jj}nd}zdd}||j_z ddl}Wn*tyz}z|j}WYd}~nd}~00| d| |t d t gW|dur|j`q||j_n|dur|j`n||j_0dS) Nrrr load_modulecWs dddS)Nrrr)rrrr exec_modulesz9ImportTracebackTests.test_import_bug..exec_modulerrztdtd}|t||dd}tjdd|dddS)Nrpassrzmod = __import__(%a)F)Z __isolated)rr!rrr r)r0Zpynamerrrrtest_unencodable_filenames    z.ImportTracebackTests.test_unencodable_filenameN)r)rrrr1r2rrrrrrrrrrrrrrrrrrrrrrrSs$             rc@s`eZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)CircularImportTestszQSee the docstrings of the modules being imported for the purpose of the test.cCs*ttjD]}|drtj|=qdS)zSMake sure no modules pre-exist in sys.modules which are being used to test.z&test.test_import.data.circular_importsN)r<r"r#keysrq)r0keyrrrr2s zCircularImportTests.tearDowncCs.z ddl}Wnty(|dYn0dS)Nrz/circular import through relative imports failed)Z,test.test_import.data.circular_imports.basicr;rgr0r_rrr test_directs  zCircularImportTests.test_directcCs.z ddl}Wnty(|dYn0dS)Nrz@relative import in module contributing to circular import failed)Z/test.test_import.data.circular_imports.indirectr;rgrrrr test_indirects  z!CircularImportTests.test_indirectcCs.z ddl}Wnty(|dYn0dS)Nrz-circular import involving a subpackage failed)Z1test.test_import.data.circular_imports.subpackager;rgrrrrtest_subpackages  z#CircularImportTests.test_subpackagecCs`z"ddlmmmm}Wnty>|dYn0ddlm}| |j|jdS)Nrz9circular import with rebinding of module attribute failed)r) Z0test.test_import.data.circular_imports.rebindingrrrZcircular_imports rebindingr;rgZ-test.test_import.data.circular_imports.subpkgrr)r0rrrrrtest_rebinding"s "  z"CircularImportTests.test_rebindingcCs.z ddl}Wnty(|dYn0dS)Nrz9circular import with binding a submodule to a name failed)Z.test.test_import.data.circular_imports.bindingr;rgrrrr test_binding*s  z CircularImportTests.test_bindingcCsddl}ddl}dSr3)Z*test.test_import.data.circular_imports.use-test.test_import.data.circular_imports.sourcerrrrtest_crossreference10sz(CircularImportTests.test_crossreference1cCsp|t}ddl}Wdn1s(0Yt|j}|d||d||d||d|dS)Nrz-test.test_import.data.circular_imports.sourcer zpartially initialized modulezcircular import)r4rrrDrArN)r0rFr_errmsgrrrtest_crossreference24s &    z(CircularImportTests.test_crossreference2cCsH|t}ddl}Wdn1s(0Y|dt|jdS)Nrzcannot import name 'b' from partially initialized module 'test.test_import.data.circular_imports.from_cycle1' (most likely due to a circular import))r4r;Z2test.test_import.data.circular_imports.from_cycle1rNrDrA)r0rFr_rrrtest_circular_from_import=s  &z-CircularImportTests.test_circular_from_importcCs|td|tdddlmmm}|tddlm}Wdn1s\0Y| t |t | t |t | td|_Wdn1s0YdS)Nz test.test_import.data.unwritablez"test.test_import.data.unwritable.xrri*)rr Z test.test_import.data.unwritablerrr unwritableZ assertWarns ImportWarningrZassertNotEqualtyperr@r4r)r0rrrrrtest_unwritable_moduleGs   * z*CircularImportTests.test_unwritable_moduleN)rrrrr2rrrrrrrrrrrrrrs  r__main__)Nr)?rk contextlibrrimportlib.utilr-Zimportlib._bootstrap_externalrr:r?ryrdrrrr"rrrrrrr_rrrrrr r r r r rrrrrZtest.test_importlib.utilrtypesrrdont_write_bytecoderrcontextmanagerr*ZTestCaser+rr"rGrSrermrrrrrrmainrrrrsh  @     GSY5E". !1R