3

T'ícã	@sdZddlZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
ddlZddlmZddlmZmZd	d
gZdd„Zejd
dedœdd„ƒZGdd„dƒZeje	eeeee
eefdœdd„ƒZeje	edœdd„ƒZejddee
eefe
eeeddfdœdd„ƒZejddeedœdd „ƒZejddeedœd!d"„ƒZejƒee	ee
ddfd#œd$d%„ƒZejedœd&d'„ƒZ ejd(d)d*ddœd+d,„ƒZ!ejeddœd-d.„ƒZ"ejd
de	d/d0œd1d2„ƒZ#ejed/d3œd4d5„ƒZ$ejd6d7„ƒZ%dS)8zSphinx test fixtures for pytestéN)Ú
namedtuple)ÚStringIO)ÚPIPE)ÚAnyÚCallableÚDictÚ	GeneratorÚTuple)Úutil)Ú
SphinxTestAppÚ#SphinxTestAppWrapperForSkipBuildingz¢sphinx(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.cCsxtD]}|jd|ƒqWdS)zRegister custom markersÚmarkersN)ÚDEFAULT_ENABLED_MARKERSZaddinivalue_line)ÚconfigÚmarker©rú9/tmp/pip-build-gk9425m9/sphinx/sphinx/testing/fixtures.pyÚpytest_configures
rÚsession)Úscope)ÚreturncCsdS)NrrrrrÚrootdirsrc@sPeZdZUiZeeeeeffeeedœdd„Zeeee	fdœdd„Z
dS)ÚSharedResult)ÚkeyÚapp_rcCs2||jkrdS|jjƒ|jjƒdœ}||j|<dS)N)ÚstatusÚwarning)ÚcacheÚ_statusÚgetvalueÚ_warning)ÚselfrrÚdatarrrÚstore&s

zSharedResult.store)rrcCs2||jkriS|j|}t|dƒt|dƒdœS)Nrr)rr)rr)r!rr"rrrÚrestore/s



zSharedResult.restoreN)Ú__name__Ú
__module__Ú__qualname__rrÚstrrrr#rr$rrrrr#s
	r)ÚrequestÚtest_paramsÚ
shared_resultÚsphinx_test_tempdirrrcs,t|jdƒr|jjdƒ}n|jjdƒ}i‰i}|dk	rxx@tt|ƒƒD]0}xt|jƒD]\}}	|	ˆ|<qTW|j|j	ƒqDW‡fdd„t
ˆjƒƒDƒ}
|drÐd|kr¬tj
dƒ‚|d|d<|j|dƒ}|j|ƒ|jd	d
ƒ}||jd|ƒ|d<}
|r|
jƒr|d|}|j|
ƒtdd
ƒ|
|ƒS)zp
    Parameters that are specified by 'pytest.mark.sphinx' for
    sphinx.application.Sphinx initialization
    Úiter_markersZsphinxNcsg|]}ˆ|‘qSrr)Ú.0Úi)Úpargsrrú
<listcomp>Qszapp_params.<locals>.<listcomp>r+Úsrcdirz:You can not specify shared_result and srcdir in same time.ÚtestrootÚrootztest-Ú
app_paramszargs,kwargs)ÚhasattrÚnoder-Ú
get_markerÚreversedÚlistÚ	enumerateÚargsÚupdateÚkwargsÚsortedÚkeysÚpytestÚ	Exceptionr$ÚpopÚgetÚexistsÚcopytreer)r)r*r+r,rr
r>Úinfor/Úar<r$r3r2Z
testroot_pathr)r0rr59s.



r5)r)rcCslt|jdƒr|jjdƒ}n|jjdƒ}|r0|jni}ddi}|j|ƒ|drht|dtƒrhtj	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" )
r6r7rIr8r>r=Ú
isinstancer(rArB)r)Úenvr>Úresultrrrr*is

r*Úfunction)r*r5Úmake_appr+rccs”|\}}|||Ž}|Vtd|jddƒƒtd|jjƒtd|jƒtd|jƒtdd|jjƒƒtd	d|jjƒƒ|d
r|j	|d
|ƒdS)z9
    Provides the 'sphinx.application.Sphinx' object
    z# testroot:r3r4z
# builder:z	# srcdir:z	# outdir:z	# status:Ú
z
# warning:r+N)
ÚprintrDZbuilderÚnamer2Zoutdirrrr r#)r*r5rNr+r<r>rrrrÚapp„s
rR)rRrcCs|jS)zJ
    Back-compatibility for testing with previous @with_app decorator
    )r)rRrrrr™srcCs|jS)zJ
    Back-compatibility for testing with previous @with_app decorator
    )r )rRrrrr¡sr)r*Úmonkeypatchrc#sb|jddd„ƒg‰tjdd…}‡‡fdd„}|V|tjdd…<xtˆƒD]}|jƒqNWdS)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|S)Nr)ÚxrrrÚ<lambda>°szmake_app.<locals>.<lambda>NcsNtƒtƒ}}|jd|ƒ|jd|ƒt||Ž}ˆj|ƒˆdrJt|ƒ}|S)Nrrr+)rÚ
setdefaultrÚappendr)r<r>rrr)Úappsr*rrÚmakeµs

zmake_app.<locals>.make)ÚsetattrÚsysÚpathr9Úcleanup)r*rSZsyspathrYrr)rXr*rrN©s	rNcCstƒS)N)rrrrrr+Åsr+ÚmoduleT)rZautousecCstjjƒdS)N)rrÚclearrrrrÚ_shared_result_cacheÊsr`cCsRt|jddƒ}y |r,tj|dgttddSWntk
rBYnXtjdƒdS)zt
    The test will be skipped when using 'if_graphviz_found' fixture and graphviz
    dot command is not found.
    Úgraphviz_dotÚz-V)ÚstdoutÚstderrNzgraphviz "dot" is not available)ÚgetattrrÚ
subprocessÚrunrÚOSErrorrAÚskip)rRrarrrÚif_graphviz_foundÏsrjz	util.path)Útmpdir_factoryrcCs|jƒ}tj|ƒjƒS)z8
    Temporary directory wrapped with `path` class.
    )Zgetbasetempr
r\Úabspath)rkÚtmpdirrrrr,àsr,)rmrcCs
tj|ƒS)z
    Temporary directory wrapped with `path` class.
    This fixture is for back-compatibility with old test implementation.
    )r
r\)rmrrrÚtempdirésrnccsDzttjƒ}dVWdx&ttjƒD]}||kr"tjj|ƒq"WXdS)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:r[ÚmodulesrC)Z
sysmodulesÚmodnamerrrÚrollback_sysmodulesòs	

rq)&Ú__doc__rfr[ÚcollectionsrÚiorrÚtypingrrrrr	rAZsphinx.testingr
Zsphinx.testing.utilrrrrZfixturer(rrr5r*rRrrrNr+r`rjr,rnrqrrrrÚ<module>sP
.