
    yIf/2                    b   d dl 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m	Z	 d dl
mZ d dlmZ d dlmZ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 dlmZ d dlmZmZm Z  d dl!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( eee)e*f                  Z+ ee,          j-        dz  Z. G d d          Z/dS )    )annotationsN)Counter)StringIO)Path)TextIOTuple)Config)checkers)_config_initialization)IS_PYPY)PyLinter)Message)_EXPECTED_RE
_OPERATORSUPDATE_OPTION)FunctionalTestFileNoFileErrorparse_python_version)
OutputLine)FunctionalTestReportertesting_pylintrcc                      e Zd ZdZ	 d(d)dZd*d	Zd*d
Zd+dZd,dZe	d-d            Z
e	d.d            Zd/dZd/dZd0dZd0dZd*dZd1d!Zd2d$Zd3d'ZdS )4LintModuleTestN	test_filer   configConfig | NonereturnNonec                &   t                      }t                      | _        d| j        j        _        t          j        | j                   t          }	 |j        }| j        	                    d           | j        	                    d           | j        	                    d           n# t          $ r Y nw xY w|| _        	 |j        g}n# t          $ r dg}Y nw xY w|r|                    d          r|                                 5 }d |                     |          D             }|                    d           |                    d	           |                    d
           d d d            n# 1 swxY w Y   |                    ddd                    |           g           | j        j                            dt*          d           | j        j                            dt*          d           | j        j                            dt*          d           | j        j                            dd g            | j        j                            dd g            | j        j                            dd g            | j        j                            dd           t-          | j        |||           t.          j        | j        j        j        k    | _        | j        rt6          rt.          j        dk    | _        || _        d S ) Nr   zsuppressed-messagezlocally-disabledzuseless-suppression minimal_messages_configc                    h | ]
}|d          S )    .0msgs     U/var/www/piapp/venv/lib/python3.11/site-packages/pylint/testutils/lint_module_test.py	<setcomp>z*LintModuleTest.__init__.<locals>.<setcomp>F   s    %V%V%Vc!f%V%V%V    zastroid-errorfatalzsyntax-errorz--disable=allz	--enable=,z--min_pyver)      )typedefaultz--max_pyver)   r   z--min_pyver_end_position)      z
--requiresc                @    d |                      d          D             S )Nc                6    g | ]}|                                 S r$   stripr&   is     r(   
<listcomp>z=LintModuleTest.__init__.<locals>.<lambda>.<locals>.<listcomp>X   s     )J)J)J!'')))J)J)Jr*   r,   splitss    r(   <lambda>z)LintModuleTest.__init__.<locals>.<lambda>X   s    )J)JQWWS\\)J)J)J r*   z--except_implementationsc                @    d |                      d          D             S )Nc                6    g | ]}|                                 S r$   r6   r8   s     r(   r:   z=LintModuleTest.__init__.<locals>.<lambda>.<locals>.<listcomp>\        <<<!AGGII<<<r*   r,   r;   r=   s    r(   r?   z)LintModuleTest.__init__.<locals>.<lambda>\       <<qwws||<<< r*   z--exclude_platformsc                @    d |                      d          D             S )Nc                6    g | ]}|                                 S r$   r6   r8   s     r(   r:   z=LintModuleTest.__init__.<locals>.<lambda>.<locals>.<listcomp>a   rB   r*   r,   r;   r=   s    r(   r?   z)LintModuleTest.__init__.<locals>.<lambda>a   rC   r*   z&--exclude_from_minimal_messages_configF)r0   )	args_listconfig_filereporter)r2   	   )r   r   _linterr   
persistentr
   
initializePYLINTRCoption_filedisabler   
_test_filesource	getoption_open_source_fileget_expected_messagesaddextendjoin_arg_parseradd_argumentr   r   sysversion_infomin_pyver_end_position_check_end_positionr   _config)selfr   r   _test_reporterrc_fileargsfmessages_to_enables           r(   __init__zLintModuleTest.__init__,   s    011zz)*&DL))) '	+GL  !5666L  !3444L  !67777 	 	 	D	 $	$%DD 	 	 	4DDD	  	Wf&&'@AA 	W'')) 7Q%V%V8R8RST8U8U%V%V%V""&&777"&&w///"&&~6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 KK*Tchh?Q6R6R*T*TUVVV 	 -- 4f 	. 	
 	
 	
 	 -- 4f 	. 	
 	
 	
 	 --&-A6 	. 	
 	
 	
 	 --JJTV 	. 	
 	
 	
 	 --&<< 	. 	
 	
 	

 	 --!<< 	. 	
 	
 	

 	 --4e 	. 	
 	
 	
 	LDg	
 	
 	
 	

  3 JJ 	  # 	B 	B'*'76'AD$s8   AB* *
B76B7C CC	AE44E8;E8c                |   |                                  r=t          j        dt          j                            dd          d          d           g }| j        j        j        D ]7}	 t          |           # t          $ r |                    |           Y 4w xY w|r+t          j        dd                    |           d	           | j        j        j        }|r?t          j                    |v r*d
}t          j        |t          j                    z             | j        j        j        }|rAt          j                                        |v r!t          j        dt          j                   | j        rA| j                            d          r)| j        j        j        rt          j        d           d S d S d S d S )NzTest cannot run with Python  r#   )maxsplitr   .z	Requires r,   z to be present.z-Test cannot run with Python implementation %rzTest cannot run on platform r!   z,Test excluded from --minimal-messages-config)!_should_be_skipped_due_to_versionpytestskiprZ   versionr<   rJ   r   requires
__import__ImportErrorappendrW   except_implementationsplatformpython_implementationexclude_platformslowerr^   rR   $exclude_from_minimal_messages_config)r_   missingrequirementrr   r'   excluded_platformss         r(   setUpzLintModuleTest.setUpu   s   1133 	KWs{/@/@q/@/Q/QRS/TWWW   <.7 	, 	,K,;'''' , , ,{+++++, 	HKFCHHW$5$5FFFGGG!%!4!K! 	D-//3IIIEC("@"B"BBCCC!\0B 	M|!!##'999K3<KKLLLL	H&&'@AA	H #H	H
 KFGGGGG	H 	H 	H 	H 	H 	Hs   (A88BBc                .    |                                   d S N)_runTestr_   s    r(   runTestzLintModuleTest.runTest   s    r*   boolc                ~    t           j        | j        j        j        k     pt           j        | j        j        j        k    S r}   )rZ   r[   rJ   r   	min_pyver	max_pyverr   s    r(   rj   z0LintModuleTest._should_be_skipped_due_to_version   s3    t|2<< @$,"5"??	
r*   strc                T    | j         j         d| j        j         d| j        j         dS )Nz (ri   ))rP   base	__class__
__module____name__r   s    r(   __str__zLintModuleTest.__str__   s0    /&``$.*C``dnF]````r*   streamr   MessageCounterc                   t                      }t          |           D ]4\  }}t          j        |          }||                    d          }||dz   }nO|                    d          s|                    d          r|dz   t          |          z   }nt          |          }|                    d          }|                    d          }|r0t          |          }t          |         t          j
        |          s|                    d                              d	          D ]&}	|||	                                fxx         dz  cc<   '6|S )
zParses a file and get expected messages.

        :param stream: File-like input stream.
        :type stream: enumerable
        :returns: A dict mapping line,msg-symbol tuples to the count on this line.
        :rtype: dict
        Nliner#   +-rm   opmsgsr,   )r   	enumerater   searchgroup
startswithintr   r   rZ   r[   r<   r7   )
r   messagesr9   r   matchlinenorm   r   requiredmsg_ids
             r(   rT   z$LintModuleTest.get_expected_messages   s[    $+99 (( 	6 	6GAt '--E};;v&&D|Q%% #)=)= #QT*Tkk),,GT""B /88!"~c&6AA ++f--33C88 6 6/000A500006r*   expected_entriesactual_entries1tuple[MessageCounter, dict[tuple[int, str], int]]c                    |                                  }|                    |           i }t          |                                          D ],\  }}|dk    r!|                    |           |dk     r| ||<   -||fS )z{Takes two multisets and compares them.

        A multiset is a dict with the cardinality of the key as the value.
        r   )copysubtractlistitemspop)r   r   rx   
unexpectedkeyvalues         r(   multiset_differencez"LintModuleTest.multiset_difference   s     #''))(((
w}}// 	- 	-JCzzC   199',fJsO
""r*   c                x    	 t          | j        j        d          S # t          $ r t	          d          cY S w xY w)Nutf-8encodingr    )openrP   expected_outputFileNotFoundErrorr   r   s    r(   _open_expected_filez"LintModuleTest._open_expected_file   sL    	 7'JJJJ  	  	  	 B<<	 s    99c                    | j         j        dk    rt          | j         j        d          S d| j         j        v rt          | j         j        d          S t          | j         j        d          S )Ninvalid_encoded_datar   r   latin1utf8)rP   r   r   rQ   r   s    r(   rS   z LintModuleTest._open_source_file   sk    ?#999.AAAAt+++.BBBBDO*V<<<<r*   'tuple[MessageCounter, list[OutputLine]]c                H                                      5 }                     |          }d d d            n# 1 swxY w Y   |st                      }                                 5 } fdt	          j        |d          D             }d d d            n# 1 swxY w Y   ||fS )Nc                D    g | ]}t          j        |j                  S r$   )r   from_csvr]   )r&   rowr_   s     r(   r:   z0LintModuleTest._get_expected.<locals>.<listcomp>   s9     % % % #C)ABB% % %r*   test)rS   rT   r   r   csvreader)r_   rc   expected_msgsexpected_output_liness   `   r(   _get_expectedzLintModuleTest._get_expected   s2   ##%% 	: 66q99M	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	&#IIM%%'' 	1% % % %:a00% % %!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 333s   8<<'"BBBc                R   | j         j        j        }|                    d            t	                      }g }|D ]i}|j        dk    sJ d|j         d            ||j        |j        fxx         dz  cc<   |                    t          j
        || j                             j||fS )Nc                *    | j         | j        | j        fS r}   )r   symbolr'   )ms    r(   r?   z,LintModuleTest._get_actual.<locals>.<lambda>   s    QVQXqu$= r*   r   r+   z#Pylint analysis failed because of ''r#   )rJ   rH   r   sortr   r   r'   r   rq   r   from_msgr]   )r_   r   received_msgsreceived_output_linesr'   s        r(   _get_actualzLintModuleTest._get_actual   s    "&,"7"@==>>>(/		 " 	 	C
g%%%?SW??? &%%#(CJ.///14///!((#C)ABB    333r*   c                ,   d}| j         j        g}| j                            |           |                                 \  }}|                                 \  }}||k    sJ |                     |||                      |                     |||           d S )NT)rP   rQ   rJ   checkr   r   error_msg_for_unequal_messages_check_output_text)r_   __tracebackhide__modules_to_checkexpected_messagesr   actual_messagesactual_outputs          r(   r~   zLintModuleTest._runTest   s      O23+,,,-1-?-?-A-A*?)-)9)9););&000...
 
 100 	 1?MRRRRRr*   r   r   r   list[OutputLine]c                L   dt          | j        j                  j         dg}|                     ||          \  }}|rA|                    d           |                    d t          |          D                        |rA|                    d           |                    d t          |          D                        d                    |          }| j	        rE| j	        
                    d          d	k    r'|d
z  }|d                    d |D                       z  }|S )NzWrong message(s) raised for "":z
Expected in testdata:c              3  @   K   | ]}d |d         dd|d          V  dS rg   r   3z: r#   Nr$   r%   s     r(   	<genexpr>z@LintModuleTest.error_msg_for_unequal_messages.<locals>.<genexpr>  s>      KKC/3q6///s1v//KKKKKKr*   z
Unexpected in testdata:c              3  @   K   | ]}d |d         dd|d          V  dS r   r$   r%   s     r(   r   z@LintModuleTest.error_msg_for_unequal_messages.<locals>.<genexpr>  s>      NNC/3q6///s1v//NNNNNNr*   
verboser   z&

Actual pylint output for this file:
c              3  4   K   | ]}t          |          V  d S r}   )r   )r&   os     r(   r   z@LintModuleTest.error_msg_for_unequal_messages.<locals>.<genexpr>  s(      "A"Aa3q66"A"A"A"A"A"Ar*   )r   rP   rQ   namer   rq   rV   sortedrW   r^   rR   )r_   r   r   r   r'   rx   r   	error_msgs           r(   r   z-LintModuleTest.error_msg_for_unequal_messages  s;    UtDO4J/K/K/PTTTU"66
 
  	LJJ0111JJKK6'??KKKKKK 	OJJ2333JJNN6*;M;MNNNNNNIIcNN	< 	BDL229==AADDI"A"A="A"A"AAAAIr*   expected_linesreceived_linesc                   t          |          t          |          z
  }t          |          t          |          z
  }dt          | j        j                  j         d}t          j        d          }|r!|dz  }t          ||          D ]
}|| dz  }|r|dz  }t          ||          D ]
}|| dz  }|dt           d	| j        j	         d
z  }t                      }t          j        |d          }	t          ||          D ])}|	                    |                                           *||                                z  }|S )NzWrong output for "r   r   z
- Missing lines:
r   r   z
- Unexpected lines:
zY
You can update the expected output automatically with:
'python tests/test_functional.py z -k "test_functional[z/]"'

Here's the update text in case you can't:
r   )dialect)setr   rP   r   r   operator
attrgetterr   r   r   r   r   writerwriterowto_csvgetvalue)
r_   r   r   rx   r   r   sort_by_line_numberr   expected_csvr   s
             r(   error_msg_for_unequal_outputz+LintModuleTest.error_msg_for_unequal_output  s   
 n%%N(;(;;((3~+>+>>
Wdo.M)N)N)SWWW	&1(;; 	)//Iw,?@@@ ) )[[[(		 	122Iz/BCCC ) )[[[(		>3@> >$(O$8> > >I $::LZf===F~3FGGG / /......000Ir*   _r   c                N    ||k    sJ |                      ||                      dS )zlThis is a function because we want to be able to update the text in
        LintModuleOutputUpdate.
        N)r   )r_   r   r   r   s       r(   r   z!LintModuleTest._check_output_text;  s8     -///1R1R]2
 2
/////r*   r}   )r   r   r   r   r   r   )r   r   )r   r   )r   r   )r   r   r   r   )r   r   r   r   r   r   )r   r   )r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   __qualname__maxDiffre   r{   r   rj   r   staticmethodrT   r   r   rS   r   r   r~   r   r   r   r$   r*   r(   r   r   )   s|       G FJG G G G GRH H H H:   
 
 
 
a a a a    \@ # # # \#$       = = = =
4 
4 
4 
44 4 4 4S S S S   ,   <
 
 
 
 
 
r*   r   )0
__future__r   r   r   rs   rZ   collectionsr   ior   pathlibr   typingCounterTyper   r   rk   _pytest.configr	   pylintr
   #pylint.config.config_initializationr   pylint.constantsr   pylint.lintr   pylint.message.messager   pylint.testutils.constantsr   r   r   %pylint.testutils.functional.test_filer   r   r   pylint.testutils.output_liner   #pylint.testutils.reporter_for_testsr   r   r   r   __file__parentrM   r   r$   r*   r(   <module>r     s  
 # " " " " " 



   



                   ) ) ) ) ) )                  ! ! ! ! ! !       F F F F F F $ $ $ $ $ $             * * * * * * N N N N N N N N N N         
 4 3 3 3 3 3 F F F F F FU38_-4>> #55]
 ]
 ]
 ]
 ]
 ]
 ]
 ]
 ]
 ]
r*   