
'![c           @   s  d  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 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 e j f d	     YZ e j d
 e  d e f d     YZ e Z d e j d d d d d d g  f d     YZ i d d 6Z e j d e  Z d   Z d e j f d     YZ  d e! f d     YZ" i e j# d 6e j$ d 6e j% d 6e j& d 6Z' d   Z( d    Z) d!   Z* d" e! f d#     YZ+ d$ e+ f d%     YZ, d&   Z- e-   Z. g  e. D] Z/ e/ j0 ^ q*Z1 e j2 j3 d' e. d( e1 d)    Z4 e5 d* k rd+ e j6 k re7 Z e j6 j8 d+  n  e j9 e j6  n  d S(,   s(   Functional full-module tests for PyLint.iN(   t   configparser(   t   checkers(   t
   interfaces(   t   lint(   t	   reporterst   test_dialectc           B   s6   e  Z e j d  d k  r( d Z d Z n d Z d Z RS(   i    i   t   :s   
(   t   __name__t
   __module__t   syst   version_infot	   delimitert   lineterminator(    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   !   s
   	t   testt   NoFileErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   -   s   t
   OutputLinet   symbolt   linenot   objectt   msgt
   confidencec           B   s/   e  Z e d     Z e d    Z d   Z RS(   c         C   sX   |  | j  | j | j p d | j j d d  | j t j k rK | j j n	 t j	 j  S(   Nt    s   
s   
(
   R   t   linet   objR   t   replaceR   R   t	   UNDEFINEDt   namet   HIGH(   t   clsR   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   from_msg<   s    *c         C   sT   t  |  d k r | d n	 t j j } |  | d t | d  | d | d |  S(   Ni   i   i    i   i   i   (   t   lenR   R   R   t   int(   R   t   rowR   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   from_csvC   s    (c         C   s%   |  j  t j j k r |  d  S|  Sd  S(   Ni(   R   R   R   R   (   t   self(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   to_csvH   s    (   R   R   t   classmethodR   R!   R#   (    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   :   s   s   [a-z][a-z\-]+st   \s*#\s*(?:(?P<line>[+-]?[0-9]+):)?(?:(?P<op>[><=]+) *(?P<version>[0-9.]+):)?\s*\[(?P<msgs>%(msg)s(?:,\s*%(msg)s)*)\]c         C   s   t  d   |  j d  D  S(   Nc         s   s   |  ] } t  |  Vq d  S(   N(   R   (   t   .0t   digit(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pys	   <genexpr>]   s    t   .(   t   tuplet   split(   t   str(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   parse_python_version\   s    t   FunctionalTestReporterc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   |  j  j |  d  S(   N(   t   messagest   append(   R"   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   handle_messagea   s    c         C   s   g  |  _  d  S(   N(   R-   (   R"   t   modulet   filepath(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   on_set_current_moduled   s    c         C   s   d S(   s   Ignore layouts.N(    (   R"   t   layout(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   display_reportsg   s    (   R   R   R/   R2   R4   (    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR,   `   s   		t   FunctionalTestFilec           B   s   e  Z d  Z i e d 6e d 6d   d 6Z d   Z d   Z e d    Z e d    Z	 e d	    Z
 e d
    Z e d  Z RS(   s0   A single functional test case file with options.t	   min_pyvert	   max_pyverc         C   s   |  j  d  S(   Nt   ,(   R)   (   t   s(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   <lambda>q   s    t   requiresc         C   sQ   | |  _  | j d d  |  _ i d d 6d d 6g  d	 6g  d
 6|  _ |  j   d  S(   Ns   .pyR   i   i   R6   i   i    R7   R;   t   except_implementations(   i   i   (   i   i    (   t
   _directoryR   t   baset   optionst   _parse_options(   R"   t	   directoryt   filename(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   __init__u   s    	c         C   s   t  j   } | j d  y | j |  j  Wn t k
 r@ n XxH | j d  D]7 \ } } |  j j | d    } | |  |  j	 | <qQ Wd  S(   Nt   testoptionsc         S   s   |  S(   N(    (   t   v(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR:      s    (
   R    t   ConfigParsert   add_sectiont   readt   option_fileR   t   itemst   _CONVERTERSt   getR?   (   R"   t   cpR   t   valuet   conv(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR@      s    c         C   s   |  j  d  S(   Ns   .rc(   t
   _file_type(   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyRI      s    c         C   s+   t  j j |  j  } d j | |  j g  S(   NR'   (   t   ost   patht   basenameR=   t   joinR>   (   R"   t   package(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR0      s    c         C   s   |  j  d d t S(   Ns   .txtt   check_exists(   RP   t   False(   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   expected_output   s    c         C   s   |  j  d  S(   Ns   .py(   RP   (   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   source   s    c         C   sF   t  j j |  j |  j |  } | s8 t  j j |  r< | St  d  S(   N(   RQ   RR   RT   R=   R>   t   existsR   (   R"   t   extRV   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyRP      s    (   R   R   t   __doc__R+   RK   RC   R@   t   propertyRI   R0   RX   RY   t   TrueRP   (    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR5   k   s   		t   >t   <s   >=s   <=c         C   s,   g  t  j |  d  D] } t j |  ^ q S(   NR   (   t   csvt   readerR   R!   (   t   streamR    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   parse_expected_output   s    c   	      C   sE  t  j   } x2t |   D]$\ } } t j |  } | d	 k rF q n  | j d  } | d	 k rn | d } nA | j d  s | j d  r | d t |  } n t |  } | j d  } | j d  } | r t	 |  } t
 | t j |  s q q n  x< | j d  j d  D]" } | | | j   f c d 7<qWq W| S(
   s   Parses a file and get expected messages.

    :param stream: File-like input stream.
    :returns: A dict mapping line,msg-symbol tuples to the count on this line.
    R   i   t   +t   -t   versiont   opt   msgsR8   N(   t   collectionst   Countert	   enumeratet   _EXPECTED_REt   searcht   Nonet   groupt
   startswithR   R+   t
   _OPERATORSR	   R
   R)   t   strip(	   Rc   R-   t   iR   t   matchRg   Rh   t   requiredt   msg_id(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   get_expected_messages   s(    	$c         C   s   |  j    } | j |  i  } xY t t j |   D]B \ } } | d k r5 | j |  | d k  rw | | | <qw q5 q5 W| | f S(   s  Takes two multisets and compares them.

    A multiset is a dict with the cardinality of the key as the value.

    :param left_op: The expected entries.
    :param right_op: Actual entries.

    :returns: The two multisets of missing and unexpected messages.
    i    (   t   copyt   subtractt   listt   sixt	   iteritemst   pop(   t   left_opt   right_opt   missingt
   unexpectedt   keyRN   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   multiset_difference   s    
"t   LintModuleTestc           B   sq   e  Z d Z d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z RS(   c         C   s   t    } t j   |  _ |  j j |  d |  j j _ t j |  j  |  j j	 d  y$ |  j j
 | j  |  j j   Wn t k
 r n X| |  _ d  S(   Ni    t   I(   R,   R   t   PyLintert   _lintert   set_reportert   configt
   persistentR   t
   initializet   disablet   read_config_fileRI   t   load_config_fileR   t
   _test_file(   R"   t	   test_filet   test_reporter(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyRC      s    	c         C   s!  |  j    r3 t j d t j j d  d f  n  g  } xG |  j j d D]5 } y t |  WqJ t	 k
 r~ | j
 |  qJ XqJ W| r t j d d j |  f  n  |  j j d rg  |  j j d j d  D] } | j   ^ q } t j   } | | k rt j d | f  qn  d  S(	   Ns   Test cannot run with Python %s.t    i    R;   s   Requires %s to be present.R8   R<   s-   Test cannot run with Python implementation %r(   t!   _should_be_skipped_due_to_versiont   pytestt   skipR	   Rg   R)   R   R?   t
   __import__t   ImportErrorR.   RT   Rs   t   platformt   python_implementation(   R"   R   t   reqt   itemt   implementationst   implementation(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   setUp   s$    ' /c         C   s0   t  j |  j j d k  p/ t  j |  j j d k S(   NR6   R7   (   R	   R
   R   R?   (   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR     s    c         C   s#   d |  j  j |  j j |  j j f S(   Ns
   %s (%s.%s)(   R   R>   t	   __class__R   R   (   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   __str__  s    c         C   s   t  |  j j  S(   N(   t   openR   RX   (   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   _open_expected_file  s    c         C   s?   |  j  j d k r" t |  j  j  St j |  j  j d d Sd  S(   Nt   invalid_encoded_datat   encodingt   utf8(   R   R>   R   RY   t   io(   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   _open_source_file  s    c         C   s[   |  j     } t |  } Wd  QX| rK |  j    } t |  } Wd  QXn g  } | | f S(   N(   R   Rx   R   Rd   (   R"   t   fobjt   expected_msgst   expected_output_lines(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   _get_expected  s    c         C   s   |  j  j j } | j d d    t j   } g  } x@ | D]8 } | | j | j f c d 7<| j t	 j
 |   q; W| | f S(   NR   c         S   s   |  j  |  j |  j f S(   N(   R   R   R   (   t   m(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR:   )  s    i   (   R   t   reporterR-   t   sortRj   Rk   R   R   R.   R   R   (   R"   R-   t   received_msgst   received_output_linesR   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   _get_received'  s    c         C   s  |  j  j |  j j g  |  j   \ } } |  j   \ } } | | k r d |  j j g } t | |  \ } } | r | j d  | j	 d   t
 |  D  n  | r | j d  | j	 d   t
 |  D  n  t j d j |   n  |  j | | |  d  S(   Ns   Wrong results for file "%s":s   
Expected in testdata:c         s   s   |  ] } d  | Vq d S(   s    %3d: %sN(    (   R%   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pys	   <genexpr>=  s    s   
Unexpected in testdata:c         s   s   |  ] } d  | Vq d S(   s    %3d: %sN(    (   R%   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pys	   <genexpr>@  s    s   
(   R   t   checkR   R0   R   R   R>   R   R.   t   extendt   sortedR   t   failRT   t   _check_output_text(   R"   t   expected_messagest   expected_textt   received_messagest   received_textR   R   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   _runTest1  s      c         C   s_   g  g  } } xE | D]= } | d | d f | k rD | j  |  q | j  |  q W| | f S(   Ni   i    (   R.   (   R"   R   t   linest   emittedt   omittedR   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   _split_linesD  s    c         C   s2   |  j  | |  d | k s. t |  j j   d  S(   Ni    (   R   t   AssertionErrorR   R>   (   R"   R   t   expected_linest   received_lines(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   M  s    N(   R   R   Ro   t   maxDiffRC   R   R   R   R   R   R   R   R   R   R   (    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR      s   								
			t   LintModuleOutputUpdatec           B   s   e  Z d    Z d   Z RS(   c         C   s6   y t  t |   j   SWn t k
 r1 t j   SXd  S(   N(   t   superR   R   t   IOErrorR   t   StringIO(   R"   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   T  s    c   	      C   s   | s
 d  S|  j  | |  \ } } | | k r | j |  | j d d    t |  j j d  @ } t j | d d } x! | D] } | j | j	    q WWd  QXn  d  S(   NR   c         S   s   |  d |  d |  d f S(   Ni   i    i   (    (   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR:   a  s    t   wt   dialectR   (
   R   R   R   R   R   RX   Ra   t   writert   writerowR#   (	   R"   R   R   R   R   t	   remainingR   R   R   (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   Z  s    (   R   R   R   R   (    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyR   S  s   	c          C   s   t  j j t  j j t  j j t   d  }  g  } xK t  j |   D]: } | d k rC | j d  rC | j t	 |  |   qC qC W| S(   Nt
   functionals   __init__.pys   .py(
   RQ   RR   RT   t   dirnamet   abspatht   __file__t   listdirt   endswithR.   R5   (   t	   input_dirt   suitet   fname(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt	   get_testsg  s    $	R   t   idsc         C   s6   t  r t |   n	 t |   } | j   | j   d  S(   N(   t   UPDATER   R   R   R   (   R   t   LintTest(    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   test_functionalu  s    
t   __main__s   -u(:   R\   Ra   Rj   R   t   operatorRQ   t   reR	   R   R|   t	   six.movesR    R   t   pylintR   R   R   R   t   excelR   t   register_dialectt	   ExceptionR   RW   R   t
   namedtupleR   t   _MESSAGEt   compileRm   R+   t   BaseReporterR,   R   R5   t   gtt   ltt   get   leRr   Rd   Rx   R   R   R   R   t   TESTSt   tR>   t   TESTS_NAMESt   markt   parametrizeR   R   t   argvR^   t   removet   main(    (    (    s:   lib/python2.7/site-packages/pylint/test/test_functional.pyt   <module>   s^   	%
	:


			o	
	$