ó {G_Tc@s"ddlZddlZddlZddlZddlZddlZddlmZmZm Z ddl m Z m Z m Z mZmZmZddlmZmZmZmZdejfd„ƒYZdejfd„ƒYZd ejfd „ƒYZd „Zed kreƒndS( iÿÿÿÿN(tverboset run_unittesttforget(ttemp_dirt make_scripttcompile_scripttmake_pkgtmake_zip_scriptt make_zip_pkg(t _run_codet_run_module_codet run_moduletrun_pathtRunModuleCodeTestcBs2eZdZddgZdZd„Zd„ZRS(s9Unit tests for runpy._run_code and runpy._run_module_codesTop level assignmentsLower level references§# Check basic code execution result = ['Top level assignment'] def f(): result.append('Lower level reference') f() # Check the sys module import sys run_argv0 = sys.argv[0] run_name_in_sys_modules = __name__ in sys.modules if run_name_in_sys_modules: module_in_sys_modules = globals() is sys.modules[__name__].__dict__ # Check nested operation import runpy nested = runpy._run_module_code('x=1\n', mod_name='') cCsÅtjd}t|jiƒ}|j|d|jƒ|j|ddƒ|j|ddƒ|j|ddƒ|j|ddƒ|j|d|ƒ|jd|ƒ|jtjd|ƒdS( Nitresultt__name__t__file__t __loader__t __package__t run_argv0trun_name( tsystargvR t test_sourcet assertEqualtexpected_resulttassertIstNonet assertNotIn(tselft saved_argv0td((s+/usr/local/lib/python2.7/test/test_runpy.pyt test_run_code*s c Csbtƒ}d}d}d}d}td|ƒ}tjd}t|j|||||ƒ}|jd|ƒ|j|d|ƒ|j|d|j ƒ|j|dd d ƒ|j|d |ƒ|j |d ƒ|j |d ƒ|j|d|ƒ|j|d|ƒ|j|d|ƒ|j|d|ƒ|jtjd|ƒ|j|tj ƒdS(Ns sSome other nonsensesNow you're just being sillyttinitialiRtnestedtxiRtrun_name_in_sys_modulestmodule_in_sys_modulesRRRR( tobjecttdictRRR RRRRRt assertTruetmodules( RR"tnametfiletloadertpackagetd1Rtd2((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_run_module_code6s4    (Rt __module__t__doc__RRR R1(((s+/usr/local/lib/python2.7/test/test_runpy.pyR s   t RunModuleTestcBs’eZdZd„Zd„Zd„Zd„Zdd„Zd„Zd„Z d „Z d „Z dd „Z d „Zd „Zd„Zd„ZRS(sUnit tests for runpy.run_modulecCs7yt|ƒWntk r!nX|jd|ƒdS(NsExpected import error for (R t ImportErrortfail(Rtmod_name((s+/usr/local/lib/python2.7/test/test_runpy.pytexpect_import_errorVs  cCs_|jdƒ|jdƒ|jdƒ|jdƒ|jdƒ|jdƒ|jdƒdS(NRs sys.imp.erics os.path.halfsa.bees.howards..eatentmultiprocessing(R8(R((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_invalid_names^s      cCstdƒdS(Ntrunpy(R (R((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_library_modulejscCsJtj|ƒtjj|dtjdƒ}t|dƒ}|jƒ|S(Nt__init__tpytw(tostmkdirtpathtjointextseptopentclose(Rtpkg_dirt pkg_fnametpkg_file((s+/usr/local/lib/python2.7/test/test_runpy.pyt _add_pkg_dirms    t runpy_testc Cs0d}|tjd}tjƒ}}tr9dG|GHntjjd|ƒtredGtjdGHnx\t|ƒD]N}tjj ||ƒ}|j |ƒ} tr®dG|GHntrrdG| GHqrqrWtjj ||ƒ} t | dƒ} | j |ƒ| j ƒtrdG| GHn|d ||} || | fS( Nt __runpy_pkg__R>s Package tree in:is Updated sys.path:s Next level in:s Created:R?t.(R@RDttempfiletmkdtempRRRBtinserttrangeRCRJREtwriteRF( Rtsourcetdepthtmod_basetpkg_namet test_fnameRGtsub_dirtiRHt mod_fnametmod_fileR7((s+/usr/local/lib/python2.7/test/test_runpy.pyt _make_pkgts.     c Cs|x3ttjƒD]"}|jdƒrtj|=qqWtrDdGHntjd=tr\dGHnxÖtj|dtƒD]¿\}}}xR|D]J}y tj tjj ||ƒƒWqˆt k rÑ} trÒ| GHqÒqˆXqˆWxX|D]P}tjj ||ƒ} ytj | ƒWqÝt k r,} tr-| GHq-qÝXqÝWqrWytj |ƒtrSdGHnWn!t k rw} trx| GHqxnXdS(NRLs Removed sys.modules entriesis Removed sys.path entryttopdowns Removed package tree( tlistRR*t startswithRRBR@twalktFalsetremoveRCtOSErrortrmdir( RttopRTR7tentrytroottdirstfilesR+textfullname((s+/usr/local/lib/python2.7/test/test_runpy.pyt_del_pkgˆs: %     cCs|jd|ƒ\}}}t|ƒz·tr:dG|GHnt|ƒ}|jd|ƒ|j|ddkƒ~t|ƒtj|ƒt j sÛtr¢dG|GHnt|ƒ}|jd|ƒ|j|ddkƒ~nWd|j |||ƒXtrdGHndS(Nsx=1 sRunning from source:R$isRunning from compiled:sModule executed successfully( R\RRR tassertInR)t __import__R@RbRtdont_write_bytecodeRl(RRTRGRZR7R/R0((s+/usr/local/lib/python2.7/test/test_runpy.pyt _check_module¡s*         c Cs |jd|dƒ\}}}|jdƒ\}}}t|ƒz·trUdG|GHnt|ƒ}|jd|ƒ|j|ddkƒ~t|ƒtj |ƒt j sötr½dG|GHnt|ƒ}|jd|ƒ|j|ddkƒ~nWd|j |||ƒXtrdGHndS( Nsx=1 t__main__RMsRunning from source:R$isRunning from compiled:sPackage executed successfully( R\t rpartitionRRR RmR)RnR@RbRRoRl( RRTRGRZR7RVt_R/R0((s+/usr/local/lib/python2.7/test/test_runpy.pyt_check_package·s,         cCs[|dkrtdƒ‚nd}|}x/t|ƒD]!}|}tjj||ƒ}q4Wtjj|dtjdƒ}t|dƒ} | jƒtr¤dG|GHntjj|dƒ} |j | ƒtrØd G| GHntjj| d ƒ} |j | ƒtr d G| GHntjj| d tjdƒ} t| dƒ} | jƒtrWd G| GHndS(Nis$Relative module test needs depth > 1RLtsiblingR>R?s Added sibling module:tuncles Added uncle package:tcousins Added cousin package:tnephews Added nephew module:( t ValueErrorRQR@RBRCRDRERFRRJ(Rtbase_dirRSRTRVt module_dirRYt parent_dirt sibling_fnamet sibling_filet uncle_dirt cousin_dirt nephew_fnamet nephew_file((s+/usr/local/lib/python2.7/test/test_runpy.pyt_add_relative_modulesÎs2          c Cssd}|j||ƒ\}}}z)|j|||ƒ|jdƒd}tr\dG|GHnt|d|ƒ}|jd|ƒ|j|d|kƒ|jd|ƒ|jd|ƒ~t|ƒtj |ƒt j sItrêd G|GHnt|d|ƒ} |jd| ƒ|j| d|kƒ|jd| ƒ|jd| ƒ~ nWd|j |||ƒXtrod GHndS( Nsa\ from __future__ import absolute_import from . import sibling from ..uncle.cousin import nephew RMisRunning from source:RRRuRxsRunning from compiled:sModule executed successfully( R\RƒRrRR RmR)RnR@RbRRoRl( RRTRtcontentsRGRZR7RVR/R0((s+/usr/local/lib/python2.7/test/test_runpy.pyt_check_relative_importsçs6      cCs:x3tdƒD]%}tr%dG|GHn|j|ƒq WdS(NisTesting package depth:(RQRRp(RRT((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_run_modules cCs=x6tddƒD]%}tr(dG|GHn|j|ƒqWdS(NiisTesting package depth:(RQRRt(RRT((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_run_package s cCs=x6tddƒD]%}tr(dG|GHn|j|ƒqWdS(Niis"Testing relative imports at depth:(RQRR…(RRT((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_explicit_relative_imports cCs@x9tddƒD](}tr(dG|GHn|j|dƒqWdS(Niis'Testing main relative imports at depth:Rq(RQRR…(RRT((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_main_relative_imports N(RR2R3R8R:R<RJR\RlRpRtRƒRR…R†R‡RˆR‰(((s+/usr/local/lib/python2.7/test/test_runpy.pyR4Ss           t RunPathTestcBsƒeZdZdZdd„Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „ZRS(sUnit tests for runpy.run_pathsX# Script may be run with optimisation enabled, so don't rely on assert # statements being executed def assertEqual(lhs, rhs): if lhs != rhs: raise AssertionError('%r != %r' % (lhs, rhs)) def assertIs(lhs, rhs): if lhs is not rhs: raise AssertionError('%r is not %r' % (lhs, rhs)) # Check basic code execution result = ['Top level assignment'] def f(): result.append('Lower level reference') f() assertEqual(result, ['Top level assignment', 'Lower level reference']) # Check the sys module import sys assertIs(globals(), sys.modules[__name__].__dict__) argv0 = sys.argv[0] cCs(|dkr|j}nt|||ƒS(N(RRR(Rt script_dirtscript_basenameRS((s+/usr/local/lib/python2.7/test/test_runpy.pyt_make_test_script5s  cCspt|ƒ}|j|d|ƒ|j|d|ƒ|jd|ƒ|j|d|ƒ|j|d|ƒdS(NRRtargv0R(R RRm(Rt script_namet expected_namet expected_filetexpected_argv0texpected_packageR((s+/usr/local/lib/python2.7/test/test_runpy.pyt _check_script:s  cCs)tj|ƒ}|jt|t|ƒdS(N(tretescapetassertRaisesRegexpR5R (RRtmsg((s+/usr/local/lib/python2.7/test/test_runpy.pyt_check_import_errorCsc CsGtƒ8}d}|j||ƒ}|j|d||dƒWdQXdS(Ntscripts (RRR”R(RR‹R7R((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_basic_scriptGs  c Cs`tƒQ}d}|j||ƒ}t|ƒ}tj|ƒ|j|d||dƒWdQXdS(NRšs (RRRR@RbR”R(RR‹R7Rt compiled_name((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_script_compiledNs   c CsGtƒ8}d}|j||ƒ}|j|d||dƒWdQXdS(NRqs R!(RRR”(RR‹R7R((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_directoryWs  c Cs`tƒQ}d}|j||ƒ}t|ƒ}tj|ƒ|j|d||dƒWdQXdS(NRqs R!(RRRR@RbR”(RR‹R7RRœ((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_directory_compiled^s   cCsHtƒ9}d}|j||ƒ}d|}|j||ƒWdQXdS(Ntnot_mains"can't find '__main__' module in %r(RRR™(RR‹R7RR˜((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_directory_errorgs   c Cs_tƒP}d}|j||ƒ}t|d|ƒ\}}|j|d||dƒWdQXdS(NRqttest_zips R!(RRRR”(RR‹R7Rtzip_nametfname((s+/usr/local/lib/python2.7/test/test_runpy.pyt test_zipfilens  c Csktƒ\}d}|j||ƒ}t|ƒ}t|d|ƒ\}}|j|d||dƒWdQXdS(NRqR¢s R!(RRRRR”(RR‹R7RRœR£R¤((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_zipfile_compiledus   cCs`tƒQ}d}|j||ƒ}t|d|ƒ\}}d|}|j||ƒWdQXdS(NR R¢s"can't find '__main__' module in %r(RRRR™(RR‹R7RR£R¤R˜((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_zipfile_error}s   c Cstƒr}tƒ`}d}d|}|j|||ƒ}t|d|ƒ\}}d}|jt|t|ƒWdQXWdQXdS(NRqs import runpy runpy.run_path(%r) R¢srecursion depth exceeded(RRRR—t RuntimeErrorR ( RR‹t dummy_dirR7RSRR£R¤R˜((s+/usr/local/lib/python2.7/test/test_runpy.pyttest_main_recursion_error…s N(RR2R3RRRR”R™R›RRžRŸR¡R¥R¦R§Rª(((s+/usr/local/lib/python2.7/test/test_runpy.pyRŠs        cCsttttƒdS(N(RR R4RŠ(((s+/usr/local/lib/python2.7/test/test_runpy.pyt test_main‘sRq(tunittestR@tos.pathRR•RNttest.test_supportRRRttest.script_helperRRRRRRR;R R R R tTestCaseR R4RŠR«R(((s+/usr/local/lib/python2.7/test/test_runpy.pyts      .">Éu