ó
öÀ„\c           @  sâ  d  Z  d d l m 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
 Z
 d d l m Z m Z d d l m Z e r± d d	 l m Z m Z m Z n  e
 j d
 d ƒ d „  ƒ Z e
 j d „  ƒ Z e
 j d „  ƒ Z e
 j d
 d ƒ d „  ƒ Z e
 j d
 d ƒ d „  ƒ Z e
 j d
 d ƒ d „  ƒ Z e
 j ƒ  d „  ƒ Z d e f d „  ƒ  YZ e
 j d „  ƒ Z e
 j d
 d d e  ƒ d „  ƒ Z! e
 j d „  ƒ Z" e
 j d
 d ƒ d „  ƒ Z# e
 j d „  ƒ Z$ d S(   sÐ   
    sphinx.testing.fixtures
    ~~~~~~~~~~~~~~~~~~~~~~~

    Sphinx test fixtures for pytest

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿ(   t   print_functionN(   t
   namedtuple(   t
   gettempdir(   t   StringIOt   string_typesi   (   t   util(   t   Anyt   Dictt   Uniont   scopet   sessionc           C  s   d  S(   N(   t   None(    (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   rootdir   s    c         C  s¤  t  |  j d ƒ r' |  j j d ƒ } n |  j j d ƒ } i  } i  } | d k	 r« xW t t | ƒ ƒ D]@ } x' t | j ƒ D] \ }	 }
 |
 | |	 <qz W| j	 | j
 ƒ qd Wn  g  t | j ƒ  ƒ D] }	 | |	 ^ q¾ } | d r-d | k rü t j d ƒ ‚ n  | d | d <| j | d ƒ } | j	 | ƒ n  | j d d ƒ } | | j d | ƒ | d <} | rŽ| j ƒ  rŽ| d | } | j | ƒ n  t d	 d
 ƒ | | ƒ S(   so   
    parameters that is specified by 'pytest.mark.sphinx' for
    sphinx.application.Sphinx initialization
    t   iter_markerst   sphinxt   shared_resultt   srcdirs9   You can not spcify shared_result and srcdir in same time.t   testroott   roots   test-t
   app_paramss   args,kwargsN(   t   hasattrt   nodeR   t
   get_markerR   t   reversedt   listt	   enumeratet   argst   updatet   kwargst   sortedt   keyst   pytestt	   Exceptiont   restoret   popt   gett   existst   copytreeR   (   t   requestt   test_paramsR   t   sphinx_test_tempdirR   t   markerst   pargsR   t   infot   it   aR   R!   R   R   t   testroot_path(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR   #   s.    
)
c         C  sœ   t  |  j d ƒ r' |  j j d ƒ } n |  j j d ƒ } | rH | j n i  } i d d 6} | j | ƒ | d r˜ t | d t ƒ r˜ t	 j
 d ƒ ‚ n  | S(   s|  
    test parameters that is 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 shared_result and srcdir in same time.
    t   get_closest_markerR'   R   s@   You can only provide a string type of value for "shared_result" N(   R   R   R/   R   R   R   R   t
   isinstanceR   R   R    (   R&   t   envR   t   result(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR'   T   s    

t   functionc         c  sÅ   | \ } } | | | Ž  } | Vt  d | j d d ƒ ƒ t  d | j j ƒ t  d | j ƒ t  d | j ƒ t  d d | j j ƒ  ƒ t  d	 d | j j ƒ  ƒ |  d
 rÁ | j	 |  d
 | ƒ n  d S(   s3   
    provides sphinx.application.Sphinx object
    s   # testroot:R   R   s
   # builder:s	   # srcdir:s	   # outdir:s	   # status:s   
s
   # warning:R   N(
   t   printR#   t   buildert   nameR   t   outdirt   _statust   getvaluet   _warningt   store(   R'   R   t   make_appR   R   R   t   app_(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   appp   s    
c         C  s   |  j  S(   s>   
    compat for testing with previous @with_app decorator
    (   R8   (   R>   (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   status„   s    c         C  s   |  j  S(   s>   
    compat for testing with previous @with_app decorator
    (   R:   (   R>   (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   warningŒ   s    c         #  si   | j  d d „  ƒ g  ‰  t j } ‡  ‡ f d †  } | V| t j (x t ˆ  ƒ D] } | j ƒ  qQ Wd S(   sÉ   
    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.
    s   sphinx.application.abspathc         S  s   |  S(   N(    (   t   x(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   <lambda>›   s    c            sr   t  ƒ  t  ƒ  } } | j d | ƒ | j d | ƒ t j |  | Ž  } ˆ  j | ƒ ˆ d rn t j | ƒ } n  | S(   NR?   R@   R   (   R   t
   setdefaultR   t   SphinxTestAppt   appendt#   SphinxTestAppWrapperForSkipBuilding(   R   R   R?   R@   R=   (   t   appsR'   (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   make    s    
N(   t   setattrt   syst   pathR   t   cleanup(   R'   t   monkeypatcht   syspathRH   R=   (    (   RG   R'   s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR<   ”   s    
	
t   SharedResultc           B  s    e  Z i  Z d  „  Z d „  Z RS(   c         C  sJ   | |  j  k r d  Si | j j ƒ  d 6| j j ƒ  d 6} | |  j  | <d  S(   NR?   R@   (   t   cacheR8   R9   R:   (   t   selft   keyR=   t   data(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR;   ³   s    c         C  sF   | |  j  k r i  S|  j  | } i t | d ƒ d 6t | d ƒ d 6S(   NR?   R@   (   RP   R   (   RQ   RR   RS   (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR!   ¼   s    (   t   __name__t
   __module__RP   R;   R!   (    (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyRO   °   s   		c           C  s   t  ƒ  S(   N(   RO   (    (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR   Æ   s    t   modulet   autousec           C  s   t  j j ƒ  d  S(   N(   RO   RP   t   clear(    (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   _shared_result_cacheË   s    c         C  sy   t  |  j d d ƒ } y? | rS t j | d g d t j d t j ƒ} | j ƒ  d SWn t k
 rg n Xt j d ƒ d S(   st   
    The test will be skipped when using 'if_graphviz_found' fixture and graphviz
    dot command is not found.
    t   graphviz_dott    s   -Vt   stdoutt   stderrNs   graphviz "dot" is not available(	   t   getattrt   configt
   subprocesst   Popent   PIPEt   communicatet   OSErrorR   t   skip(   R>   RZ   t   dot(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   if_graphviz_foundÐ   s    	
c           C  s%   t  j t j j d t ƒ  ƒ ƒ j ƒ  S(   s=   
    temporary directory that wrapped with `path` class.
    t   SPHINX_TEST_TEMPDIR(   R   RK   t   ost   environR#   R   t   abspath(    (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyR(   ä   s    c         C  s   t  j |  ƒ S(   sz   
    temporary directory that wrapped with `path` class.
    this fixture is for compat with old test implementation.
    (   R   RK   (   t   tmpdir(    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   tempdirì   s    (%   t   __doc__t
   __future__R    Ri   R`   RJ   t   collectionsR   t   tempfileR   R   t   sixR   R   R[   R   t   Falset   typingR   R   R   t   fixtureR   R   R'   R>   R?   R@   R<   t   objectRO   R   t   TrueRY   Rg   R(   Rm   (    (    (    s6   lib/python2.7/site-packages/sphinx/testing/fixtures.pyt   <module>
   s0   1!