
i\c           @` se  d  Z  d d l m Z d d l m Z d d l m 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 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 d d l m Z d Z d Z d Z d Z d Z e e e e e f Z d a d   Z d   Z d   Z  d   Z! d e f d     YZ" d e# f d     YZ$ d   Z% d d d e& d  Z' d e j( f d     YZ) d   Z* d   Z+ d    Z, d! e j- f d"     YZ. d#   Z/ d$   Z0 e
 d%    Z1 d& e j- f d'     YZ2 d(   Z3 d)   Z4 d*   Z5 d+   Z6 d,   Z7 d-   Z8 e j9 d. d/  d0    Z: d S(1   s5    discover and run doctests in modules and test files.i    (   t   absolute_import(   t   division(   t   print_functionN(   t   contextmanager(   t   ExceptionInfo(   t   ReprFileLocation(   t   TerminalRepr(   t   safe_getattr(   t   FixtureRequest(   t   Skippedt   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 | 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_errorss   --doctest-continue-on-failures<   for a given doctest, continue to run after the first failuret   doctest_continue_on_failure(   t   addinit   getgroupt	   addoptiont   Falset   strt   lowert   DOCTEST_REPORT_CHOICES(   t   parsert   group(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   pytest_addoption'   sP    
	c         C` sj   | j  } |  j d k rG | j j rf t | |  |  rf t |  |  Sn t | |  |  rf t |  |  Sd  S(   Ns   .py(   t   configt   extt   optionR   t   _is_setup_pyt   DoctestModulet   _is_doctestt   DoctestTextfile(   t   patht   parentR-   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   pytest_collect_fileY   s    	c         C` s5   | j  d k r t S| j   } d | k p4 d | k S(   Ns   setup.pyt
   setuptoolst	   distutils(   t   basenameR&   t   read(   R-   R4   R5   t   contents(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR0   b   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-   R4   R5   t   globst   glob(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR2   i   s    !t   ReprFailDoctestc           B` s   e  Z d    Z d   Z RS(   c         C` s   | |  _  d  S(   N(   t   reprlocation_lines(   t   selfRE   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   __init__t   s    c         C` sI   xB |  j  D]7 \ } } x | D] } | j |  q W| j |  q
 Wd  S(   N(   RE   t   linet
   toterminal(   RF   t   twt   reprlocationt   linesRH   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRI   x   s    (   t   __name__t
   __module__RG   RI   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRD   s   s   	t   MultipleDoctestFailuresc           B` s   e  Z d    Z RS(   c         C` s    t  t |   j   | |  _ d  S(   N(   t   superRO   RG   t   failures(   RF   RQ   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRG      s    (   RM   RN   RG   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRO      s   c          ` s/   d d  l    d   j f   f d     Y}  |  S(   Ni    t   PytestDoctestRunnerc           ` sG   e  Z d  Z d d d e   f d  Z   f d   Z   f d   Z RS(   s   
        Runner to collect failures.  Note that the out variable in this case is
        a list instead of a stdout-like object
        i    c         ` s/     j  j |  d | d | d | | |  _ d  S(   Nt   checkert   verboset   optionflags(   t   DebugRunnerRG   t   continue_on_failure(   RF   RS   RT   RU   RW   (   t   doctest(    s.   lib/python2.7/site-packages/_pytest/doctest.pyRG      s    	c         ` s8     j  | | |  } |  j r. | j |  n |  d  S(   N(   t   DocTestFailureRW   R   (   RF   t   outt   testt   examplet   gott   failure(   RX   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   report_failure   s    	c         ` sX   t  | d t  r  | d  n    j | | |  } |  j rN | j |  n |  d  S(   Ni   (   t
   isinstanceR	   t   UnexpectedExceptionRW   R   (   RF   RZ   R[   R\   t   exc_infoR^   (   RX   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   report_unexpected_exception   s    	N(   RM   RN   t   __doc__t   NoneR?   RG   R_   Rc   (    (   RX   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRR      s   (   RX   RV   (   RR   (    (   RX   s.   lib/python2.7/site-packages/_pytest/doctest.pyt   _init_runner_class   s    c      	   C` s7   t  d  k r t   a  n  t  d |  d | d | d |  S(   NRS   RT   RU   RW   (   t   RUNNER_CLASSRe   Rf   (   RS   RT   RU   RW   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   _get_runner   s    t   DoctestItemc           B` sD   e  Z d d d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C` sA   t  t |   j | |  | |  _ | |  _ d  |  _ d  |  _ d  S(   N(   RP   Ri   RG   t   runnert   dtestRe   t   objt   fixture_request(   RF   t   nameR5   Rj   Rk   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRG      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(	   Rk   Re   t   _setup_fixturesRm   t   dictt   getfixturevaluet   itemsRB   t   update(   RF   RB   Rn   t   value(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   setup   s    c         C` sO   t  |  j  |  j   g  } |  j j |  j d | | rK t |   n  d  S(   NRZ   (   t   _check_all_skippedRk   t$   _disable_output_capturing_for_darwinRj   t   runRO   (   RF   RQ   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   runtest   s    
c         C` sz   t  j   d k r d S|  j j j d  } | rv | j d t  | j   \ } } t j	 j
 |  t j j
 |  n  d S(   sW   
        Disable output capturing. Otherwise, stdout is lost to doctest (#985)
        t   DarwinNt   capturemanagert   in_(   t   platformt   systemR-   t   pluginmanagert	   getplugint   suspend_global_captureR?   t   read_global_capturet   syst   stdoutt   writet   stderr(   RF   t   capmanRZ   t   err(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRy      s    c         C` s~  d d  l  } d  } | j | j | j f  r< | j g } n | j t  rZ | j j } n  | d  k	 rdg  } x| D]} | j } | j	 } | j
 } | j d  k r d  }	 n | j | j d }	 t |  j }
 t | |	 |
  } t   } t |  j j d   } |	 d  k	 r| j	 j j t  } g  t |  D]' \ } } d | | j d | f ^ q0} | t | j d d  | j d !} nF d g } d } x4 | j j   D]# } | j d | | f  d	 } qWt | | j  r| | j | | j |  j d
  7} n? t | j  } | d t  | j  g 7} | t! j" | j   7} | j | | f  qs Wt# |  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('   RX   Re   t   errisinstanceRY   Ra   Rv   RO   RQ   R\   R[   t   filenamet   linenoR   RM   R   t   _get_checkert   _get_report_choiceR-   R@   t	   docstringt
   splitlinesR&   t	   enumeratet   maxt   sourceR   R`   t   output_differenceR]   t   splitR   Rb   t   reprt	   tracebackt   format_exceptionRD   RP   Ri   t   repr_failure(   RF   t   excinfoRX   RQ   RE   R^   R\   R[   R   R   t   messageRK   RS   t   report_choiceRL   t   it   xt   indentRH   t   inner_excinfo(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR      sP    					7'	
	
c         C` s   |  j  |  j j d |  j f S(   Ns   [doctest] %s(   t   fspathRk   R   Rn   (   RF   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt
   reportinfo  s    N(	   RM   RN   Re   RG   Rw   R{   Ry   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRi      s   	
			7c          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   Rr   R   R   R   R   R   R   t   _get_allow_unicode_flagt   _get_allow_bytes_flag(   RX   (    (    s.   lib/python2.7/site-packages/_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   (   R5   t   optionflags_strt   flag_lookup_tablet   flag_acct   flag(    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   get_optionflags'  s    	c         C` s4   |  j  d  } | r0 |  j  d  r0 t } q0 n  | S(   NR"   t   usepdb(   t   getvalueR&   (   R-   RW   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   _get_continue_on_failure0  s
    R3   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 |   } t d d d | d t	   d t
 |  j   } t | |  | j   }	 |	 j | | | | d  }
 |
 j r t |
 j |  | |
  Vn  d  S(	   Ni    R   t   __main__RM   RT   RU   RS   RW   (   RX   R-   R   R   t	   read_textR'   R9   R   Rh   R   R   t   _fix_spoof_python2t   DocTestParsert   get_doctestt   examplesRi   Rn   (   RF   RX   t   encodingt   textR   Rn   RB   RU   Rj   R*   R[   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR   =  s"    		N(   RM   RN   Re   Rl   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR3   :  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   .0R   (   RX   (    s.   lib/python2.7/site-packages/_pytest/doctest.pys	   <genexpr>^  s    s!   all tests skipped by +SKIP option(   RX   t   allR   t   pytestt   skip(   R[   t   all_skipped(    (   RX   s.   lib/python2.7/site-packages/_pytest/doctest.pyRx   X  s    c         C` s   t  |  d d  d k	 S(   sr   
    returns if a object is possibly a mock object by checking the existence of a highly improbable attribute
    t1   pytest_mock_example_attribute_that_shouldnt_existN(   R   Re   (   Rl   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt
   _is_mockedc  s    c          #` s[   t  t d d      d k r& d Vn1 d   f d  }  |  t _ z	 d VWd   t _ Xd S(   s   
    contextmanager which replaces ``inspect.unwrap`` with a version
    that's aware of mock objects and doesn't recurse on them
    t   unwrapNc         ` s9     d  k r  |  d t S |  d   f d   Sd  S(   Nt   stopc         ` s   t  |   p   |   S(   N(   R   (   Rl   (   R   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   <lambda>|  t    (   Re   R   (   Rl   R   (   t   real_unwrap(   R   s.   lib/python2.7/site-packages/_pytest/doctest.pyt   _mock_aware_unwrapx  s    (   t   getattrt   inspectRe   R   (   R   (    (   R   s.   lib/python2.7/site-packages/_pytest/doctest.pyt   _patch_unwrap_mock_awarem  s    		R1   c           B` s   e  Z d    Z RS(   c      
   #` s4  d d  l    d   j f   f d     Y} |  j j d k rX |  j j j |  j  } nS y |  j j   } Wn= t k
 r |  j j	 d  r t
 j d |  j  q   n X|   } t |   } t d d d | d	 t   d
 t |  j   } x@ | j | | j  D]) } | j rt | j |  | |  VqqWd  S(   Ni    t   MockAwareDocTestFinderc           ` s   e  Z d  Z   f d   Z RS(   s   
            a hackish doctest finder that overrides stdlib internals to fix a stdlib bug

            https://github.com/pytest-dev/pytest/issues/3456
            https://bugs.python.org/issue25532
            c         ` sI   t  |  r d  St   *   j j |  | | | | | | |  Wd  QXd  S(   N(   R   R   t   DocTestFindert   _find(   RF   t   testsRl   Rn   t   modulet   source_linesRB   t   seen(   RX   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR     s
    
	(   RM   RN   Rd   R   (    (   RX   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR     s   s   conftest.pyR!   s   unable to import module %rRT   RU   RS   RW   (   RX   R   R   R9   R-   R   t   _importconftestt   pyimportt   ImportErrorR   R   R   R   Rh   R   R   t   findRM   R   Ri   Rn   (   RF   R   R   t   finderRU   Rj   R[   (    (   RX   s.   lib/python2.7/site-packages/_pytest/doctest.pyR     s(    			(   RM   RN   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR1     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.   lib/python2.7/site-packages/_pytest/doctest.pyt   func  s    t   nodeR   t   clst   funcargsN(	   R   R=   t   _fixturemanagert   getfixtureinfoRe   R&   t   _fixtureinfoR   t   _fillfixtures(   t   doctest_itemR   t   fmRm   (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRq     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.   lib/python2.7/site-packages/_pytest/doctest.pyt   remove_prefixes  s    (   t   OutputCheckert   check_outputR?   R   R   R&   t   _unicode_literal_ret   _bytes_literal_re(   RF   t   wantR]   RU   t   rest   allow_unicodet   allow_bytesR   (   RX   R   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR     s     (   RM   RN   Rd   t   compilet   UNICODER   R   R   (    (   RX   R   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR     s   (   t   hasattrR   R   RX   R   R   (   R   (    (   RX   R   s.   lib/python2.7/site-packages/_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.   lib/python2.7/site-packages/_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.   lib/python2.7/site-packages/_pytest/doctest.pyR     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.   lib/python2.7/site-packages/_pytest/doctest.pyR     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  |   }  r6 t | t  r6 | j   } n  | S(   N(   R   R`   t   bytest   decode(   RF   t   result(   R  R   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR   /  s    (   RM   RN   R   (    (   R  R   (    s.   lib/python2.7/site-packages/_pytest/doctest.pyR  .  s   (   t   _pytest.compatR  RX   R  t   _fakeout(   Rj   R   R  R  (    (   R  R   s.   lib/python2.7/site-packages/_pytest/doctest.pyR     s    	t   scopeR=   c           C` s   t    S(   sg   
    Fixture that returns a :py:class:`dict` that will be injected into the namespace of doctests.
    (   Rr   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyRp   8  s    (;   Rd   t
   __future__R    R   R   R   R   R   R   t
   contextlibR   R   t   _pytest._code.codeR   R   R   R
  R   t   _pytest.fixturesR   t   _pytest.outcomesR	   R  R   R   R   R  R)   Re   Rg   R,   R6   R0   R2   RD   t	   ExceptionRO   Rf   R?   Rh   t   ItemRi   R   R   R   t   ModuleR3   Rx   R   R   R1   Rq   R   R   R   R   R   t   fixtureRp   (    (    (    s.   lib/python2.7/site-packages/_pytest/doctest.pyt   <module>   sd   		2				
	$b				
		
.		7						