σ
Ύ^Yc        
   @` sΛ  d  Z  d d l m Z m Z 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
 Z
 d d l Z y d d l Z Wn e k
 r d Z n Xe j d0 k Z e Z e d  Z e   Z e j d  d1 k Z e j d  d2 k Z e rύ d n d	 Z e e d
  rd   Z n	 d   Z e j Z e j Z e e d d    Z e e j d   Z  d   Z! d   Z" d   Z# d   Z$ d d  Z% e j d  d3 k r²d   Z n  e rλd d l& Z& e' Z( e) e* f Z+ e* f Z, d   Z- n1 e) e* e. f Z+ e. f Z, d d l/ m( Z( d   Z- d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 e r[d   Z5 n	 d   Z5 d4 Z6 d*   Z7 e rd d+ l8 m9 Z: n% d d l; Z; d, e; j< f d-     YZ: d. e f d/     YZ= d S(5   s#   
python version compatibility code
i    (   t   absolute_importt   divisiont   print_functionNi   i   i   i   t   ModuleNotFoundErrort   ImportErrort	   signaturec         C` s   t  t j |    S(   N(   t   strt   inspectR   (   t   func(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   _format_args$   s    c         C` s   t  j t  j |     S(   N(   R   t   formatargspect
   getargspec(   R   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyR	   '   s    t	   exc_clearc           C` s   d  S(   N(   t   None(    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   <lambda>-   s    t    c         C` s    t  j |   } | o t |   S(   N(   R   t   isgeneratorfunctiont   iscoroutinefunction(   R   t   genfunc(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   is_generator2   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.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyR   7   s    c         C` so   d d  l  } t j j | j |    } t j j |   j } | j |  r] | j |  } n  d | | d f S(   Ni    s   %s:%di   (	   R   t   pyt   patht   localt   getfilet   builtint   _getcodet   co_firstlinenot   relto(   t   functiont   curdirR   t   fnt   lineno(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   getlocationA   s    c         C` s   t  |  d d  } | s d St j j d t j j d d   } | d k	 r t g  | D]( } | j rV | j | j k rV | ^ qV  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   lent   attribute_namet   newt   DEFAULT(   R    R%   R&   t   p(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   num_mock_patch_argsJ   s    $)c         C` sf  |  } x t  | d  r$ | j } q	 W| d  k rO t j |   rF d pI d } n  | |  k rt | t |   7} | }  n  t |  t j  rρ t j	 t
 j j |  j   d } |  } | t | j  } | j rx! | j D] } | j |  qΤ Wqn t j	 t
 j j |    d } t |  d t |  d d    p1d } t |  } | rXt | | | ! St | |  S(   Nt   __wrapped__i   i    t   func_defaultst   __defaults__(    (   R   R0   R   R   t   ismethodR/   t
   isinstancet	   functoolst   partialt   getargst   _pytestt   _codet
   getrawcodeR   R*   t   argst   keywordst   removeR   t   tuple(   R    t
   startindext   realfunctiont   argnamesR6   t   kwt   defaultst   numdefaults(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   getfuncargnamesV   s,    	"		c         C` s   t  |  t t j f  S(   s   Return true if the object is a class. Overrides inspect.isclass for
        python 2.6 because it will return True for objects which always return
        something on __getattr__ calls (see #1035).
        Backport of https://hg.python.org/cpython/rev/35bf8f7a8edc
        (   R4   t   typet   typest	   ClassType(   t   object(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   isclasst   s    c         C` sX   t  |  t  r> |  r7 t j |   \ } } | j d  Sd Sn |  j d  j d  Sd 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   asciiR   t   unicode_escapeN(   R4   t   bytest   codecst   escape_encodet   decodet   encode(   t   valt   encoded_bytest   _(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   _escape_strings   s    (   t   imapc         C` sR   t  |  t  rA y |  j d  SWqN t k
 r= |  j d  SXn |  j d  Sd 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.

        RK   s   string-escapes   unicode-escapeN(   R4   RM   RQ   t   UnicodeDecodeError(   RR   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyRU   ₯   s    	c         C` s   |  } xr t  d  D]. } t |  d d  } | d k r; Pn  | }  q Wt d j d t j j |  d t j j |      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   R0   s<   could not find real function of {start}
stopped at {current}t   startt   currentN(   t   rangeR   R   t
   ValueErrort   formatR   t   iot   safereprR4   R5   R6   R   (   t   objt	   start_objt   it   new_obj(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   get_real_func·   s    
	c         C` s\   t  |   }  t |  d  r' |  j }  n  t j j |   } t | d t  sX t |    | S(   Nt   place_asi   (	   Rc   R   Rd   R8   R9   t   getfslinenoR4   t   intt   AssertionError(   R_   t   fslineno(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyRe   Μ   s    c         C` sC   y |  j  SWn1 t k
 r> y |  j SWq? t k
 r: |  SXn Xd  S(   N(   t   __func__t   AttributeErrort   im_func(   R   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt	   getimfuncΦ   s    c         C` s-   y t  |  | |  SWn t k
 r( | SXd S(   s    Like getattr but return default upon any Exception.

    Attribute access can potentially fail for 'evil' Python objects.
    See issue #214.
    N(   R   t	   Exception(   RI   t   namet   default(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   safe_getattrΰ   s    c           C` s   t  j d k S(   sY  Return if the test suite should fail if a @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   (   R'   t   version_info(    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt)   _is_unittest_unexpected_success_a_failureμ   s    c         C` s
   t  |   S(   s   returns v as string(   R   (   t   v(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   safe_strχ   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   UnicodeErrorR4   t   unicodeRQ   (   Rs   t   errors(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyRt   ϋ   s    t	   Collectort   Modulet	   Generatort   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(   RG   R   t   pytestt   collectt   __all__t   COLLECT_FAKEMODULE_ATTRIBUTESt   setattrR   (   R   R   t   attr(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   _setup_collect_fakemodule  s    (   t   TextIOt	   CaptureIOc           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(   Nt   encodings   UTF-8t   newlineR   t   write_through(   t   superR   t   __init__R]   t   BytesIOt   True(   t   self(    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyR   #  s    c         C` s   |  j  j   j d  S(   Ns   UTF-8(   t   buffert   getvalueRP   (   R   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyR   )  s    (   t   __name__t
   __module__R   R   (    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_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(   R   (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   funcargnames0  s    (   R   R   t   __doc__t   propertyR   (    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyR   ,  s   (   i   i    (   i   i   (   i   i   (   i   i   (
   Ry   Rz   s	   GeneratorR|   R}   s   SessionR   R   R   R   (>   R   t
   __future__R    R   R   R'   R   RG   t   reR5   R   R8   t   enumR   R   Rq   t   _PY3t   _PY2RF   t   NoneTypeRI   t   NOTSETt   PY35t   PY36t   MODULE_NOT_FOUND_ERRORR   R	   t
   isfunctionRJ   R   R   t   compilet
   REGEX_TYPER   R   R$   R/   RE   RN   t   mapRV   RM   R   t   STRING_TYPESt   UNICODE_TYPESRU   Rw   t	   itertoolsRc   Re   Rl   Rp   Rr   Rt   R   R   t   py.ioR   R   R]   t   TextIOWrapperR   (    (    (    s.   /tmp/pip-build-hU8Cw8/pytest/_pytest/compat.pyt   <module>   s   
						
									
	
		
	         		
