
^Yc           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z m	 Z	 m
 Z
 d d l m Z d Z d Z d Z d	 Z d
 Z e e e e e f Z d   Z d   Z d   Z d e
 f d     YZ d e j f d     YZ d   Z d   Z d e j f d     YZ d   Z d e j f d     YZ d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ e j% d d   d!    Z& d S("   s5    discover and run doctests in modules and test files.i    (   t   absolute_importt   divisiont   print_functionN(   t   ExceptionInfot   ReprFileLocationt   TerminalRepr(   t   FixtureRequestt   nonet   cdifft   ndifft   udifft   only_first_failurec         C` s   |  j  d d d d d d g |  j  d d d d	 |  j d
  } | j d d d d t d d d d | j d d t j d d d d d t d d | j d d d d g  d d d d d d | j d d d d t d d d d d  S(    Nt   doctest_optionflagss   option flags for doctestst   typet   argst   defaultt   ELLIPSISt   doctest_encodings   encoding used for doctest filess   utf-8t   collects   --doctest-modulest   actiont
   store_truet   helps   run doctests in all .py modulest   destt   doctestmoduless   --doctest-reportR
   s9   choose another output format for diffs on doctest failuret   choicest   doctestreports   --doctest-globt   appendt   metavart   pats2   doctests file matching pattern, default: test*.txtt   doctestglobs   --doctest-ignore-import-errorss   ignore doctest ImportErrorst   doctest_ignore_import_errors(   t   addinit   getgroupt	   addoptiont   Falset   strt   lowert   DOCTEST_REPORT_CHOICES(   t   parsert   group(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   pytest_addoption   s*    c         C` sW   | j  } |  j d k r4 | j j rS t |  |  Sn t | |  |  rS t |  |  Sd  S(   Ns   .py(   t   configt   extt   optionR   t   DoctestModulet   _is_doctestt   DoctestTextfile(   t   patht   parentR)   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   pytest_collect_file1   s    	c         C` sh   | j  d k r% | j j |  r% t S|  j d  p: d g } x$ | D] } | j d |  rD t SqD Wt S(   Ns   .txts   .rstR   s	   test*.txtt   fnmatch(   s   .txts   .rst(   R*   t   sessiont
   isinitpatht   Truet	   getoptiont   checkR"   (   R)   R/   R0   t   globst   glob(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR-   :   s    !t   ReprFailDoctestc           B` s   e  Z d    Z d   Z RS(   c         C` s   | |  _  | |  _ d  S(   N(   t   reprlocationt   lines(   t   selfR;   R<   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   __init__F   s    	c         C` s5   x |  j  D] } | j |  q
 W|  j j |  d  S(   N(   R<   t   lineR;   t
   toterminal(   R=   t   twR?   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR@   J   s    (   t   __name__t
   __module__R>   R@   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR:   D   s   	t   DoctestItemc           B` s;   e  Z d d d   Z d   Z d   Z d   Z d   Z RS(   c         C` sA   t  t |   j | |  | |  _ | |  _ d  |  _ d  |  _ d  S(   N(   t   superRD   R>   t   runnert   dtestt   Nonet   objt   fixture_request(   R=   t   nameR0   RF   RG   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR>   Q   s
    			c         C` s   |  j  d  k	 r| t |   |  _ t d |  j j  } x0 |  j j d  j   D] \ } } | | | <qL W|  j  j j |  n  d  S(   Nt
   getfixturet   doctest_namespace(	   RG   RH   t   _setup_fixturesRJ   t   dictt   getfixturevaluet   itemsR8   t   update(   R=   R8   RK   t   value(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   setupX   s    %c         C` s$   t  |  j  |  j j |  j  d  S(   N(   t   _check_all_skippedRG   RF   t   run(   R=   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   runtest`   s    c         C` s  d d  l  } | j | j | j f  r| j } | j } | j } | j } | j d  k rc d  } n | j | j d } | j
 j } t | | |  }	 t   }
 t |  j j d   } | d  k	 r/| j j j t  } g  t |  D]' \ } } d | | j d | f ^ q } | | j d | j d !} nF d g } d } x4 | j j   D]# } | j d | | f  d	 } qNW| j | j  r| |
 j | | j |  j d
  7} nE t | j j  } | d t | j  g 7} | t j | j j   7} t |	 |  St  t! |   j" |  Sd  S(   Ni    i   R   s   %03d %si	   s?   EXAMPLE LOCATION UNKNOWN, not showing all tests of that examples   >>>s	   ??? %s %ss   ...s   
s   UNEXPECTED EXCEPTION: %s(#   t   doctestt   errisinstancet   DocTestFailuret   UnexpectedExceptionRS   t   examplet   testt   filenamet   linenoRH   R   RB   R   t   _get_checkert   _get_report_choiceR)   R6   t	   docstringt
   splitlinesR"   t	   enumeratet   sourceR   t   output_differencet   gott   splitR   t   exc_infot   reprt	   tracebackt   format_exceptionR:   RE   RD   t   repr_failure(   R=   t   excinfoRX   t   doctestfailureR\   R]   R^   R_   t   messageR;   t   checkert   report_choiceR<   t   it   xt   indentR?   t   inner_excinfo(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyRm   d   sB    						7	
c         C` s   |  j  d  d |  j f S(   Ns   [doctest] %s(   t   fspathRH   RK   (   R=   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt
   reportinfo   s    N(   RB   RC   RH   R>   RT   RW   Rm   Rx   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyRD   P   s
   			)c          C` s[   d d  l  }  t d |  j d |  j d |  j d |  j d |  j d |  j d t   d	 t	    S(
   Ni    t   DONT_ACCEPT_TRUE_FOR_1t   DONT_ACCEPT_BLANKLINEt   NORMALIZE_WHITESPACER   t   IGNORE_EXCEPTION_DETAILt   COMPARISON_FLAGSt   ALLOW_UNICODEt   ALLOW_BYTES(
   RX   RO   Ry   Rz   R{   R   R|   R}   t   _get_allow_unicode_flagt   _get_allow_bytes_flag(   RX   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   _get_flag_lookup   s    						c         C` sD   |  j  j d  } t   } d } x | D] } | | | O} q( W| S(   NR   i    (   R)   t   getiniR   (   R0   t   optionflags_strt   flag_lookup_tablet   flag_acct   flag(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   get_optionflags   s    	R.   c           B` s   e  Z d Z d    Z RS(   c         c` s   d d  l  } |  j j d  } |  j j |  } t |  j  } |  j j } i d d 6} t |   } | j d d d | d t	    } t
 | |  | j   }	 |	 j | | | | d  }
 |
 j r t |
 j |  | |
  Vn  d  S(   Ni    R   t   __main__RB   t   verboset   optionflagsRq   (   RX   R)   R   Rw   t	   read_textR#   t   basenameR   t   DebugRunnerR`   t   _fix_spoof_python2t   DocTestParsert   get_doctestt   examplesRD   RK   (   R=   RX   t   encodingt   textR^   RK   R8   R   RF   R&   R]   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR      s    	N(   RB   RC   RH   RI   R   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR.      s   c         ` sE   d d l    t   f d   |  j D  } | rA t j d  n  d S(   s\   raises pytest.skip() if all examples in the given DocTest have the SKIP
    option set.
    i    Nc         3` s'   |  ] } | j  j   j t  Vq d  S(   N(   t   optionst   gett   SKIPR"   (   t   .0Rt   (   RX   (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pys	   <genexpr>   s    s!   all tests skipped by +SKIP option(   RX   t   allR   t   pytestt   skip(   R]   t   all_skipped(    (   RX   s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyRU      s    R,   c           B` s   e  Z d    Z RS(   c         c` s  d d  l  } |  j j d k r9 |  j j j |  j  } nS y |  j j   } Wn= t k
 r |  j j d  r t	 j
 d |  j  q   n X| j   } t |   } | j d d d | d t    } x@ | j | | j  D]) } | j r t | j |  | |  Vq q Wd  S(   Ni    s   conftest.pyR   s   unable to import module %rR   R   Rq   (   RX   Rw   R   R)   t   pluginmanagert   _importconftestt   pyimportt   ImportErrort   getvalueR   R   t   DocTestFinderR   R   R`   t   findRB   R   RD   RK   (   R=   RX   t   modulet   finderR   RF   R]   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR      s     	(   RB   RC   R   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR,      s   c      	   C` s_   d   } i  |  _  |  j j } | j d |  d | d d d t  |  _ t |   } | j   | S(   sO   
    Used by DoctestTextfile and DoctestItem to setup fixture information.
    c           S` s   d  S(   N(    (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   func   s    t   nodeR   t   clst   funcargsN(	   R   R3   t   _fixturemanagert   getfixtureinfoRH   R"   t   _fixtureinfoR   t   _fillfixtures(   t   doctest_itemR   t   fmRJ   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyRN      s    		
c          ` sf   t  t d  r t j   Sd d l   d d l  d   j f    f d     Y}  |  t _ t j   S(   sJ  
    Returns a doctest.OutputChecker subclass that takes in account the
    ALLOW_UNICODE option to ignore u'' prefixes in strings and ALLOW_BYTES
    to strip b'' prefixes.
    Useful when the same doctest should run in Python 2 and Python 3.

    An inner class is used to avoid importing "doctest" at the module
    level.
    t   LiteralsOutputCheckeri    Nc           ` sJ   e  Z d  Z  j d  j  Z  j d  j  Z    f d   Z RS(   s   
        Copied from doctest_nose_plugin.py from the nltk project:
            https://github.com/nltk/nltk

        Further extended to also support byte literals.
        s   (\W|^)[uU]([rR]?[\'\"])s   (\W|^)[bB]([rR]?[\'\"])c         ` s     j  j |  | | |  } | r% t S| t   @} | t   @} | rQ | rQ t S f d   } | r | |  j |  } | |  j |  } n  | r | |  j |  } | |  j |  } n    j  j |  | | |  } | Sd  S(   Nc         ` s     j  |  d |  S(   Ns   \1\2(   t   sub(   t   regext   txt(   t   re(    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   remove_prefixes  s    (   t   OutputCheckert   check_outputR5   R   R   R"   t   _unicode_literal_ret   _bytes_literal_re(   R=   t   wantRg   R   t   rest   allow_unicodet   allow_bytesR   (   RX   R   (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR     s$    		(   RB   RC   t   __doc__t   compilet   UNICODER   R   R   (    (   RX   R   (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR     s   (   t   hasattrR`   R   RX   R   R   (   R   (    (   RX   R   s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR`      s    

"$	c          C` s   d d l  }  |  j d  S(   s7   
    Registers and returns the ALLOW_UNICODE flag.
    i    NR~   (   RX   t   register_optionflag(   RX   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR   )  s    c          C` s   d d l  }  |  j d  S(   s5   
    Registers and returns the ALLOW_BYTES flag.
    i    NR   (   RX   R   (   RX   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR   1  s    c         C` sC   d d l  } i | j t 6| j t 6| j t 6| j t 6d t	 6|  S(   s   
    This function returns the actual `doctest` module flag value, we want to do it as late as possible to avoid
    importing `doctest` and all its dependencies when parsing options, as it adds overhead and breaks tests.
    i    N(
   RX   t   REPORT_UDIFFt   DOCTEST_REPORT_CHOICE_UDIFFt   REPORT_CDIFFt   DOCTEST_REPORT_CHOICE_CDIFFt   REPORT_NDIFFt   DOCTEST_REPORT_CHOICE_NDIFFt   REPORT_ONLY_FIRST_FAILUREt(   DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILUREt   DOCTEST_REPORT_CHOICE_NONE(   t   keyRX   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyRa   9  s    



c         ` sY   d d l  m } | s d Sd d l m   d   f    f d     Y} |   |  _ d S(   s  
    Installs a "SpoofOut" into the given DebugRunner so it properly deals with unicode output. This
    should patch only doctests for text files because they don't have a way to declare their
    encoding. Doctests in docstrings from Python modules don't have the same problem given that
    Python already decoded the strings.
    
    This fixes the problem related in issue #2434.
    i    (   t   _PY2N(   t	   _SpoofOutt   UnicodeSpoofc           ` s   e  Z    f d    Z RS(   c         ` s+     j  |   }  r' | j   } n  | S(   N(   R   t   decode(   R=   t   result(   R   R   (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR   Z  s    (   RB   RC   R   (    (   R   R   (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR   X  s   (   t   _pytest.compatR   RX   R   t   _fakeout(   RF   R   R   R   (    (   R   R   s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyR   I  s    	t   scopeR3   c           C` s   t    S(   s2   
    Inject names into the doctest namespace.
    (   RO   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyRM   c  s    ('   R   t
   __future__R    R   R   Rk   R   t   _pytest._code.codeR   R   R   t   _pytest.fixturesR   R   R   R   R   R   R%   R(   R1   R-   R:   t   ItemRD   R   R   t   ModuleR.   RU   R,   RN   R`   R   R   Ra   R   t   fixtureRM   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/doctest.pyt   <module>   s@   					
A			
		8				