
i\c        	   @` s  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	 Z	 d d l
 m 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 y d d l Z Wn e k
 rd Z n Xe	 j dL k Z e Z e rEd d l m Z m Z n d d l m Z m Z e   Z e	 j d  dM k Z  e	 j d  dN k Z! e! rd n d Z" e rd d l# m$ Z% d d l# m& Z& m' Z' m( Z( m) Z) n2 d d l* m$ Z% d d l* m& Z& m' Z' m( Z( m) Z) e	 j dO k r+d d l+ m, Z, n	 d   Z, d   Z- e j. Z. e j/ Z/ e0 e	 d d    Z1 e2 e j3 d   Z4 d   Z5 d   Z6 d   Z7 d   Z8 e9 d d  Z: e d     Z; d!   Z< d"   e= d#  D Z> e> j? i d$ e@ d%  6d& e@ d'  6d( e@ d)  6 d*   ZA e rYeB eC f ZD e j ZE e  rDd+   ZF n	 d,   ZF d-   ZG n e jH ZD e j ZE d.   ZG d/ e f d0     YZI d1   ZJ d2   ZK d3   ZL d4   ZM d5   ZN d6   ZO d7   ZP e rd8   ZQ n	 d9   ZQ dP ZR dC   ZS e r"d dD lT mU ZU dE eU f dF     YZV n% d d lW ZW dE eW jX f dG     YZV dH e f dI     YZY e jZ rrdJ   Z[ n d dK l m[ Z[ d S(Q   s#   
python version compatibility code
i    (   t   absolute_import(   t   division(   t   print_functionN(   t   contextmanager(   t	   text_type(   t   saferepr(   t   fail(   t   TEST_OUTCOMEi   (   t	   signaturet	   Parameteri   i   i   t   ModuleNotFoundErrort   ImportError(   t   MutableMapping(   t   Iterablet   Mappingt   Sequencet   Sizedi   (   t   spec_from_file_locationc          O` s   d  S(   N(   t   None(   t   _t   __(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR   <   s    c         C` s   t  t |    S(   N(   t   strR   (   t   func(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   _format_args@   s    t	   exc_clearc           C` s   d  S(   N(   R   (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   <lambda>G   t    R   c         C` s    t  j |   } | o t |   S(   N(   t   inspectt   isgeneratorfunctiont   iscoroutinefunction(   R   t   genfunc(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   is_generatorL   s    c         C` s.   t  |  d t  p- t t d  o- t j |   S(   s   Return True if func is a decorated coroutine function.

    Note: copied and modified from Python 3.5's builtin couroutines.py to avoid import asyncio directly,
    which in turns also initializes the "logging" module as side-effect (see issue #8).
    t   _is_coroutineR   (   t   getattrt   Falset   hasattrR   R   (   R   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR   Q   s    c         C` sf   t  |   }  t j j t j |    } |  j j } | j |  rT | j |  } n  d | | d f S(   Ns   %s:%di   (	   t   get_real_funct   pyt   patht   localR   t   getfilet   __code__t   co_firstlinenot   relto(   t   functiont   curdirt   fnt   lineno(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   getlocation\   s    c         C` s   t  |  d d  } | s d St j j d  t j j d  g } t |  r g  | D] } | d k	 rS | j ^ qS } t g  | D]% } | j r~ | j	 | k r~ | ^ q~  St |  S(   s?    return number of arguments used up by mock arguments (if any) t	   patchingsi    t   mocks   unittest.mockN(
   R!   R   t   syst   modulest   gett   anyt   DEFAULTt   lent   attribute_namet   new(   R,   R1   t   mock_modulest   mt	   sentinelst   p(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   num_mock_patch_argse   s    $(3c         C` s   y t  |   j } Wn5 t t f k
 rJ } t d j |  |  d t n Xt d   | j   D  } | s | r t	 | j
 j |  j d  t  r | d } n  t |  d  r | t |   } n  | S(   s	  Returns the names of a function's mandatory arguments.

    This should return the names of all function arguments that:
        * Aren't bound to an instance or type as in instance or class methods.
        * Don't have default values.
        * Aren't bound with functools.partial.
        * Aren't replaced with mocks.

    The is_method and cls arguments indicate that the function should
    be treated as a bound method even though it's not unless, only in
    the case of cls, the function is a static method.

    @RonnyPfannschmidt: This function should be refactored when we
    revisit fixtures. The fixture mechanism should ask the node for
    the fixture names, and not try to obtain directly from the
    function object well after collection has occurred.

    s)   Could not determine arguments of {!r}: {}t   pytracec         s` sN   |  ]D } | j  t j k s- | j  t j k r | j t j k r | j Vq d  S(   N(   t   kindR	   t   POSITIONAL_OR_KEYWORDt   KEYWORD_ONLYt   defaultt   emptyt   name(   t   .0R>   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pys	   <genexpr>   s   i   t   __wrapped__N(   R   t
   parameterst
   ValueErrort	   TypeErrorR   t   formatR"   t   tuplet   valuest
   isinstancet   __dict__R5   t   __name__R   t   staticmethodR#   R?   (   R,   t	   is_methodt   clsRI   t   et	   arg_names(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   getfuncargnamess   s    
(c           c` s	   d Vd S(   s   Context manager that does nothing, useful in situations where you might need an actual context manager or not
    depending on some condition. Using this allow to keep the same codeN(    (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   dummy_context_manager   s    c         C` s#   t  d   t |   j j   D  S(   Nc         s` sE   |  ]; } | j  t j t j f k r | j t j k	 r | j Vq d  S(   N(   RA   R	   RB   RC   RD   RE   RF   (   RG   R>   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pys	   <genexpr>   s   (   RM   R   RI   RN   (   R,   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   get_default_arg_names   s    c         C` s7   i  |  ]- } | t  d  d  k r d j |  |  q S(   i    i   u   \x{:02x}(   t   rangeRL   (   RG   t   i(    (    s-   lib/python2.7/site-packages/_pytest/compat.pys
   <dictcomp>   s   	 i   u   \ts   	u   \rs   u   \ns   
c         C` s   |  j  t  S(   N(   t	   translatet$   _non_printable_ascii_translate_table(   t   s(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   _translate_non_printable   s    c         C` s   |  j  d d  S(   Nt   asciit   backslashreplace(   t   decode(   t   val(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   _bytes_to_ascii   s    c         C` s0   |  r( t  j |   \ } } | j d  Sd Sd  S(   NR`   R   (   t   codecst   escape_encodeRb   (   Rc   t   encoded_bytesR   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyRd      s    c         C` s@   t  |  t  r t |   } n |  j d  j d  } t |  S(   s9  If val is pure ascii, returns it as a str().  Otherwise, escapes
        bytes objects into a sequence of escaped bytes:

        b'ô' -> u'\xc3\xb4\xc5\xd6'

        and escapes unicode objects into a sequence of escaped unicode
        ids, e.g.:

        '4\nV\U00043efa\x0eMXWB\x1e\u3028\u15fd\xcd\U0007d944'

        note:
           the obvious "v.decode('unicode-escape')" will return
           valid utf-8 unicode if it finds them in bytes, but we
           want to return escaped bytes for any byte, even if they match
           a utf-8 string.

        t   unicode_escapeR`   (   RO   t   bytesRd   t   encodeRb   R_   (   Rc   t   ret(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   ascii_escaped   s    c         C` ss   t  |  t  rQ y |  j d  } Wqi t k
 rM |  j d  j d  } qi Xn |  j d  j d  } t |  S(   s  In py2 bytes and str are the same type, so return if it's a bytes
        object, return it unchanged if it is a full ascii string,
        otherwise escape it into its binary form.

        If it's a unicode string, change the unicode characters into
        unicode escapes.

        R`   s   string-escapes   unicode-escape(   RO   Ri   Rb   t   UnicodeDecodeErrorRj   R_   (   Rc   Rk   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyRl      s    	t   _PytestWrapperc           B` s   e  Z d  Z d   Z RS(   s%  Dummy wrapper around a function object for internal use only.

    Used to correctly unwrap the underlying function object
    when we are creating fixtures, because we wrap the function object ourselves with a decorator
    to issue warnings when the fixture function is called directly.
    c         C` s   | |  _  d  S(   N(   t   obj(   t   selfRo   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   __init__  s    (   RQ   t
   __module__t   __doc__Rq   (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyRn   
  s   c         C` s   |  } x t  d  D]\ } t |  d d  } t | t  rG | j }  Pn  t |  d d  } | d k ri Pn  | }  q Wt d j d t |  d t |      t |  t	 j
  r |  j }  n  |  S(   sq    gets the real function object of the (possibly) wrapped object by
    functools.wraps or functools.partial.
    id   t   __pytest_wrapped__RH   s<   could not find real function of {start}
stopped at {current}t   startt   currentN(   RZ   R!   R   RO   Rn   Ro   RJ   RL   R   t	   functoolst   partialR   (   Ro   t	   start_objR[   t   new_obj(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR$     s     	
	c         C` sn   y t  |  d  } t |   }  Wn t k
 r3 |  SX| rj t  |  d  rj t |  j  rj |  j |  }  n  |  S(   s   
    Attempts to obtain the real function object that might be wrapping ``obj``, while at the same time
    returning a bound method to ``holder`` if the original object was a bound method.
    t   __func__t   __get__(   R#   R$   t	   Exceptiont   callableR|   (   Ro   t   holderRS   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   get_real_method2  s    $c         C` s\   t  |   }  t |  d  r' |  j }  n  t j j |   } t | d t  sX t |    | S(   Nt   place_asi   (	   R$   R#   R   t   _pytestt   _codet   getfslinenoRO   t   intt   AssertionError(   Ro   t   fslineno(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR   A  s    c         C` s$   y |  j  SWn t k
 r |  SXd  S(   N(   R{   t   AttributeError(   R   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt	   getimfuncK  s    c         C` s-   y t  |  | |  SWn t k
 r( | SXd S(   sN   Like getattr but return default upon any Exception or any OutcomeException.

    Attribute access can potentially fail for 'evil' Python objects.
    See issue #214.
    It catches OutcomeException because of #2490 (issue #580), new outcomes are derived from BaseException
    instead of Exception (for more details check #2707)
    N(   R!   R   (   t   objectRF   RD   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   safe_getattrR  s    c         C` s'   y t  |   SWn t k
 r" t SXd S(   s0   Ignore any exception via isinstance on Python 3.N(   t   isclassR}   R"   (   Ro   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   safe_isclass`  s    c           C` s   t  j d k S(   sZ  Return if the test suite should fail if an @expectedFailure unittest test PASSES.

    From https://docs.python.org/3/library/unittest.html?highlight=unittest#unittest.TestResult.wasSuccessful:
        Changed in version 3.4: Returns False if there were any
        unexpectedSuccesses from tests marked with the expectedFailure() decorator.
    i   i   (   i   i   (   R3   t   version_info(    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt)   _is_unittest_unexpected_success_a_failureh  s    c         C` s
   t  |   S(   s   returns v as string(   R   (   t   v(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   safe_strt  s    c         C` sW   y t  |   SWnB t k
 rR t |  t  s< t |   }  n  d } |  j d |  SXd S(   s5   returns v as string, converting to ascii if necessaryt   replaces   utf-8N(   R   t   UnicodeErrorRO   R   Rj   (   R   t   errors(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR   {  s    t	   Collectort   Modulet   Functiont   Instancet   Sessiont   Itemt   Classt   Filet   _fillfuncargsc          C` sh   d d l  m }  d d  l } |  d  | _ g  | j _ x* t D]" } t | j | t | |   q> Wd  S(   Ni    (   t
   ModuleTypes   pytest.collect(   t   typesR   t   pytestt   collectt   __all__t   COLLECT_FAKEMODULE_ATTRIBUTESt   setattrR!   (   R   R   t   attr(    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   _setup_collect_fakemodule  s    (   t   TextIOt	   CaptureIOc           B` s   e  Z e d     Z RS(   c         C` s   t  |  d d  S(   Nt	   _encodings   UTF-8(   R!   (   Rp   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   encoding  s    (   RQ   Rr   t   propertyR   (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR     s   c           B` s   e  Z d    Z d   Z RS(   c         C` s2   t  t |   j t j   d d d d d t d  S(   NR   s   UTF-8t   newlineR   t   write_through(   t   superR   Rq   t   iot   BytesIOt   True(   Rp   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyRq     s    c         C` s   |  j  j   j d  S(   Ns   UTF-8(   t   buffert   getvalueRb   (   Rp   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR     s    (   RQ   Rr   Rq   R   (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR     s   	t   FuncargnamesCompatAttrc           B` s   e  Z d  Z e d    Z RS(   s    helper class so that Metafunc, Function and FixtureRequest
    don't need to each define the "funcargnames" compatibility attribute.
    c         C` s   |  j  S(   s?    alias attribute for ``fixturenames`` for pre-2.3 compatibility(   t   fixturenames(   Rp   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   funcargnames  s    (   RQ   Rr   Rs   R   R   (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyR     s   c          O` s   d   } | S(   Nc         S` s   |  S(   N(    (   R.   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   dec  s    (    (   R   R   R   (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt	   lru_cache  s    	(   R   (   i   i    (   i   i   (   i   i   (   i   i   (	   R   R   R   R   R   R   R   R   R   (\   Rs   t
   __future__R    R   R   Re   Rw   R   t   reR3   t
   contextlibR   R%   t   sixR   R   t   _pytest._io.safereprR   t   _pytest.outcomesR   R   t   enumR   R   R   t   _PY3t   _PY2R   R	   t   funcsigsR   t   NOTSETt   PY35t   PY36t   MODULE_NOT_FOUND_ERRORt   collections.abcR   t   MappingMixinR   R   R   R   t   collectionst   importlib.utilR   R   t
   isfunctionR   R!   R   t   typet   compilet
   REGEX_TYPER   R   R0   R?   R"   RW   RX   RY   RZ   R]   t   updatet   ordR_   Ri   R   t   STRING_TYPESt   UNICODE_TYPESRd   Rl   t   string_typesRn   R$   R   R   R   R   R   R   R   R   R   t   py.ioR   R   R   t   TextIOWrapperR   t   PY2R   (    (    (    s-   lib/python2.7/site-packages/_pytest/compat.pyt   <module>   s   
	%"									5	.										
				
	        	

	