3

T'íc!ã@s¢dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZm
Z
mZddlmZddlmZddlmZddlmZmZdd	lmZmZdd
lmZddlmZddlm Z d
ddgZ!d+ee"e#ddœdd„Z$d,ee"e#ddœdd„Z%e"e"ddœdd„Z&d-ee
e"e
ddœdd„Z'e"e
dœdd„Z(Gdd
„d
ƒZ)Gd d„dej*ƒZ+Gd!d„dƒZ,ej-d"ƒZ.d.e"e/ee"ddfd#œd$d%„Z0e"e"d&œd'd(„Z1d)d*„Z2dS)/zSphinx test suite utilitieséN)ÚStringIO)ÚIOÚAnyÚDictÚ	GeneratorÚListÚPattern)ÚElementTree)Únodes)ÚNode)Ú
directivesÚroles)ÚapplicationÚlocale)ÚModuleAnalyzer)Úpath)ÚrelpathÚStructÚ
SphinxTestAppÚ#SphinxTestAppWrapperForSkipBuilding)ÚregexÚtextÚflagsÚreturncCs&tj|||ƒs"ds"td||fƒ‚dS)NFz%r did not match %r)ÚreÚsearchÚAssertionError)rrr©rú5/tmp/pip-build-gk9425m9/sphinx/sphinx/testing/util.pyÚassert_re_searchsrcCs&tj|||ƒr"ds"td||fƒ‚dS)NFz%r did match %r)rrr)rrrrrrÚassert_not_re_searchsr )ÚthingÚprefixrcCs"|j|ƒsdstd||fƒ‚dS)NFz%r does not start with %r)Ú
startswithr)r!r"rrrÚassert_startswith#s
r$Ú)ÚnodeÚclsÚxpathÚkwargsrc	Ks|rœt|tƒrÀt||dfd|i|—Ž|dd…r¾t|dtƒr`t||dfd|i|—Žn^t|tjƒsxtd|ƒ‚t|ƒdks˜td|t|ƒfƒ‚t|d|dd…fd|di|—ŽnÜt|tƒrTt|ttjfƒsètd|ƒ‚t|ƒt|ƒkstd|t|ƒt|ƒfƒ‚x†t|ƒD]0\}}|d	|}t|||fd|i|—ސqWnHt|t	ƒr~||ksœtd
|||fƒ‚nt||ƒsœtd|||fƒ‚|rt|tjƒs¼td|ƒ‚xX|j
ƒD]L\}}||ksêtd
|||fƒ‚|||ksÆtd|||||fƒ‚qÆWdS)Nrr(éz%The node%s does not have any childrenz&The node%s has %d child nodes, not onez[0]z"The node%s does not have any itemsz%The node%s has %d child nodes, not %rz[%d]zThe node %r is not %r: %rz$The node%s is not subclass of %r: %rz'The node%s does not have any attributesz)The node%s does not have %r attribute: %rzThe node%s[%s] is not %r: %r)Ú
isinstanceÚlistÚassert_nodeÚtupler
ÚElementrÚlenÚ	enumerateÚstrÚitems)	r&r'r(r)ÚiZnodeclsrÚkeyÚvaluerrrr-(s>

(
"
r-)rrcCs0tjddtjdtdtj|ƒSQRXdS)NF)ÚrecordÚignore)Úcategory)ÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarningr	Úparse)rrrrÚetree_parseNsr?c@seZdZeddœdd„ZdS)rN)r)rcKs|jj|ƒdS)N)Ú__dict__Úupdate)Úselfr)rrrÚ__init__UszStruct.__init__)Ú__name__Ú
__module__Ú__qualname__rrCrrrrrTsc
sreZdZUdZdZedZedeeee	e
eeeeee
ddœ‡fdd„
Zde	dd	œd
d„Zedœd
d„Z‡ZS)rzŠ
    A subclass of :class:`Sphinx` that runs on the test root, with some
    better default values for the initialization parameters.
    NÚhtmlFr)ÚbuildernameÚsrcdirÚbuilddirÚfreshenvÚ
confoverridesÚstatusÚwarningÚtagsÚdocutilsconfÚparallelrcsð|	dk	r|dj|	ƒ|dkr&|d}|}|j|ƒ}|jdd|jdƒ}
|
jdd|dkrbi}d}tjdd…|_tjjƒ|_	t
jjƒ|_dd„t
tjƒDƒ|_y(tƒj||||
||||||||
d	Wntk
rê|jƒ‚YnXdS)
Nz
docutils.confZ_buildT)Úexist_okÚdoctreesFcSsh|]}|jdƒr|’qS)Úvisit_)r#)Ú.0Úvrrrú	<setcomp>ysz)SphinxTestApp.__init__.<locals>.<setcomp>)rQ)Z
write_textZjoinpathÚmakedirsÚsysrÚ_saved_pathrÚ_directivesÚcopyÚ_saved_directivesr
Ú_rolesÚ_saved_rolesÚdirr
ÚGenericNodeVisitorÚ_saved_nodeclassesÚsuperrCÚ	ExceptionÚcleanup)rBrHrIrJrKrLrMrNrOrPrQZconfdirÚoutdirZ
doctreedirZwarningiserror)Ú	__class__rrrCas.

zSphinxTestApp.__init__)rSrcCsžtjjƒtjjƒ|jtjdd…<tjj	ddƒ|j
t_|j
t_xVttjƒD]H}|jdƒrN||jkrNttjd|dd…ƒttjd|dd…ƒqNWdS)NZautodoc_fodderrTéZdepart_)rÚcacheÚclearrZtranslatorsrZrYrÚmodulesÚpopr]rr[r_r
r^r`r
rar#rbÚdelattr)rBrSÚmethodrrrre„s



zSphinxTestApp.cleanup)rcCsd|jj|jjfS)Nz<%s buildername=%r>)rgrDZbuilderÚname)rBrrrÚ__repr__‘szSphinxTestApp.__repr__)
rGNNFNNNNNr)F)rDrErFÚ__doc__Z_statusrZ_warningr2rÚboolrrrÚintrCrerpÚ
__classcell__rr)rgrrYs
, 
c@sBeZdZdZeddœdd„Zeedœdd„Zeedd	œd
d„Z	dS)rzª
    This class is a wrapper for SphinxTestApp to speed up the test by skipping
    `app.build` process if it is already built and there is even one output
    file.
    N)Úapp_rcCs
||_dS)N)Úapp)rBrurrrrCœsz,SphinxTestAppWrapperForSkipBuilding.__init__)rorcCst|j|ƒS)N)Úgetattrrv)rBrorrrÚ__getattr__Ÿsz/SphinxTestAppWrapperForSkipBuilding.__getattr__)Úargsr)rcOs|jjjƒs|jj||ŽdS)N)rvrfÚlistdirÚbuild)rBryr)rrrr{¢sz)SphinxTestAppWrapperForSkipBuilding.build)
rDrErFrqrrCr2rrxr{rrrrr•szu(".*?")|u(\'.*?\'))ÚrootÚsuffixrc#sZxTtj|ddD]B\}}}t|ƒ}x.‡fdd„|DƒD]}||}t||ƒVq6WqWdS)NT)Úfollowlinkscs g|]}ˆs|jˆƒr|‘qSr)Úendswith)rUÚf)r}rrú
<listcomp>¯szfind_files.<locals>.<listcomp>)ÚosÚwalkrr)r|r}ÚdirpathZ_dirsÚfilesr€Zfpathr)r}rÚ
find_files¬s
r†)rrcCstjdd|ƒS)Nz.*?mr%)rÚsub)rrrrÚstrip_escseq´srˆcstjˆƒ‡fdd„ƒ}|S)zA
    A simple decorator that does nothing, for tests to use.
    cs
ˆ||ŽS)Nr)ryr))r€rrÚwrapper¼sz!simple_decorator.<locals>.wrapper)Ú	functoolsÚwraps)r€r‰r)r€rÚsimple_decorator¸srŒ)r)r)Nr%)N)3rqrŠr‚rrYr:ÚiorÚtypingrrrrrrZ	xml.etreer	Zdocutilsr
Zdocutils.nodesrZdocutils.parsers.rstrr
ZsphinxrrZ
sphinx.pycoderZsphinx.testing.pathrZsphinx.util.osutilrÚ__all__r2rsrr r$r-r?rZSphinxrrÚcompileZ_unicode_literals_rerrr†rˆrŒrrrrÚ<module>s8 
&<