
    [h.                        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e                      ZdS )    )annotationsN)Path   )TestBase   )config)eq_   )utilc                      e Zd ZdZ ej        d          d             Z ej        d          d             Zd Z ej                    d             Z	ej        d	             Z
ed
             Zd Zd ZdS )MypyTest)no_sqlalchemy2_stubsfunction)scopec              #  >   K   |                                  E d {V  d S N	_cachedirselfs    o/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/testing/fixtures/mypy.pyper_func_cachedirzMypyTest.per_func_cachedir   .      >>###########    classc              #  >   K   |                                  E d {V  d S r   r   r   s    r   cachedirzMypyTest.cachedir!   r   r   c              #    K   d}t          j                    5 }t          t          |          dz  d          5 }|                    d| d           d d d            n# 1 swxY w Y   t          t          |          dz  d          5 }|                    d| d           d d d            n# 1 swxY w Y   |V  d d d            d S # 1 swxY w 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_files       r   r   zMypyTest._cachedir%   s     	(** 	hX!77  !!
 	
 
 
                  X!88#  !!   
 
 
               NNN?	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sX   !CACA#	#C&A#	'#C
B0$C0B4	4C7B4	8CCCc                $    ddl m dfd	}|S )Nr   )apiFc           	        |
}ddd|dt           j                            ||rdnd          g}t           j                            |           }t           j                            ||          }| |k    rt	          j        | |           |                    |           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exitcoder*   r   s            r   r6   z!MypyTest.mypy_runner.<locals>.runN   s    #'$  &5..4 D* w''--H7<<h??L|##l333KK%%% JNN-t444'*wwt}}$FFH68++r   )FN)mypyr*   )r   r   r6   r*   s    ` @r   mypy_runnerzMypyTest.mypy_runnerJ   sA    #	, #	, #	, #	, #	, #	, #	,J 
r   c                     d fd	}|S )NFc                                         |           } | |          \  }}}                    | ||||           d S )N)r7   )_collect_messages_check_output)r.   r7   expected_messagesr<   r=   r>   r@   r   s         r   r6   z)MypyTest.mypy_typecheck_file.<locals>.runw   s`     $ 6 6t < <'2{4J'O'O'O$FFH'    r   )F )r   r@   r6   s   `` r   mypy_typecheck_filezMypyTest.mypy_typecheck_fileu   s.    	 	 	 	 	 	 	 
r   c                8   t           j                            |           r| }n[t          j                    d         j        }t           j                            t           j                            |          |           }t          t          |          
                    d                    }t          j        j        D ][}|rWt           j                            |          r8|                    t          |          | z  
                    d                     \|S )Nr   z**/*.py)r-   r.   isabsinspectstackr:   r/   dirnamelistr   globr   optionsmypy_extra_test_pathsisdirextend)rL   r.   caller_pathfiles	extra_dirs        r   file_combinationszMypyTest.file_combinations   s    7==!! 	GDD!-//!,5K7<< < <gFFDT$ZZ__Y//00= 	J 	JI JRW]]955 Jd9oo7==iHHIIIr   c           
        ddl m} g }t          j        d          }t          j        d          }t	          |          5 }g }t          |d          D ]e\  }|                    |          }	|	r|	                    d                              d          \  }
}}t          j
        t          |
          t          |          fk     r*t          j        d|	                    d          z             |                    |          }	|	rt          |	                    d                    }t          |	                    d                    }t          |	                    d	                    }t          j        d
d|	                    d                    }|rg|s[t          j        dd |          }t          j        dd |          }t          j        dd|          }t          j        dd |          }dx}}d| d}|r8t           j        r,|d         t          j        |rdndd |dd                    z   }|r#t           j        rt          j        dd |          }|                    |||                                f           ;|r(|                    fd|D                        g |d d <   g	 d d d            n# 1 swxY 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                2    d|                      d           S )N\r   groupms    r   <lambda>z,MypyTest._collect_messages.<locals>.<lambda>   s    *;qwwqzz*;*; r   z([\w_]+)c                4    d|                      d           dS )Nz	(?:.*\.)?r   \*?r]   r_   s    r   ra   z,MypyTest._collect_messages.<locals>.<lambda>       *Fqwwqzz*F*F*F r   Listzbuiltins.listz\b(int|str|float|bool)\bc                4    d|                      d           dS )Nz	builtins.r   rc   r]   r_   s    r   ra   z,MypyTest._collect_messages.<locals>.<lambda>   rd   r   TzRevealed type is ""z\b(List|Tuple|Dict|Set)\bz\b(List|Tuple|Dict|Set|Type)\bc                P    |                      d                                          S )Nr   )r^   lowerr_   s    r   ra   z,MypyTest._collect_messages.<locals>.<lambda>   s    aggajj&6&6&8&8 r   zOptional\[(.*?)\]c                2    |                      d           dS )Nr   z | Noner]   r_   s    r   ra   z,MypyTest._collect_messages.<locals>.<lambda>   s    &<&<&< r   c              3  ,   K   | ]\  }}}|||fV  d S r   rF   ).0is_mypyis_reexpected_msgnums       r   	<genexpr>z-MypyTest._collect_messages.<locals>.<genexpr>   sK       - -#!(	 gul;- - - - - -r   )sqlalchemy.ext.mypy.utilrX   recompiler%   	enumeratematchr^   	partitionsysversion_infointr   	skip_testboolsubr   py39py310r3   striprR   )r   r.   rX   rE   expected_re	py_ver_refile_current_assert_messagesliner`   major_minorrm   rn   is_typero   rp   s                    @r   rC   zMypyTest._collect_messages   s   444444j!MNNJGHH	$ZZ ^	45&(#&ua00 \4 \4	TOOD)) &'ggajj&:&:3&?&?OE1e'3u::s5zz*BBB(3qwwqzzB   %%d++ Q4"1771::..G ,,E"1771::..G#%6*;R#L#LL %L$ 
 ,.6 + ; ; ,, ,L ,.6 + F F ,, ,L ,.6 &, ,L ,.6 ; F F ,, ,L +/.%'KL'K'K'K 49  (4A $+!G < <%F88(,: : (  4:  (*v0<<(( (
 ,22 %););)=)=>    - 	4%,, - - - - 5- - -    24+AAA.y\4^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4 ^	4@ ! s   I:KKKc                J   g }t           j                            |          }|rTg }|                    d          }	|	r|	                    d          }
t          j        d|
          r|                    d|
f           nt          j        d|
          r0|	r-|	                    d          }t          j        d|          sn|	-nMt          j        d|
t
          j                  rn,t          j        d|
          r|                    d	|
f           |	|D ]\  }}}}|	                    d
d          }|sdnd}t          |          D ]W\  }\  }}|r&t          j        d| d| d| d| | 	|          r n?0| d| d| d| | |	                    d
d          v r nX|                    |           ||= |rdd                    |          }t          d|d           |r1d                    d |D                       }t          d|d           J d            |rUt          t          |           d           t          d                    d |D                                  J d            d S |dk    rt          ||d           t          |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'rg   z[SQLAlchemy Mypy plugin] r   z.*z\:z\: :z: z"Couldn't locate expected messages:)sepc              3      K   | ]	\  }}|V  
d S r   rF   rl   r   msgs      r   rq   z)MypyTest._check_output.<locals>.<genexpr>+  s&      %?%?fac%?%?%?%?%?%?r   zRemaining messages:Fz'expected messages not found, see stdoutz& messages from mypy were not consumed:c              3      K   | ]	\  }}|V  
d S r   rF   r   s      r   rq   z)MypyTest._check_output.<locals>.<genexpr>1  s&      993999999r   z&errors and/or notes remain, see stdout)r   )r-   r.   r0   splitr5   rs   rv   r3   Ireplaceru   r/   printlenr	   )r   r.   rE   r<   r=   r>   not_locatedr:   output	raw_lineseolrp   rm   rn   r   prefixidxtyperrmsgmissingextras                         r   rD   zMypyTest._check_output   sw   7##D)) ?	)
 FT**I /MM!$$84a88 /MM7A,////XF  / $ "&]]1--!x(FKK "! $ " XA1bd  / X5q99 /MM61+...!  /$ ->    (WeSkk#s++<CK44*3F*;*;  &C#v 
8K(KKcKKcKKfKcKK"  " "E	" $AAcAASAAFACAA!>>#s334 4 4
  &&s+++3KK H))K00:GNNNN B II%?%?%?%?%???E/DAAAAGGGGG GVLLLMMMdii99&99999:::FFFFFG G 1}}ff$////!((((((r   N)__name__
__module____qualname____requires__r   fixturer   r   r   r@   rG   staticmethodrV   rC   rD   rF   r   r   r   r      s       ,LV^*%%%$ $ &%$ V^'"""$ $ #"$# # #J V^( ( (T ^  ^   \f! f! f!PB) B) B) B) B)r   r   )
__future__r   rJ   r-   pathlibr   rs   r1   rx   r#   baser   r   r   
assertionsr	   r   add_to_markerr?   r   rF   r   r   <module>r      s    # " " " " "  				       				  



                          ^) ^) ^) ^) ^)x ^) ^) ^) ^) ^)r   