
'![c           @  s  d  Z  d d l m 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 m	 Z	 m
 Z
 d d l m Z m Z 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 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 e j" d  Z# d d d d g Z$ e e e%   Z& e j" d d k Z' d   Z( d e f d     YZ) d e f d     YZ* d e j+ d d d d d d g  f d     YZ, d  e- f d!     YZ. d"   Z/ d# e- f d$     YZ0 e)   Z1 e!   Z2 e2 j3 e1  d e2 j4 _5 e j6 e2  d%   Z7 e j8 d d&   Z: e j8 d'    Z; d S((   s*   functional/non regression tests for pylinti(   t   print_functionN(   t   glob(   t   linesept   getcwdt   sep(   t   abspatht   basenamet   dirnamet   joint   splitext(   t   StringIO(   t   checkers(   t   PyLintASTWalker(   t   BaseReporter(   t	   IReporter(   t   PyLinters   %d%d%di   t    t   =t   -t   .i    c         C  sX  g  } xKt  t |  | d |   D],} t |  } t |  d } | j d d  d } | j   r} t | k  r} q$ q} n  | j d  r | d j   r t | d k r q$ q n  t  t | | d   }	 |	 r*xf t |	 d t	 D]< }
 |
 j d d  d d	  } | j   r t | k r Pq q Wn t | | d
  }
 | j
 | |
 f  q$ W| S(   s  get python input examples and output messages

    We use following conventions for input files and messages:
    for different inputs:
        test for python  >= x.y    ->  input   =  <name>_pyxy.py
        test for python  <  x.y    ->  input   =  <name>_py_xy.py
    for one input and different messages:
        message for python >=  x.y ->  message =  <name>_pyxy.txt
        lower versions             ->  message with highest num
    t   *i    t   _pyi   it   _s   *.txtt   reverseis   .txt(   R   R   R   R	   t   rsplitt   isdigitt   SYS_VERS_STRt
   startswitht   sortedt   Truet   append(   t	   input_dirt   msg_dirt   prefixt   suffixt   resultt   fnamet   infilet   fbaset   pyrestrt   messagest   outfilet   py_rest(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   _get_tests_info3   s(    $		t   TestReporterc           B  sP   e  Z d  Z e Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d Z RS(   s$   reporter storing plain text messagesc         C  s'   i  |  _  |  j   t   t |  _ d  S(   N(   t   message_idst   resetR   R   t   path_strip_prefix(   t   self(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   __init__^   s    	
c         C  s   t    |  _ g  |  _ d  S(   N(   R
   t   outR(   (   R0   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyR.   d   s    c         C  s   | j  } | j } | j } | j } d |  j | <| rD d | } n  | d } t ru t d k ru | j d d  } n  |  j j	 d | | | | f  d S(   s<   manage message of different type and in the context of path i   s   :%si    s   
s   
s   %s:%3s%s: %sN(
   t   objt   linet   msg_idt   msgR-   t   PY3KR   t   replaceR(   R   (   R0   R6   R3   R4   R5   t   sigle(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   handle_messageh   s    				
c         C  sQ   |  j  j   x$ |  j  D] } t | d |  j q W|  j j   } |  j   | S(   Nt   file(   R(   t   sortt   printR2   t   getvalueR.   (   R0   R6   R#   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   finalizex   s    
c         C  s   d  S(   N(    (   R0   t   modulet   filepath(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   on_set_current_module   s    c         C  s   d S(   s   ignore layoutsN(    (   R0   t   layout(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   display_reports   s    N(   t   __name__t
   __module__t   __doc__R   t   __implements__R1   R.   R:   R?   RB   RD   t   Nonet   _display(    (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyR,   Y   s   							t   MinimalTestReporterc           B  s    e  Z d    Z d   Z d Z RS(   c         C  s   |  j  j |  d  S(   N(   R(   R   (   R0   R6   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyR:      s    c         C  s   g  |  _  d  S(   N(   R(   (   R0   R@   RA   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRB      s    N(   RE   RF   R:   RB   RI   RJ   (    (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRK      s   		t   MessageR5   R4   t   nodet   argst
   confidencec           B  s,   e  Z d d d d d   Z d   Z d Z RS(   c         C  s   t  j |  | | | | | f  S(   N(   t   tuplet   __new__(   t   clsR5   R4   RM   RN   RO   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRQ      s    c         C  sM   t  | t  rI |  j r7 | j r7 t t |   j |  S|  d  | d  k St S(   Ni(   t
   isinstanceRL   RO   t   supert   __eq__t   NotImplemented(   R0   t   other(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRU      s
    N(   RE   RF   RI   RQ   RU   t   __hash__(    (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRL      s   	t   UnittestLinterc           B  sV   e  Z d  Z d   Z d   Z d d d d d  Z d   Z d   Z e	 d    Z
 RS(   s0   A fake linter class to capture checker messages.c         C  s   g  |  _  i  |  _ d  S(   N(   t	   _messagest   stats(   R0   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyR1      s    	c         C  s   z |  j  SWd  g  |  _  Xd  S(   N(   RZ   (   R0   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   release_messages   s    c         C  s&   |  j  j t | | | | |   d  S(   N(   RZ   R   RL   (   R0   R5   R4   RM   RN   RO   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   add_message   s    c         O  s   t  S(   N(   R   (   R0   t   unused_argst   unused_kwargs(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   is_message_enabled   s    c         K  s4   x* t  j |  D] \ } } | |  j | <q W|  j S(   N(   t   sixt	   iteritemsR[   (   R0   t   kwargst   namet   value(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt	   add_stats   s    c         C  s   t  j S(   N(   t   lintert   options_providers(   R0   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRh      s    N(   RE   RF   RG   R1   R\   RI   R]   R`   Rf   t   propertyRh   (    (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRY      s   				c            s     f d   } | S(   s1   Decorator for setting config values on a checker.c           s%   t  j       f d    } | S(   Nc           sc   x3 t  j   D]" \ } } t |  j j | |  q Wt |  t  rU |  j j   n    |   d  S(   N(   Ra   Rb   t   setattrt   checkert   configRS   t   CheckerTestCaset   open(   R0   t   keyRe   (   t   funRc   (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   _forward   s
    (   t	   functoolst   wraps(   Rp   Rq   (   Rc   (   Rp   s/   lib/python2.7/site-packages/pylint/testutils.pyt   _wrapper   s    !	(    (   Rc   Rt   (    (   Rc   s/   lib/python2.7/site-packages/pylint/testutils.pyt
   set_config   s    Rm   c           B  sP   e  Z d  Z d Z i  Z d   Z e j d    Z	 e j d    Z
 d   Z RS(   sB   A base testcase class for unit testing individual checker classes.c         C  sk   t    |  _ |  j |  j  |  _ x6 t j |  j  D]" \ } } t |  j j | |  q4 W|  j j	   d  S(   N(
   RY   Rg   t   CHECKER_CLASSRk   Ra   Rb   t   CONFIGRj   Rl   Rn   (   R0   Ro   Re   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   setup_method   s
    c         c  s   |  j    
 d VWd QXd S(   s6   Assert that no messages are added by the given method.N(   t   assertAddsMessages(   R0   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   assertNoMessages   s    c         g  sl   d V|  j  j   } d d j d   | D  d j d   | D  f } t |  | k sh t |   d S(   s#  Assert that exactly the given method adds the given messages.

        The list of messages must exactly match *all* the messages added by the
        method. Additionally, we check to see whether the args in each message can
        actually be substituted into the message string.
        Ns<   Expected messages did not match actual.
Expected:
%s
Got:
%ss   
c         s  s   |  ] } t  |  Vq d  S(   N(   t   repr(   t   .0t   m(    (    s/   lib/python2.7/site-packages/pylint/testutils.pys	   <genexpr>   s    c         s  s   |  ] } t  |  Vq d  S(   N(   R{   (   R|   R}   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pys	   <genexpr>   s    (   Rg   R\   R   t   listt   AssertionError(   R0   R(   t   gotR6   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRy      s    c         C  s-   t  t  } | j |  j  | j |  d S(   s    recursive walk on the given nodeN(   R   Rg   t   add_checkerRk   t   walk(   R0   RM   t   walker(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyR      s    N(   RE   RF   RG   RI   Rv   Rw   Rx   t
   contextlibt   contextmanagerRz   Ry   R   (    (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyRm      s   	c         C  s   t  t j t |   j   S(   N(   R~   t   tokenizet   generate_tokensR
   t   readline(   t   code(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   _tokenize_str  s    c         c  s   t  j   \ } } |  rV t j d k rC t j | t |  d   qV t j | |   n  z	 | VWd t j |  t j |  Xd S(   s   Create a new temporary file.

    If *content* parameter is given, then it will be written
    in the temporary file, before passing it back.
    This is a context manager and should be used with a *with* statement.
    i   i    t   asciiN(   i   i    (	   t   tempfilet   mkstempt   syst   version_infot   ost   writet   bytest   closet   remove(   t   contentt   file_handlet   tmp(    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   _create_tempfile  s    	c         c  s3   t    $ } t j |   } | | _ | VWd QXd S(   sC   Create an astroid module for the given code, backed by a real file.N(   R   t   astroidt   parseR;   (   R   t   tempR@   (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   _create_file_backed_module  s    	(<   RG   t
   __future__R    t   collectionsR   Rr   R   R   R   R   R   t   os.pathR   R   R   R   R	   R   R   R   Ra   t	   six.movesR
   R   t   pylintR   t   pylint.utilsR   t   pylint.reportersR   t   pylint.interfacesR   t   pylint.lintR   R   R   t   TITLE_UNDERLINESt   __file__t   PREFIXR7   R+   R,   RK   t
   namedtupleRL   t   objectRY   Ru   Rm   t   test_reporterRg   t   set_reporterRl   t
   persistentt
   initializeR   R   RI   R   R   (    (    (    s/   lib/python2.7/site-packages/pylint/testutils.pyt   <module>   sP   (	&2%	)			