ó
öÀ„\c           @   sê  d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l	 m
 Z
 m Z d d l m Z d d l m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z e r)d d l m Z d d l m Z m Z m  Z  m! Z! m Z m" Z" n  d d d d g Z# d d „ Z$ d d „ Z% d „  Z& d d d „ Z( d „  Z) d e* f d „  ƒ  YZ+ d e j, f d „  ƒ  YZ- d e* f d „  ƒ  YZ. e j/ d ƒ Z0 d „  Z1 d d „ Z2 d  „  Z3 d S(!   sÄ   
    sphinx.testing.util
    ~~~~~~~~~~~~~~~~~~~

    Sphinx test suite utilities

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   ElementTree(   t   nodes(   t
   directivest   roles(   t   string_types(   t   applicationt   locale(   t   LaTeXBuilder(   t   AutoDirective(   t   ModuleAnalyzer(   t   path(   t   relpath(   t   List(   t   Anyt   Dictt	   Generatort   IOR   t   Patternt   Structt   SphinxTestAppt#   SphinxTestAppWrapperForSkipBuildingt   remove_unicode_literalsi    c         C   s8   t  j |  | | ƒ s4 t s4 t d |  | f ƒ ‚ n  d  S(   Ns   %r did not match %r(   t   ret   searcht   Falset   AssertionError(   t   regext   textt   flags(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   assert_re_search)   s    c         C   s8   t  j |  | | ƒ r4 t s4 t d |  | f ƒ ‚ n  d  S(   Ns   %r did match %r(   R   R   R   R   (   R   R   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   assert_not_re_search/   s    c         C   s2   |  j  | ƒ s. t s. t d |  | f ƒ ‚ n  d  S(   Ns   %r does not start with %r(   t
   startswithR   R   (   t   thingt   prefix(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   assert_startswith5   s    t    c   	      K   s+  | rµt  | t ƒ r¿ t |  | d d | | | d r²t  | d t ƒ ri t |  | d d | | q¼ t |  ƒ d k s— t d | t |  ƒ f ƒ ‚ t |  d | d d | d | q²qµt  | t ƒ rSt |  ƒ t | ƒ k st d | t |  ƒ t | ƒ f ƒ ‚ x¤ t | ƒ D]4 \ } } | d | } t |  | | d | | qWqµt  | t ƒ rŠ|  | k s²t d | | |  f ƒ ‚ qµt  |  | ƒ sµt d	 | | |  f ƒ ‚ n  xo | j ƒ  D]a \ } } | |  k sót d
 | | |  f ƒ ‚ |  | | k sÂt d | | | |  | f ƒ ‚ qÂWd  S(   Ni    t   xpathi   s&   The node%s has %d child nodes, not ones   [0]s%   The node%s has %d child nodes, not %rs   [%d]s   The node %r is not %r: %rs$   The node%s is not subclass of %r: %rs)   The node%s does not have %r attribute: %rs   The node%s[%s] is not %r: %r(	   t
   isinstancet   listt   assert_nodet   tuplet   lenR   t	   enumerateR   t   items(	   t   nodet   clsR$   t   kwargst   it   nodeclsR
   t   keyt   value(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR'   ;   s.    
("!(%c         C   s=   t  j d t ƒ % t  j d d t ƒt j |  ƒ SWd  QXd  S(   Nt   recordt   ignoret   category(   t   warningst   catch_warningsR   t   filterwarningst   DeprecationWarningR    t   parse(   R
   (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   etree_parseY   s    c           B   s   e  Z d  „  Z RS(   c         K   s   |  j  j | ƒ d  S(   N(   t   __dict__t   update(   t   selft   kwds(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   __init__a   s    (   t   __name__t
   __module__R@   (    (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR   `   s   c        	   B   sD   e  Z d  Z d d e d d d d d d „ Z e d „ Z d „  Z RS(   sŠ   
    A subclass of :class:`Sphinx` that runs on the test root, with some
    better default values for the initialization parameters.
    t   htmlc	         C   sH  | d  k	 r  | d j | ƒ n  | d }	 | }
 |	 j | ƒ } | j ƒ  sX | j ƒ  n  |	 j d ƒ } | j ƒ  s€ | j ƒ  n  | d  k r• i  } n  t } t j |  _ t	 j
 j ƒ  |  _ t j j ƒ  |  _ t d „  t t j ƒ Dƒ ƒ |  _ y5 t j j |  | |
 | | | | | | | | | ƒ Wn t k
 rC|  j ƒ  ‚  n Xd  S(   Ns   docutils.conft   _buildt   doctreesc         s   s$   |  ] } | j  d  ƒ r | Vq d S(   t   visit_N(   R   (   t   .0t   v(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pys	   <genexpr>ˆ   s    (   t   Nonet
   write_textt   joinpatht   isdirt   makedirsR   t   sysR
   t   _saved_pathR   t   _directivest   copyt   _saved_directivesR   t   _rolest   _saved_rolest   sett   dirR   t   GenericNodeVisitort   _saved_nodeclassesR   t   SphinxR@   t	   Exceptiont   cleanup(   R>   t   buildernamet   srcdirt   freshenvt   confoverridest   statust   warningt   tagst   docutilsconft   builddirt   confdirt   outdirt
   doctreedirt   warningiserror(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR@   l   s0    
	"
c         C   s×   t  j j ƒ  t j j ƒ  g  t _ t j j ƒ  |  j	 t
 j (t
 j j d d  ƒ |  j t _ |  j t _ xh t t j ƒ D]W } | j d ƒ rx | |  j k rx t t j d | d ƒ t t j d | d ƒ qx qx Wd  S(   Nt   autodoc_fodderRF   i   t   depart_(   R   t	   _registryt   clearR	   t   cacheR   t   usepackagesR   t   translatorsRO   RN   R
   t   modulest   popRI   RR   R   RP   RT   R   RS   RV   R   RW   R   RX   t   delattr(   R>   RE   t   method(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR[   “   s    	c         C   s   d |  j  j |  j j f S(   Ns   <%s buildername=%r>(   t	   __class__RA   t   buildert   name(   R>   (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   __repr__£   s    N(   RA   RB   t   __doc__RI   R   R@   R[   Rw   (    (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR   f   s   %c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sª   
    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.
    c         C   s   | |  _  d  S(   N(   t   app(   R>   t   app_(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR@   ¯   s    c         C   s   t  |  j | ƒ S(   N(   t   getattrRy   (   R>   Rv   (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   __getattr__³   s    c         O   s,   |  j  j j ƒ  s( |  j  j | | Ž  n  d  S(   N(   Ry   Rf   t   listdirt   build(   R>   t   argst   kw(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR~   ·   s    (   RA   RB   Rx   R@   R|   R~   (    (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR   ¨   s   		s   u(".*?")|u(\'.*?\')c         C   s   t  j d „  |  ƒ S(   Nc         S   s   |  j  d ƒ p |  j  d ƒ S(   Ni   i   (   t   group(   t   x(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   <lambda>Ä   s    (   t   _unicode_literals_ret   sub(   t   s(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyR   Â   s    c         c   s‹   x„ t  j |  d t ƒD]m \ } } } t | ƒ } xO g  | D]" } | sW | j | ƒ r; | ^ q; D] } | | } t | |  ƒ Vqa Wq Wd  S(   Nt   followlinks(   t   ost   walkt   TrueR
   t   endswithR   (   t   roott   suffixt   dirpatht   dirst   filest   ft   fpath(    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt
   find_filesÇ   s
    %6
c         C   s   t  j d d |  ƒ S(   Ns   .*?mR#   (   R   R…   (   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   strip_escseqÐ   s    (4   Rx   Rˆ   R   RN   R6   t	   xml.etreeR    t   docutilsR   t   docutils.parsers.rstR   R   t   sixR   t   sphinxR   R   t   sphinx.builders.latexR   t   sphinx.ext.autodocR   t   sphinx.pycodeR	   t   sphinx.testing.pathR
   t   sphinx.util.osutilR   R   t   typingR   R   R   R   R   R   t   __all__R   R   R"   RI   R'   R;   t   objectR   RY   R   R   t   compileR„   R   R“   R”   (    (    (    s2   lib/python2.7/site-packages/sphinx/testing/util.pyt   <module>
   s@   1			B		