o $aA@s$dZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z ddlZddlmZddlmZmZd d gZd d Zejd ddefddZGdddZejde de dededede e e ff ddZejde de fddZejddde de e e fde dede eddff ddZejdddedefdd Zejdddedefd!d"Zede d#e de e ddffd$dZejdefd%dZ ejd&d'd(d5d)d*Z!ejdeddfd+d,Z"ejd dd-e dd.fd/dZ#ejd0edd.fd1d2Z$ejd3d4Z%dS)6z sphinx.testing.fixtures ~~~~~~~~~~~~~~~~~~~~~~~ Sphinx test fixtures for pytest :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N) namedtuple)StringIO)PIPE)AnyCallableDict GeneratorTuple)util) SphinxTestApp#SphinxTestAppWrapperForSkipBuildingzsphinx(builder, testroot=None, freshenv=False, confoverrides=None, tags=None, docutilsconf=None, parallel=0): arguments to initialize the sphinx test application.z0test_params(shared_result=...): test parameters.cCstD]}|d|qdS)zRegister custom markersmarkersN)DEFAULT_ENABLED_MARKERSaddinivalue_line)configmarkerr9/usr/lib/python3/dist-packages/sphinx/testing/fixtures.pypytest_configure srsession)scopereturncCsdSNrrrrrrootdir&src@sZeZdZUiZeeeeeffed<dededefddZ dedeee ffddZ d S) SharedResultcachekeyapp_rcCs2||jvrdS|j|jd}||j|<dS)Nstatuswarning)r_statusgetvalue_warning)selfrrdatarrrstore.s zSharedResult.storecCs2||jvriS|j|}t|dt|ddS)Nrr r)rr)r$rr%rrrrestore7s    zSharedResult.restoreN) __name__ __module__ __qualname__rrstr__annotations__r rr&rr'rrrrr+s  rrequest test_params shared_resultsphinx_test_tempdircst|jdr |jd}n|jd}ii}|dur8tt|D]}t|jD]\}} | |<q(||j q!fddt D} |drdd|vrRt d|d|d<||d} || |d d } ||d| |d<} |r| s|d | }|| td d | |S)zp Parameters that are specified by 'pytest.mark.sphinx' for sphinx.application.Sphinx initialization iter_markerssphinxNcsg|]}|qSrr).0ipargsrr Yszapp_params..r/srcdirz:You can not specify shared_result and srcdir in same time.testrootrootztest- app_paramsz args,kwargs)hasattrnoder1 get_markerreversedlist enumerateargsupdatekwargssortedkeyspytest Exceptionr'popgetexistscopytreer)r-r.r/r0rr rDinfor4arBr'r9r8 testroot_pathrr5rr;As.          r;cCsjt|jdr |jd}n|jd}|r|jni}ddi}|||dr3t|dts3t d|S)au Test parameters that are specified by 'pytest.mark.test_params' :param Union[str] shared_result: If the value is provided, app._status and app._warning objects will be shared in the parametrized test functions and/or test functions that have same 'shared_result' value. **NOTE**: You can not specify both shared_result and srcdir. get_closest_markerr.r/Nz@You can only provide a string type of value for "shared_result" ) r<r=rPr>rDrC isinstancer+rGrH)r-envrDresultrrrr.qs    functionmake_appccs|\}}||i|}|Vtd|ddtd|jjtd|jtd|jtdd|jtd d|j|d rM| |d |d Sd S) z9 Provides the 'sphinx.application.Sphinx' object z # testroot:r9r:z # builder:z # srcdir:z # outdir:z # status: z # warning:r/N) printrJbuildernamer8outdirr!r"r#r&)r.r;rUr/rBrDrrrrapps  r[cC|jSzJ Back-compatibility for testing with previous @with_app decorator )r!r[rrrrrcCr\r])r#r^rrrr r_r monkeypatchc#s`|dddgtjdd}fdd}|V|tjdd<tD]}|q'dS)z Provides make_app function to initialize SphinxTestApp instance. if you want to initialize 'app' in your test function. please use this instead of using SphinxTestApp class directory. zsphinx.application.abspathcSs|Srr)xrrrszmake_app..NcsRtt}}|d||d|t|i|}|dr't|}|S)Nrr r/)r setdefaultr appendr )rBrDrr rappsr.rrmakes   zmake_app..make)setattrsyspathr?cleanup)r.r`syspathrgrrrerrUs   cCstSr)rrrrrr/smoduleT)rautousecCstjdSr)rrclearrrrr_shared_result_cachesrpcCsRt|jdd}z|rtj|dgttdWdSWn ty!YnwtddS)zt The test will be skipped when using 'if_graphviz_found' fixture and graphviz dot command is not found. graphviz_dotz-V)stdoutstderrNzgraphviz "dot" is not available)getattrr subprocessrunrOSErrorrGskip)r[rqrrrif_graphviz_founds rztmpdir_factoryz util.pathcCs|}t|S)z8 Temporary directory wrapped with `path` class. ) getbasetempr rjabspath)r{tmpdirrrrr0sr~cCs t|S)z Temporary directory wrapped with `path` class. This fixture is for back-compatibility with old test implementation. )r rj)r~rrrtempdirs rc csdzttj}dVWttjD] }||vrtj|qdSttjD] }||vr0tj|q$w)z Rollback sys.modules to its value before testing to unload modules during tests. For example, used in test_ext_autosummary.py to permit unloading the target module to clear its cache. N)r@rimodulesrI) sysmodulesmodnamerrrrollback_sysmoduless   r)rN)&__doc__rvri collectionsriorrtypingrrrrr rGsphinx.testingr sphinx.testing.utilr r rrfixturer+rrr;r.r[rr rUr/rprzr0rrrrrrsf        /    "