
    c                       d Z ddlm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
mZmZ ddlmZ ddlmZ ddlmZ eZeeef         Zes"d	 ej         e ej        d
                    <   d#dZdZdZd$dZd%dZd&dZefd'd"Z dS )(z,Utility functions for configuration testing.    )annotationsN)Path)AnyDict)Mock)	PY38_PLUS)Runc                    | S )N )r_s     Clib/python3.11/site-packages/pylint/testutils/configuration_test.py<lambda>r      s          tested_configuration_file
str | Pathsuffixstrdefaultreturnc                J   |}t          |           }|j        |j         d| z  }|                                rSt	          |d          5 }|                                }ddd           n# 1 swxY w Y   t          j        d|           nt          j        d||           |S )zKReturn the expected value from the file if it exists, or the given default..utf8)encodingNz
%s exists.z%s not found, using '%s'.)r   parentstemexistsopenreadlogginginfo)r   r   r   expectedpathexpected_result_pathfs          r   get_expected_or_defaultr'   "   s     H)**D;DI)@)@)@)@@""$$ Q&888 	 AvvxxH	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 
 	\#7888802FPPPOs   A,,A03A0functional_appendfunctional_removeconfiguration_pathdefault_configurationPylintConfigurationc                   t          j        |          }t          | dd          }t          j        |          }|                                D ]\  }}|t          k    r+|                                D ]\  }}||xx         |z  cc<   ;|t          k    rF|                                D ]0\  }}g }	||         D ]}
|
|vr|	                    |
           |	||<   1|||<   |S )zIGet the expected parsed configuration of a configuration functional test.zresult.jsonz{}r   r   )	copydeepcopyr'   jsonloadsitemsEXPECTED_CONF_APPEND_KEYEXPECTED_CONF_REMOVE_KEYappend)r*   r+   resultconfig_as_jsonto_overridekeyvaluefkeyfvalue	new_value	old_values              r   get_expected_configurationr@   ;   s*    ]011F,=$  N *^,,K!''))    
U** 	  % ' 'ft&',, 	  % ) )f	!' 4 4I . 4!((333(t)  F3KKMr   suffix_filter
list[Path]c                p    t          |           fdj                                        D             S )zEReturn all the file related to a test conf file ending with a suffix.c                    g | ]R}t          |j                                      j                  .t          |                                        P|SS r   )r   r   
startswithendswith).0p	conf_pathrA   s     r   
<listcomp>z%get_related_files.<locals>.<listcomp>Y   sc       qv;;!!).11 7:!ffoom6T6T	  r   )r   r   iterdir)r   rA   rI   s    `@r   get_related_filesrL   T   sS     .//I    !))++   r   user_specific_pathr   tuple[int, str]c                d   d}d}t          | d          }t          |          dk    rt          j        d| |           dS |st          j        d           d	S |d         }	 t          t          |j                                      d
d          d                   }n/# t          $ r"}t          j        d| ||           Y d}~dS d}~ww xY wt          | | dd          }t          j        d| |           ||                    | t          |                               |                    fS )z-Get the expected output of a functional test.r   zwe expect a single file of the form 'filename.32.out' where 'filename' represents the name of the configuration file, and '32' the expected error code.out)rA      zToo much .out files for %s %s.)zout file is brokenz9.out file does not exists, so the expected exit code is 0)r   r   r   )maxsplitrR   z-Wrong format for .out file name for %s %s: %sNz.outr   r.   z4Output exists for %s so the expected exit code is %s)abspathrelpath)rL   lenr!   errorr"   intr   r   rsplit	Exceptionr'   formatr   relative_to)r*   rM   	exit_codemsgpossible_out_filesr$   eoutputs           r   get_expected_outputrb   `   s    I	P  ++=USSS
" (,	
 	
 	

 ('  	PQQQua D	(DI--cA->>rBCC		 ( ( (;		
 	
 	
 ('''''( %i#5#5#5r  F L>  
 fmm"'((445GHH $    s   "<B 
C)CC
Path | strfile_to_linttuple[Mock, Mock, Run]c                2   t          |           } d| |g}t          j                            d          5 }d}t          j                            |          5 }t	          |          }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |||fS )zHSimulate a run with a configuration without really launching the checks.z--rcfilezsys.exitz#pylint.lint.pylinter.check_parallelN)r   unittestmockpatchr	   )r*   rd   argsmocked_exitcheckmocked_check_parallelrunners          r   run_using_a_configuration_filero      s    /00*L9D 
		Z	(	( K
 6]  '' 	+@YYF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	               -v55s5   "B	A2&B	2A6	6B	9A6	:B		BB)r   r   r   r   r   r   r   r   )r*   r   r+   r,   r   r,   )r   r   rA   r   r   rB   )r*   r   rM   r   r   rN   )r*   rc   rd   r   r   re   )!__doc__
__future__r   r/   r1   r!   rerg   pathlibr   typingr   r   unittest.mockr   pylint.constantsr   pylint.lintr	   ConfigurationValuer   r,   _deepcopy_dispatchtypecompiler'   r4   r5   r@   rL   rb   __file__ro   r   r   r   <module>r}      s~  
 3 2 " " " " " "    				                      & & & & & &        3 223   C 5CNDDDB001   * / .    2	 	 	 	. . . .d 9A6 6 6 6 6 6 6r   