σ
η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 m Z d d l m	 Z	 d d l m
 Z
 d	   Z d
   Z d e f d     YZ d e f d     YZ d   Z d   Z d   Z d   Z d   Z e
 j Z d S(   sD   
support for presenting detailed information in failing assertions.
i    (   t   absolute_import(   t   division(   t   print_functionN(   t   rewrite(   t   truncate(   t   utilc         C` sD   |  j  d  } | j d d d d d d d d
 d d d d d d  S(   Nt   debugconfigs   --assertt   actiont   storet   destt
   assertmodet   choicesR   t   plaint   defaultt   metavart   MODEt   helps4  Control assertion debugging tools.  'plain'
                            performs no assertion debugging.  'rewrite'
                            (the default) rewrites assert statements in
                            test modules on import to provide assert
                            expression information.(   R   R   (   t   getgroupt	   addoption(   t   parsert   group(    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   pytest_addoption   s    c          G` s   xA |  D]9 } t  | t  s d } t | j t |      q q Wx6 t j D]" } t  | t j  rN | } PqN qN Wt	   } | j
 |    d S(   s€  Register one or more module names to be rewritten on import.

    This function will make sure that this module or all modules inside
    the package will get their assert statements rewritten.
    Thus you should make sure to call this before the module is
    actually imported, usually in your __init__.py if you are a plugin
    using a package.

    :raise TypeError: if the given module names are not strings.
    s/   expected module names as *args, got {0} insteadN(   t
   isinstancet   strt	   TypeErrort   formatt   reprt   syst	   meta_pathR   t   AssertionRewritingHookt   DummyRewriteHookt   mark_rewrite(   t   namest   namet   msgt   hookt
   importhook(    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   register_assert_rewrite#   s    "	R   c           B` s   e  Z d  Z d   Z RS(   s3   A no-op import hook for when rewriting is disabled.c         G` s   d  S(   N(    (   t   selfR    (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyR   >   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyR   ;   s   t   AssertionStatec           B` s   e  Z d  Z d   Z RS(   s   State for the assertion plugin.c         C` s.   | |  _  | j j j d  |  _ d  |  _ d  S(   Nt	   assertion(   t   modet   tracet   roott   gett   NoneR#   (   R&   t   configR,   (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   __init__E   s    	(   R'   R(   R)   R2   (    (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyR*   B   s   c         ` s   t  j j d  r! t d   n  t   d    _ t j      j _ } t  j	 j
 d |    j j d    f d   }   j |  | S(   s?   Try to install the rewrite hook, raise SystemError if it fails.t   javas   rewrite not supportedR   i    s   installed rewrite import hookc          ` s>     j  j }  |  d  k	 r: |  t j k r: t j j |   n  d  S(   N(   t   _assertstateR#   R0   R   R   t   remove(   R#   (   R1   (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   undoV   s    (   R   t   platformt
   startswitht   SystemErrorR*   R4   R   R   R#   R   t   insertR-   t   add_cleanup(   R1   R#   R6   (    (   R1   s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   install_importhookK   s    c         C` sD   t  |  j d d   } | r@ | j d  k	 r@ | j j |   q@ n  d  S(   NR4   (   t   getattrR1   R0   R#   t   set_session(   t   sessiont   assertstate(    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   pytest_collection_   s    c         ` s     f d   } | t  _ d S(   sώ   Setup the pytest_assertrepr_compare hook

    The newinterpret and rewrite modules will use util._reprcompare if
    it exists to use custom reporting via the
    pytest_assertrepr_compare hook.  This sets up this custom
    comparison for the test.
    c      	   ` sΕ     j  j d   j d |  d | d |  } x | D] } | r1 t j |    } g  | D] } | j d d  ^ qV } t j d  j |  }   j j	 d  d	 k rΉ | j d
 d  } n  | Sq1 Wd S(   sI  Call the pytest_assertrepr_compare hook and prepare the result

        This uses the first result from the hook and then ensures the
        following:
        * Overly verbose explanations are truncated unless configured otherwise
          (eg. if running in verbose mode).
        * Embedded newlines are escaped to help util.format_explanation()
          later.
        * If the rewrite mode is used embedded %-characters are replaced
          to protect later % formatting.

        The result can be formatted by util.format_explanation() for
        pretty printing.
        R1   t   opt   leftt   rights   
s   \ns   
~R
   R   t   %s   %%N(
   t   ihookt   pytest_assertrepr_compareR1   R   t   truncate_if_requiredt   replacet   sixt	   text_typet   joint   getvalue(   RB   RC   RD   t   hook_resultt   new_explt   linet   res(   t   item(    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   callbinreprr   s    %N(   R   t   _reprcompare(   RR   RS   (    (   RR   s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   pytest_runtest_setupi   s    	c         C` s   d  t _ d  S(   N(   R0   R   RT   (   RR   (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   pytest_runtest_teardown   s    c         C` sD   t  |  j d d   } | r@ | j d  k	 r@ | j j d   q@ n  d  S(   NR4   (   R=   R1   R0   R#   R>   (   R?   R@   (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   pytest_sessionfinish   s    (   R)   t
   __future__R    R   R   R   RJ   t   _pytest.assertionR   R   R   R   R%   t   objectR   R*   R<   RA   RU   RV   RW   t   assertrepr_compareRG   (    (    (    s9   lib/python2.7/site-packages/_pytest/assertion/__init__.pyt   <module>   s$   					
	'		