o
    bz&                     @   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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d  Z"g dZ#eee$Z%ej!d dkZ&dd Z'G dd deZ(G dd deZ)G dd de*dg dZ+G dd dZ,dd Z-G dd dZ.e( Z/e  Z0e01e/ de0j2_3e4e0 dd  Z5ej6d%d!d"Z7ej6d#d$ Z8dS )&z*functional/non regression tests for pylint    )print_functionN)glob)linesepgetcwdsep)abspathbasenamedirnamejoinsplitext)StringIO)checkers)PyLintASTWalker)BaseReporter)	IReporter)PyLinterz%d%d%d   ) =-.c                 C   s   g }t t| |d | D ]l}t|}t|d }|ddd }| r*t|k r*q|dr@|dd  r@t|dd kr@qt t||d }	|	rkt|	d	d
D ]}
|
ddd dd }| rit|kri nqQnt||d }
|	||
f q|S )a  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
    *r   Z_py   _Nz*.txtT)reversez.txt)
r   r
   r   r   rsplitisdigitSYS_VERS_STR
startswithsortedappend)Z	input_dirZmsg_dirprefixsuffixresultfnameinfileZfbaseZpyrestrmessagesoutfileZpy_rest r*   O/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/testutils.py_get_tests_info5   s*   r,   c                   @   sH   e Zd ZdZeZdd Zdd Zdd Zdd	 Z	d
d Z
dd ZdZdS )TestReporterz$reporter storing plain text messagesc                 C   s   i | _ |   t t | _d S N)message_idsresetr   r   Zpath_strip_prefixselfr*   r*   r+   __init__`   s   zTestReporter.__init__c                 C   s   t  | _g | _d S r.   )r   outr(   r1   r*   r*   r+   r0   f   s   
zTestReporter.resetc                 C   sj   |j }|j}|j}|j}d| j|< |rd| }|d }tr'tdkr'|dd}| j	d||||f  dS )z<manage message of different type and in the context of path r   z:%sr   
z
z%s:%3s%s: %sN)
objlinemsg_idmsgr/   PY3Kr   replacer(   r"   )r2   r9   r6   r7   r8   Zsigler*   r*   r+   handle_messagej   s   
zTestReporter.handle_messagec                 C   s:   | j   | j D ]	}t|| jd q| j }|   |S )N)file)r(   sortprintr4   getvaluer0   )r2   r9   r%   r*   r*   r+   finalizez   s   


zTestReporter.finalizec                 C   s   d S r.   r*   r2   modulefilepathr*   r*   r+   on_set_current_module      z"TestReporter.on_set_current_modulec                 C      dS )zignore layoutsNr*   )r2   Zlayoutr*   r*   r+   display_reports   s    zTestReporter.display_reportsN)__name__
__module____qualname____doc__r   Z__implements__r3   r0   r<   rA   rE   rH   _displayr*   r*   r*   r+   r-   [   s    	r-   c                   @   s    e Zd Zdd Zdd ZdZdS )MinimalTestReporterc                 C   s   | j | d S r.   )r(   r"   )r2   r9   r*   r*   r+   r<      s   z"MinimalTestReporter.handle_messagec                 C   s
   g | _ d S r.   )r(   rB   r*   r*   r+   rE      s   
z)MinimalTestReporter.on_set_current_moduleN)rI   rJ   rK   r<   rE   rM   r*   r*   r*   r+   rN      s    rN   c                       s*   e Zd ZdddZ fddZdZ  ZS )MessageNc                 C   s   t | |||||fS r.   )tuple__new__)clsr8   r7   nodeargs
confidencer*   r*   r+   rQ      s   zMessage.__new__c                    sB   t |tr| jr|jrtt| |S | d d |d d kS tS )Nr   )
isinstancerO   rU   super__eq__NotImplemented)r2   other	__class__r*   r+   rX      s
   
zMessage.__eq__)NNNN)rI   rJ   rK   rQ   rX   __hash____classcell__r*   r*   r[   r+   rO      s    
rO   )r8   r7   rS   rT   rU   c                   @   sH   e Zd ZdZdd Zdd Z	dddZd	d
 Zdd Ze	dd Z
dS )UnittestLinterz0A fake linter class to capture checker messages.c                 C   s   g | _ i | _d S r.   )	_messagesstatsr1   r*   r*   r+   r3      s   
zUnittestLinter.__init__c                 C   s   z| j W g | _ S g | _ w r.   )r`   r1   r*   r*   r+   release_messages   s   zUnittestLinter.release_messagesNc                 C   s   | j t||||| d S r.   )r`   r"   rO   )r2   r8   r7   rS   rT   rU   
col_offsetr*   r*   r+   add_message   s   zUnittestLinter.add_messagec                 O   rG   )NTr*   )r2   Zunused_argsZunused_kwargsr*   r*   r+   is_message_enabled   rF   z!UnittestLinter.is_message_enabledc                 K   s"   |  D ]	\}}|| j|< q| jS r.   )itemsra   )r2   kwargsnamevaluer*   r*   r+   	add_stats   s   zUnittestLinter.add_statsc                 C   s   t jS r.   )linteroptions_providersr1   r*   r*   r+   rl      s   z UnittestLinter.options_providers)NNNNN)rI   rJ   rK   rL   r3   rb   rd   re   rj   propertyrl   r*   r*   r*   r+   r_      s    
r_   c                     s    fdd}|S )z1Decorator for setting config values on a checker.c                    s   t   fdd}|S )Nc                    sB     D ]\}}t| jj|| qt| tr| j   |  d S r.   )rf   setattrcheckerconfigrV   CheckerTestCaseopenr2   keyri   )funrg   r*   r+   _forward   s
   

z.set_config.<locals>._wrapper.<locals>._forward)	functoolswraps)ru   rv   rg   )ru   r+   _wrapper   s   zset_config.<locals>._wrapperr*   )rg   rz   r*   ry   r+   
set_config   s   r{   c                   @   sD   e Zd ZdZdZi Zdd Zejdd Z	ejdd Z
d	d
 ZdS )rq   zBA base testcase class for unit testing individual checker classes.Nc                 C   sH   t  | _| | j| _| j D ]\}}t| jj|| q| j  d S r.   )	r_   rk   CHECKER_CLASSro   CONFIGrf   rn   rp   rr   rs   r*   r*   r+   setup_method   s
   zCheckerTestCase.setup_methodc                 c   s6    |    dV  W d   dS 1 sw   Y  dS )z6Assert that no messages are added by the given method.N)assertAddsMessagesr1   r*   r*   r+   assertNoMessages   s   
"z CheckerTestCase.assertNoMessagesc                 g   sV    dV  | j  }dddd |D ddd |D f }t||ks)J |dS )a#  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.
        Nz<Expected messages did not match actual.
Expected:
%s
Got:
%sr5   c                 s       | ]}t |V  qd S r.   repr.0mr*   r*   r+   	<genexpr>       z5CheckerTestCase.assertAddsMessages.<locals>.<genexpr>c                 s   r   r.   r   r   r*   r*   r+   r      r   )rk   rb   r
   list)r2   r(   gotr9   r*   r*   r+   r      s   
z"CheckerTestCase.assertAddsMessagesc                 C   s"   t t}|| j || dS )z recursive walk on the given nodeN)r   rk   Zadd_checkerro   walk)r2   rS   walkerr*   r*   r+   r      s   zCheckerTestCase.walk)rI   rJ   rK   rL   r|   r}   r~   
contextlibcontextmanagerr   r   r   r*   r*   r*   r+   rq      s    

rq   c                 C   s   t tt| jS r.   )r   tokenizegenerate_tokensr   readline)coder*   r*   r+   _tokenize_str  s   r   c              	   c   st    t  \}}| rtjdkrt|t| d nt||  z|V  W t| t| dS t| t| w )zCreate 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.
    )r   r   asciiN)	tempfilemkstempsysversion_infooswritebytescloseremove)contentZfile_handletmpr*   r*   r+   _create_tempfile  s   


r   c                 c   sD    t  }t| }||_|V  W d   dS 1 sw   Y  dS )zCCreate an astroid module for the given code, backed by a real file.N)r   astroidparser=   )r   temprC   r*   r*   r+   _create_file_backed_module+  s   
"r   r.   )9rL   
__future__r   collectionsr   rw   r   r   r   r   r   os.pathr   r   r	   r
   r   r   r   r   ior   r   Zpylintr   Zpylint.utilsr   Zpylint.reportersr   Zpylint.interfacesr   Zpylint.lintr   r   r   ZTITLE_UNDERLINES__file__PREFIXr:   r,   r-   rN   
namedtuplerO   r_   r{   rq   Ztest_reporterrk   Zset_reporterrp   
persistentZ
initializer   r   r   r   r*   r*   r*   r+   <module>   sT   &3

"+

