o
    ŠågÅ.  ã                   @  s”   d dl mZ d dlZd dl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
mZ ddlmZ ddlmZ d	d
lmZ ejjG dd„ deƒƒZdS )é    )ÚannotationsN)ÚPathé   )ÚTestBaseé   )Úconfig)Úeq_é   )Úutilc                   @  sz   e Zd ZdZejdd�dd„ ƒZejdd�dd„ ƒZd	d
„ Ze ¡ dd„ ƒZ	ejdd„ ƒZ
edd„ ƒZdd„ Zdd„ ZdS )ÚMypyTest)Úno_sqlalchemy2_stubsÚfunction)Úscopec                 c  ó   � |   ¡ E d H  d S ©N©Ú	_cachedir©Úself© r   ú\/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/testing/fixtures/mypy.pyÚper_func_cachedir   ó   €zMypyTest.per_func_cachedirÚclassc                 c  r   r   r   r   r   r   r   Úcachedir!   r   zMypyTest.cachedirc              	   c  sÂ   � d}t  ¡ �P}tt|ƒd dƒ�}| d|› d�¡ W d   ƒ n1 s%w   Y  tt|ƒd dƒ�}| d|› d�¡ W d   ƒ n1 sGw   Y  |V  W d   ƒ d S 1 sZw   Y  d S )	NÚ úsqla_mypy_config.cfgÚwz˜
                    [mypy]

                    plugins = sqlalchemy.ext.mypy.plugin

                    show_error_codes = True

                    z¡
                    disable_error_code = no-untyped-call

                    [mypy-sqlalchemy.*]
                    ignore_errors = True

                    úplain_mypy_config.cfgz^
                    [mypy]

                    show_error_codes = True

                    z®
                    disable_error_code = var-annotated,no-untyped-call
                    [mypy-sqlalchemy.*]
                    ignore_errors = True

                    )ÚtempfileÚTemporaryDirectoryÚopenr   Úwrite)r   Ú	mypy_pathr   Úconfig_filer   r   r   r   %   s2   €
ÿüÿýÿýÿý"ázMypyTest._cachedirc                   s    ddl m‰  d‡ ‡fdd„	}|S )Nr   )ÚapiFc           	   	     sŽ   |d u rˆ}ddd|dt j ||rdnd¡g}t j | ¡}t j ||¡}| |kr.t | |¡ | |¡ t j dd ¡ ˆ  	|¡\}}}|||fS )Nz--strictz--raise-exceptionsz--cache-dirz--config-filer   r   ÚMYPY_FORCE_COLOR)
ÚosÚpathÚjoinÚbasenameÚshutilÚcopyfileÚappendÚenvironÚpopÚrun)	r(   Ú
use_pluginÚuse_cachedirÚargsÚfilenameÚtest_programÚstdoutÚstderrÚexitcode©r%   r   r   r   r0   N   s,   ÿûú

z!MypyTest.mypy_runner.<locals>.run)FN)Úmypyr%   )r   r   r0   r   r9   r   Úmypy_runnerJ   s   %zMypyTest.mypy_runnerc                   s   d‡ ‡fdd„	}|S )NFc                   s2   ˆ  | ¡}ˆ | |d�\}}}ˆ | ||||¡ d S )N)r1   )Ú_collect_messagesÚ_check_output)r(   r1   Úexpected_messagesr6   r7   r8   ©r;   r   r   r   r0   w   s
   

ÿz)MypyTest.mypy_typecheck_file.<locals>.run)Fr   )r   r;   r0   r   r?   r   Úmypy_typecheck_fileu   s   zMypyTest.mypy_typecheck_filec                 C  s‚   t j | ¡r	| }nt ¡ d j}t j t j |¡| ¡}tt	|ƒ 
d¡ƒ}tjjD ]}|r>t j |¡r>| t	|ƒ|   
d¡¡ q(|S )Nr   z**/*.py)r'   r(   ÚisabsÚinspectÚstackr4   r)   ÚdirnameÚlistr   Úglobr   ÚoptionsÚmypy_extra_test_pathsÚisdirÚextend)rD   r(   Úcaller_pathÚfilesÚ	extra_dirr   r   r   Úfile_combinations€   s   €zMypyTest.file_combinationsc              
     sô  ddl m} g }t d¡}t d¡}t|ƒ�Ú}g }t|dƒD ]É\‰ }| |¡}	|	rJ|	 d¡ d¡\}
}}t	j
t|
ƒt|ƒfk rIt d|	 d¡ ¡ q| |¡}	|	rÓt|	 d¡ƒ}t|	 d¡ƒ}t|	 d	¡ƒ}t d
d|	 d¡¡}|r |s–t ddd„ |¡}t ddd„ |¡}t dd|¡}t ddd„ |¡}d }}d|› d�}|rºtjrº|d t |r®dnddd„ |dd … ¡ }|rÈtjrÈt ddd„ |¡}| ||| ¡ f¡ q|rç| ‡ fdd„|D ƒ¡ g |d d …< qW d   ƒ |S 1 sów   Y  |S ) Nr   )Úmypy_14z)\s*# EXPECTED(_MYPY)?(_RE)?(_TYPE)?: (.+)z%^#\s*PYTHON_VERSION\s?>=\s?(\d+\.\d+)r   Ú.zRequires python >= %sr   r	   z# noqa[:]? ?.*r   é   z([\[\]])c                 S  s   d|   d¡› �S )Nú\r   ©Úgroup©Úmr   r   r   Ú<lambda>¯   ó    z,MypyTest._collect_messages.<locals>.<lambda>z([\w_]+)c                 S  ó   d|   d¡› d�S )Nz	(?:.*\.)?r   ú\*?rS   rU   r   r   r   rW   ¸   ó    ÚListzbuiltins.listz\b(int|str|float|bool)\bc                 S  rY   )Nz	builtins.r   rZ   rS   rU   r   r   r   rW   Â   r[   TzRevealed type is "ú"z\b(List|Tuple|Dict|Set)\bz\b(List|Tuple|Dict|Set|Type)\bc                 S  s   |   d¡ ¡ S )Nr   )rT   ÚlowerrU   r   r   r   rW   Ú   s    zOptional\[(.*?)\]c                 S  s   |   d¡› d�S )Nr   z | NonerS   rU   r   r   r   rW   ã   rX   c                 3  s"   � | ]\}}}ˆ |||fV  qd S r   r   )Ú.0Úis_mypyÚis_reÚexpected_msg©Únumr   r   Ú	<genexpr>ê   s   € 
ü
ÿz-MypyTest._collect_messages.<locals>.<genexpr>)Úsqlalchemy.ext.mypy.utilrO   ÚreÚcompiler!   Ú	enumerateÚmatchrT   Ú	partitionÚsysÚversion_infoÚintr   Ú	skip_testÚboolÚsubr
   Úpy39Úpy310r-   ÚstriprJ   )r   r(   rO   r>   Úexpected_reÚ	py_ver_reÚfile_Úcurrent_assert_messagesÚlinerV   ÚmajorÚ_Úminorr`   ra   Úis_typerb   r   rc   r   r<   Ž   sŽ   



ÿ
ý	ýÿý

ÿ
ù

ýÿú€¤
þ` `zMypyTest._collect_messagesc                 C  s  g }t j |¡}|rðg }| d¡}	|	rU|	 d¡}
t d|
¡r&| d|
f¡ n-t d|
¡r=|	r<|	 d¡}t d|¡s:n|	s.nt d|
tj¡rFnt d|
¡rS| d	|
f¡ |	s|D ]V\}}}}| 	d
d¡}|sgdnd}t
|ƒD ]6\}\}}|rŒt d|› d|› d|› d|› |› �	|¡r‹ nqm|› d|› d|› d|› |› �| 	d
d¡v r£ nqm| |¡ qW||= qW|rÓd |¡}td|dd� |rÏd dd„ |D ƒ¡}td|dd� J dƒ‚|rîtt|ƒ› d�ƒ td dd„ |D ƒ¡ƒ J dƒ‚d S |dkrût||dd� t|d|d� d S )NÚ
r   z.+\.py:\d+: error: .*Úerrorz/.+\.py:\d+: note: +(?:Possible overload|def ).*z.+\.py:\d+: note: +def \[.*z*.+\.py:\d+: note: .*(?:perhaps|suggestion)z.+\.py:\d+: note: .*Únoteú'r]   z[SQLAlchemy Mypy plugin] r   z.*z\:z\: ú:z: z"Couldn't locate expected messages:)Úsepc                 s  ó   � | ]\}}|V  qd S r   r   ©r_   r{   Úmsgr   r   r   re   +  ó   € z)MypyTest._check_output.<locals>.<genexpr>zRemaining messages:Fz'expected messages not found, see stdoutz& messages from mypy were not consumed:c                 s  r„   r   r   r…   r   r   r   re   1  r‡   z&errors and/or notes remain, see stdout)r†   )r'   r(   r*   Úsplitr/   rg   rj   r-   ÚIÚreplaceri   r)   ÚprintÚlenr   )r   r(   r>   r6   r7   r8   Únot_locatedr4   ÚoutputÚ	raw_linesÚeÚolrd   r`   ra   r†   ÚprefixÚidxÚtypÚerrmsgÚmissingÚextrar   r   r   r=   ö   sv   

ÿ
ý€ÿðþü
ÿý

ýzMypyTest._check_outputN)Ú__name__Ú
__module__Ú__qualname__Ú__requires__r   Úfixturer   r   r   r;   r@   ÚstaticmethodrN   r<   r=   r   r   r   r   r      s    



%
*


hr   )Ú
__future__r   rB   r'   Úpathlibr   rg   r+   rl   r   Úbaser   r   r   Ú
assertionsr   r
   Úadd_to_markerr:   r   r   r   r   r   Ú<module>   s   