o $a @sdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZddlmZddlmZddlmZddlmZmZdd lmZmZdd lmZdd lmZdd lm Z gd Z!d3dede"de#ddfddZ$d3dede"de#ddfddZ%de"de"ddfddZ&d4dede de"de ddf dd Z'd!e"de fd"d#Z(Gd$d%d%Z)Gd&d'd'ej*Z+Gd(d)d)Z,e-d*Z.d5d+e"d,e/de e"ddffd-d.Z0de"de"fd/d0Z1d1d2Z2dS)6z sphinx.testing.util ~~~~~~~~~~~~~~~~~~~ Sphinx test suite utilities :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)StringIO)IOAnyDict GeneratorListPattern) ElementTree)nodes)Node) directivesroles) applicationlocale)ModuleAnalyzerpath)relpath)Struct SphinxTestApp#SphinxTestAppWrapperForSkipBuildingregextextflagsreturncCs"t|||sJd||fdS)NFz%r did not match %rresearchrrrr5/usr/lib/python3/dist-packages/sphinx/testing/util.pyassert_re_search!r!cCs"t|||rJd||fdS)NFz%r did match %rrrrrr assert_not_re_search&r"r#thingprefixcCs||s Jd||fdS)NFz%r does not start with %r startswith)r$r%rrr assert_startswith+s r(nodeclsxpathkwargsc Ks|rt|tr_t||dfd|i||ddr^t|dtr/t||dfd|i|nt|tjs;Jd|t|dksKJd|t|ft|d|ddfd|di|nft|trt|ttjfsrJd|t|t|ksJd|t|t|ft|D]\}}|d |}t|||fd|i|qn!t|tr||ksJd |||fnt||sJd |||f|rt|tjsJd || D]%\}}||vsJd |||f|||ksJd|||||fqdSdS)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) isinstancelist assert_nodetupler Elementlen enumeratestritems) r*r+r,r-inodeclsrkeyvaluerrr r10sV  &       r1rcCsHtjddtjdtdt|WdS1swYdS)NF)recordignore)category)warningscatch_warningsfilterwarningsDeprecationWarningr parserrrr etree_parseVs$rDc@seZdZdeddfddZdS)rr-rNcKs|j|dSN)__dict__update)selfr-rrr __init__]szStruct.__init__)__name__ __module__ __qualname__rrIrrrr r\srcseZdZUdZdZeed<dZeed<    dded e d e d e d e d e de de edededdffdd Zdde ddfddZdefddZZS)rz A subclass of :class:`Sphinx` that runs on the test root, with some better default values for the initialization parameters. N_status_warninghtmlFr buildernamesrcdirbuilddirfreshenv confoverridesstatuswarningtags docutilsconfparallelrc s| dur |d| |dur|d}|} ||} | jdd|d} | jdd|dur1i}d}tjdd|_tj|_ t j |_ ddt tjD|_ztj|| | | |||||||| d WdStys|w) Nz docutils.conf_buildT)exist_okdoctreesFcSsh|] }|dr|qS)visit_r&).0vrrr s z)SphinxTestApp.__init__..)rY) write_textjoinpathmakedirssysr _saved_pathr _directivescopy_saved_directivesr _roles _saved_rolesdirr GenericNodeVisitor_saved_nodeclassessuperrI Exceptioncleanup)rHrPrQrRrSrTrUrVrWrXrYconfdiroutdir doctreedirwarningiserror __class__rr rIis2       zSphinxTestApp.__init__r\cCstjtj|jtjdd<tj dd|j t _ |j t_ttjD]$}|drJ||jvrJttjd|ddttjd|ddq&dS)Nautodoc_fodderr]depart_)rcacheclearr translatorsrerdrmodulespoprhr rfrjr rirkr rlr'rmdelattr)rHr\methodrrr rps    zSphinxTestApp.cleanupcCsd|jj|jjfS)Nz<%s buildername=%r>)rvrJbuildername)rHrrr __repr__szSphinxTestApp.__repr__) rONNFNNNNNr)F)rJrKrL__doc__rMr__annotations__rNr6rboolrrrintrIrpr __classcell__rrrur ras6   # rc@sJeZdZdZdeddfddZdedefdd Zd ed eddfd 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. app_rNcCs ||_dSrE)app)rHrrrr rIs z,SphinxTestAppWrapperForSkipBuilding.__init__rcCs t|j|SrE)getattrr)rHrrrr __getattr__s z/SphinxTestAppWrapperForSkipBuilding.__getattr__argsr-cOs&|jjs|jj|i|dSdSrE)rrrlistdirbuild)rHrr-rrr rs z)SphinxTestAppWrapperForSkipBuilding.build) rJrKrLrrrIr6rrrrrrr rs rzu(".*?")|u(\'.*?\')rootsuffixc#sTtj|ddD]\}}}t|}fdd|DD] }||}t||VqqdS)NT) followlinkscsg|] }r |r|qSr)endswith)r^frrr szfind_files..)oswalkrr)rrdirpathdirsfilesrfpathrrr find_filessrcCstdd|S)Nz.*?mr))rsub)rrrr strip_escseqsrcstfdd}|S)zA A simple decorator that does nothing, for tests to use. cs|i|SrEr)rr-rrr wrappersz!simple_decorator..wrapper) functoolswraps)rrrrr simple_decoratorsr)r)Nr)rE)3rrrrrdr?iortypingrrrrrr xml.etreer docutilsr docutils.nodesr docutils.parsers.rstr r sphinxrr sphinx.pycodersphinx.testing.pathrsphinx.util.osutilr__all__r6rr!r#r(r1rDrSphinxrrcompile_unicode_literals_rerrrrrrrr s:          &< "