
    g.                        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y)    )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y)MypyTest)no_sqlalchemy2_stubsfunction)scopec              #  @   K   | j                         E d {    y 7 wN	_cachedirselfs    _/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/sqlalchemy/testing/fixtures/mypy.pyper_func_cachedirzMypyTest.per_func_cachedir        >>###   classc              #  @   K   | j                         E d {    y 7 wr   r   r   s    r   cachedirzMypyTest.cachedir!   r   r   c              #  r  K   d}t        j                         5 }t        t        |      dz  d      5 }|j	                  d| d       d d d        t        t        |      dz  d      5 }|j	                  d| d       d d d        | d d d        y # 1 sw Y   LxY w# 1 sw Y   "xY w# 1 sw Y   y xY ww)	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 !! K  	
  X!88# !! K  
 N?	 	   #	 	sK   B7B+B B+(B>B+
	B7B	B+B(	$B++B40B7c                $    ddl m dfd	}|S )Nr   )apic           	        |
}ddd|dt         j                  j                  ||rdnd      g}t         j                  j                  |       }t         j                  j                  ||      }| |k7  rt	        j
                  | |       |j                  |       t         j                  j                  dd        	j                  |      \  }}}|||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    #'$  & /4D* ww''-H77<<h?L|#l3KK% JJNN-t4'*wwt}$FFH68++    )FN)mypyr*   )r   r   r6   r*   s    ` @r   mypy_runnerzMypyTest.mypy_runnerJ   s    #	,J 
r?   c                     d fd	}|S )Nc                n    j                  |       } | |      \  }}}j                  | ||||       y )N)r7   )_collect_messages_check_output)r.   r7   expected_messagesr<   r=   r>   rA   r   s         r   r6   z)MypyTest.mypy_typecheck_file.<locals>.runw   sA     $ 6 6t <'24J'O$FFH'r?   )F )r   rA   r6   s   `` r   mypy_typecheck_filezMypyTest.mypy_typecheck_fileu   s    	 
r?   c                (   t         j                  j                  |       r| }n^t        j                         d   j
                  }t         j                  j                  t         j                  j                  |      |       }t        t        |      j                  d            }t        j                  j                  D ]Q  }|st         j                  j                  |      s&|j                  t        |      | z  j                  d             S |S )Nr   z**/*.py)r-   r.   isabsinspectstackr:   r/   dirnamelistr   globr   optionsmypy_extra_test_pathsisdirextend)rM   r.   caller_pathfiles	extra_dirs        r   file_combinationszMypyTest.file_combinations   s    77==!D!--/!,55K77<< <gFDT$Z__Y/0== 	JIRWW]]95d9o7==iHI	J r?   c           
     &   ddl m} g }t        j                  d      }t        j                  d      }t	        |      5 }g }t        |d      D ])  \  }|j                  |      }	|	rs|	j                  d      j                  d      \  }
}}t        j                  t        |
      t        |      fk  r't        j                  d|	j                  d      z         |j                  |      }	|	rft        |	j                  d            }t        |	j                  d            }t        |	j                  d	            }t        j                  d
d|	j                  d            }|rk|s_t        j                  dd |      }t        j                  dd |      }t        j                  dd|      }t        j                  dd |      }dx}}d| d}|r5t         j"                  r%|d   t        j                  |rdndd |dd        z   }|r(t         j$                  rt        j                  dd |      }|j'                  |||j)                         f       |s|j+                  fd|D               g |d d  , 	 d d d        |S # 1 sw Y   |S xY w)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                *    d| j                  d       S )N\r   groupms    r   <lambda>z,MypyTest._collect_messages.<locals>.<lambda>   s    Qqwwqzl*; r?   z([\w_]+)c                ,    d| j                  d       dS )Nz	(?:.*\.)?r   \*?r^   r`   s    r   rb   z,MypyTest._collect_messages.<locals>.<lambda>       Yqwwqzl#*F r?   Listzbuiltins.listz\b(int|str|float|bool)\bc                ,    d| j                  d       dS )Nz	builtins.r   rd   r^   r`   s    r   rb   z,MypyTest._collect_messages.<locals>.<lambda>   re   r?   TzRevealed type is ""z\b(List|Tuple|Dict|Set)\bz\b(List|Tuple|Dict|Set|Type)\bc                @    | j                  d      j                         S )Nr   )r_   lowerr`   s    r   rb   z,MypyTest._collect_messages.<locals>.<lambda>   s    aggaj&6&6&8 r?   zOptional\[(.*?)\]c                *    | j                  d       dS )Nr   z | Noner^   r`   s    r   rb   z,MypyTest._collect_messages.<locals>.<lambda>   s    G&< r?   c              3  2   K   | ]  \  }}}|||f  y wr   rG   ).0is_mypyis_reexpected_msgnums       r   	<genexpr>z-MypyTest._collect_messages.<locals>.<genexpr>   s-      -#!(	 gul;-s   )sqlalchemy.ext.mypy.utilrY   recompiler%   	enumeratematchr_   	partitionsysversion_infointr   	skip_testboolsubr   py39py310r3   striprS   )r   r.   rY   rF   expected_re	py_ver_refile_current_assert_messageslinera   major_minorrn   ro   is_typerp   rq   s                    @r   rD   zMypyTest._collect_messages   s   4jj!MNJJGH	$Z ^	45&(#&ua0 \4	TOOD)&'ggaj&:&:3&?OE1e''3u:s5z*BB((3qwwqzB %%d+"1771:.G ,E"1771:.G#%66*;R#LL$
 ,.66 + ; ,,L ,.66 + F ,,L ,.66 &,L ,.66 ; F ,,L +/.%);L>'K499 (4A $+ !=%F8(,: ( 4:: (*vv0<((
 ,22 %););)=> -%,, - 5-  24+A.y\4^	4@ ! A^	4@ ! s   HJ"JJc                   g }t         j                  j                  |      }|rg }|j                  d      }	|	r|	j	                  d      }
t        j                  d|
      r|j                  d|
f       nt        j                  d|
      r.|	r{|	j	                  d      }t        j                  d|      snS|	r+nOt        j                  d|
t
        j                        rn)t        j                  d|
      r|j                  d	|
f       |	r|D ]  \  }}}}|j                  d
d      }|sdnd}t        |      D ]T  \  }\  }}|r't        j                  d| d| d| d| | 	|      s0 n7| d| d| d| | |j                  d
d      v sT n |j                  |       ||=  |rNdj                  |      }t        d|d       |r&dj                  d |D              }t        d|d       J d       |r?t        t        |       d       t        dj                  d |D                     J d       y |dk7  rt        ||d       t        |d|       y )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'rh   z[SQLAlchemy Mypy plugin] r   z.*z\:z\: :z: z"Couldn't locate expected messages:)sepc              3  &   K   | ]	  \  }}|  y wr   rG   rm   r   msgs      r   rr   z)MypyTest._check_output.<locals>.<genexpr>+  s     %?fac%?   zRemaining messages:z'expected messages not found, see stdoutz& messages from mypy were not consumed:c              3  &   K   | ]	  \  }}|  y wr   rG   r   s      r   rr   z)MypyTest._check_output.<locals>.<genexpr>1  s     939r   z&errors and/or notes remain, see stdout)r   )r-   r.   r0   splitr5   rt   rw   r3   Ireplacerv   r/   printlenr	   )r   r.   rF   r<   r=   r>   not_locatedr:   output	raw_lineseolrq   rn   ro   r   prefixidxtyperrmsgmissingextras                         r   rE   zMypyTest._check_output   sf   77##D)
 FT*IMM!$884a8MM7A,/XXF $&]]1-!xx(FK! $ XXA1bdd XX5q9MM61+.! $ ->  (WeSkk#s+<C4*3F*; &C#v88!(2cU#cU#fXcUK" "#*AcU"SEF8C5A!>>#s34   &&s+3K% ( ))K0:GN II%?%??E/DAGGGuV%KLMdii9&99:FFFu  1}ff$/!(r?   N)__name__
__module____qualname____requires__r   fixturer   r   r   rA   rH   staticmethodrW   rD   rE   rG   r?   r   r   r      s    ,LV^^*%$ &$ V^^'"$ #$#J V^^( (T ^^   f!PB)r?   r   )
__future__r   rK   r-   pathlibr   rt   r1   ry   r#   baser   r   r   
assertionsr	   r   add_to_markerr@   r   rG   r?   r   <module>r      sU    #  	  	  
      ^)x ^) ^)r?   