o
    y¬´\aF  ã                   @   sü  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m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
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
dlmZ d
dlmZ d
dl	mZ d
dl	mZ dd„ Zejdd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Z ej	!dJd"d#„ƒZ!d$d%„ Z"d a#d&d'„ Z$dKd(d)„Z%dKd*d+„Z&dKd,d-„Z'dKd.d/„Z(dKd0d1„Z)dKd2d3„Z*dKd4d5„Z+dKd6d7„Z,dKd8d9„Z-dKd:d;„Z.dKd<d=„Z/dKd>d?„Z0d@dA„ Z1dBdC„ Z2G dDdE„ dEe3ƒZ4G dFdG„ dGe3ƒZ5G dHdI„ dIe3ƒZ6dS )Lé    )Úabsolute_importNé   )Ú	assertsql)Úconfig)Úmock)Úutil)Údb_spec)Úfailé   )Úexc)Úorm)Úpool)Úschema)Útypes)Údefault)Úurl)Úcompat©Ú	decoratorc                  O   ó   t tj| fi |¤ŽS )aÊ  Context manager which expects one or more warnings.

    With no arguments, squelches all SAWarnings emitted via
    sqlalchemy.util.warn and sqlalchemy.util.warn_limited.   Otherwise
    pass string expressions that will match selected warnings via regex;
    all non-matching warnings are sent through.

    The expect version **asserts** that the warnings were in fact seen.

    Note that the test suite sets SAWarning warnings to raise exceptions.

    )Ú_expect_warningsÚsa_excÚ	SAWarning©ÚmessagesÚkw© r   úO/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/testing/assertions.pyÚexpect_warnings    s   r   c                 o   sd   � t | ƒ}t| tjƒr|tjƒsdV  dS t|i |¤Ž� dV  W d  ƒ dS 1 s+w   Y  dS )z›Context manager which expects one or more warnings on specific
    dialects.

    The expect version **asserts** that the warnings were in fact seen.

    N)r   Ú
isinstancer   Ústring_typesr   Ú_currentr   )Údbr   r   Úspecr   r   r   Úexpect_warnings_on0   s   €
"ÿr$   c                     ó   t ‡ fdd„ƒ}|S )z„Decorator form of expect_warnings().

    Note that emits_warning does **not** assert that the warnings
    were in fact seen.

    c                    ó@   t ˆ ddiŽ� | |i |¤ŽW  d   ƒ S 1 sw   Y  d S ©NÚassert_F)r   ©ÚfnÚargsr   ©r   r   r   ÚdecorateI   ó   $ÿzemits_warning.<locals>.decorater   ©r   r-   r   r,   r   Úemits_warningA   s   r0   c                  O   r   ©N)r   r   ÚSADeprecationWarningr   r   r   r   Úexpect_deprecatedQ   s   r3   c                    s   t ‡ ‡fdd„ƒ}|S )aV  Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    c                    sH   t ˆ gˆ¢R ddiŽ� | |i |¤ŽW  d   ƒ S 1 sw   Y  d S r'   )r$   r)   ©r"   r   r   r   r-   a   s   $ÿz"emits_warning_on.<locals>.decorater   )r"   r   r-   r   r4   r   Úemits_warning_onU   s   r5   c                     r%   )a+  Mark a test as immune from fatal deprecation warnings.

    With no arguments, squelches all SADeprecationWarning failures.
    Or pass one or more strings; these will be matched to the root
    of the warning description by warnings.filterwarnings().

    As a special case, you may pass a function name prefixed with //
    and it will be re-written as needed to match the standard warning
    verbiage emitted by the sqlalchemy.util.deprecated decorator.

    Note that uses_deprecated does **not** assert that the warnings
    were in fact seen.

    c                    r&   r'   )r3   r)   r,   r   r   r-   y   r.   z!uses_deprecated.<locals>.decorater   r/   r   r,   r   Úuses_deprecatedi   s   r6   TFc                 #   s¬   � ˆrdd„ |D ƒ‰n|‰t ˆƒ‰tj‰‡ ‡‡‡‡fdd„}t d|¡� d V  W d   ƒ n1 s2w   Y  |rP|r>tjsTˆrRJ dd ‡fdd	„ˆD ƒ¡ ƒ‚d S d S d S )
Nc                 S   s    g | ]}t  |t jt jB ¡‘qS r   )ÚreÚcompileÚIÚS)Ú.0Úmsgr   r   r   Ú
<listcomp>‡   s     z$_expect_warnings.<locals>.<listcomp>c                    s¤   t | ˆ ƒr| }t|ƒ} n	|r|d }nd }|rt|ˆ ƒs'ˆ| g|¢R i |¤ŽS ˆs+d S ˆD ]}ˆr6| | ¡s<ˆsD|| krDˆ |¡  d S q-ˆ| g|¢R i |¤Ž d S )Nr   )r   ÚstrÚ
issubclassÚmatchÚdiscard)r<   Úargr   Ú	exceptionÚfilter_©Úexc_clsÚfiltersÚ	real_warnÚregexÚseenr   r   Úour_warn�   s&   


ÿ
€z"_expect_warnings.<locals>.our_warnzwarnings.warnzWarnings were not seen: %sz, c                 3   s"   � | ]}d ˆ r
|j n| V  qdS )z%rN)Úpattern)r;   Ús)rI   r   r   Ú	<genexpr>ª   s   € 
ÿz#_expect_warnings.<locals>.<genexpr>)ÚsetÚwarningsÚwarnr   Úpatchr   Úpy3kÚjoin)rF   r   rI   r(   Úpy2konlyrK   r   rE   r   r   �   s"   €ÿÿÿÿr   c                   C   s
   t ƒ  dS )zÛCheck things that have to be finalized at the end of a test suite.

    Hardcoded at the moment, a modular system can be built here
    to support things like PG prepared transactions, tables all
    dropped, etc.

    N)Ú!_assert_no_stray_pool_connectionsr   r   r   r   Úglobal_cleanup_assertions¯   s   
rW   c                  C   st   t  ¡  tjrtd7 atdttjƒ ƒ t  ¡  tjr0ttjƒ} tj ¡  dat	 
d|  ¡ d S tdkr8J dƒ‚d S )Nr   z2Encountered a stray connection in test cleanup: %sr   z8Stray connection refused to leave after gc.collect(): %sé
   Fz*Encountered more than 10 stray connections)ÚtestutilÚlazy_gcr   Ú_refsÚ_STRAY_CONNECTION_FAILURESÚprintr>   Ú
gc_collectÚclearrP   rQ   )Úerrr   r   r   rV   ½   s&   ÿÿ

ÿÿrV   c                 C   s$   t  || ¡sJ |pd| |f ƒ‚d S )Nz%r !~ %r)r7   r@   ©ÚaÚbr<   r   r   r   Úeq_regexç   s   $rd   c                 C   s    | |ksJ |pd| |f ƒ‚dS )z.Assert a == b, with repr messaging on failure.ú%r != %rNr   ra   r   r   r   Úeq_ë   ó    rf   c                 C   s    | |ksJ |pd| |f ƒ‚dS )z.Assert a != b, with repr messaging on failure.z%r == %rNr   ra   r   r   r   Úne_ð   rg   rh   c                 C   s    | |ksJ |pd| |f ƒ‚dS )z.Assert a <= b, with repr messaging on failure.re   Nr   ra   r   r   r   Úle_õ   rg   ri   c                 C   ó   t | d|d� d S )NT©r<   ©Úis_©rb   r<   r   r   r   Úis_trueú   ó   ro   c                 C   rj   )NFrk   rl   rn   r   r   r   Úis_falseþ   rp   rq   c                 C   s    | |u sJ |pd| |f ƒ‚dS )z.Assert a is b, with repr messaging on failure.z%r is not %rNr   ra   r   r   r   rm     rg   rm   c                 C   s    | |usJ |pd| |f ƒ‚dS )z2Assert a is not b, with repr messaging on failure.z%r is %rNr   ra   r   r   r   Úis_not_  rg   rr   c                 C   s    | |v sJ |pd| |f ƒ‚dS )z.Assert a in b, with repr messaging on failure.z%r not in %rNr   ra   r   r   r   Úin_  rg   rs   c                 C   s    | |vsJ |pd| |f ƒ‚dS )z2Assert a in not b, with repr messaging on failure.z%r is in %rNr   ra   r   r   r   Únot_in_  rg   rt   c                 C   s"   |   |¡sJ |pd| |f ƒ‚dS )z>Assert a.startswith(fragment), with repr messaging on failure.z%r does not start with %rN)Ú
startswith)rb   Úfragmentr<   r   r   r   Ústartswith_  s   þrw   c                 C   sX   t  dd| ¡} t  dd| ¡} t  dd|¡}t  dd|¡}| |ks*J |p(d| |f ƒ‚d S )Nz^\s+?|\nÚ z {2,}ú re   )r7   Úsubra   r   r   r   Úeq_ignore_whitespace  s
    r{   c                 O   s>   z||i |¤Ž d}W n | y   d}Y nw |sJ dƒ‚d S )NFTú#Callable did not raise an exceptionr   )Ú
except_clsÚ	callable_r+   r   Úsuccessr   r   r   Úassert_raises'  s   ÿr€   c              
   O   sx   z||i |¤Ž J dƒ‚ | y; } z$t  |t |¡t j¡s&J d||f ƒ‚tt |¡ d¡ƒ W Y d }~d S d }~ww )NFr|   z%r !~ %súutf-8)r7   Úsearchr   Ú	text_typeÚUNICODEr]   Úencode)r}   r<   r~   r+   ÚkwargsÚer   r   r   Úassert_raises_message2  s   þ"€ûrˆ   c                   @   s(   e Zd Z									ddd„ZdS )ÚAssertsCompiledSQLNFc                    s@  |rt  ¡ }n8|	rd }n3|d u rt| dd ƒ}|d u rtjj}n |dkr(t  ¡ }n|dkr1t  ¡ }nt|tj	ƒr?t
 |¡ ¡ ƒ }i }i }|rI||d< |d urSt|ƒ|d< |
rYd|d< t|tjƒrk| ¡ }d|j_|j}n+t|tjjƒr–tj |d¡�}| ¡  |jd	 d
 d	 }W d   ƒ n1 s‘w   Y  |rœ||d< |jdd|i|¤Ž}tt|di ƒƒ}tjrÉ| d¡ dd¡}tdt  |¡ |  d¡ƒ ntdt  |¡ d¡ | ƒ t! "ddt  |¡¡}t#||d|||f ƒ |d urøt#| $|¡|ƒ |d u�r| $|¡‰ t#t%‡ fdd„|j&D ƒƒ|ƒ |d u�rt#|j'|ƒ d S d S )NÚ__dialect__r   Údefault_enhancedÚschema_translate_mapÚcolumn_keysTÚliteral_bindsÚ_execute_stmtr   r   Úcompile_kwargsÚdialectÚparamsr�   ÚasciiÚignorez
SQL String:
z[\n\t]rx   z%r != %r on dialect %rc                    s   g | ]}ˆ | ‘qS r   r   )r;   Úx©Úpr   r   r=   �  ó    z5AssertsCompiledSQL.assert_compile.<locals>.<listcomp>r   )(r   ÚDefaultDialectÚgetattrr   r"   r‘   ÚStrCompileDialectr   r   r    r   ÚURLÚget_dialectÚlistr   ÚQueryÚ_compile_contextÚ	statementÚ
use_labelsÚpersistenceÚBulkUDr   rR   ÚobjectÚexec_Ú
mock_callsr8   ÚreprrS   r…   Údecoder]   rƒ   r7   rz   rf   Úconstruct_paramsÚtupleÚpositiontupÚprefetch)ÚselfÚclauseÚresultr’   Úcheckparamsr‘   ÚcheckpositionalÚcheck_prefetchÚuse_default_dialectÚallow_dialect_selectrŽ   rŒ   r   r�   ÚcontextÚ	stmt_mockÚcÚ	param_strÚccr   r–   r   Úassert_compile?  sv   



þÿÿÿþÿ


ÿz!AssertsCompiledSQL.assert_compile)	NNNNNFFFN)Ú__name__Ú
__module__Ú__qualname__r»   r   r   r   r   r‰   >  s    ôr‰   c                   @   s   e Zd Zddd„Zdd„ ZdS )ÚComparesTablesFc                 C   sB  t |jƒt |jƒksJ ‚t|j|jƒD ]n\}}t|j|jƒ ||j|j u s(J ‚t|j|jƒ t|j|jƒ |rNd}t|jt|jƒƒsMJ ||j|jf ƒ‚n|  	||¡ t|jt
jƒrdt|jj|jjƒ tdd„ |jD ƒdd„ |jD ƒƒ |jr�t|jtjƒs�J ‚qt |jƒt |jƒksŽJ ‚|jD ]}|jj|j d usžJ ‚q‘d S )Nz)Type '%s' doesn't correspond to type '%s'c                 S   ó   h | ]}|j j’qS r   ©ÚcolumnÚname©r;   Úfr   r   r   Ú	<setcomp>«  r˜   z5ComparesTables.assert_tables_equal.<locals>.<setcomp>c                 S   rÀ   r   rÁ   rÄ   r   r   r   rÆ   ¬  r˜   )Úlenr¸   Úziprf   rÃ   Úprimary_keyÚnullabler   ÚtypeÚassert_types_baseÚsqltypesÚStringÚlengthÚforeign_keysÚserver_defaultr   ÚFetchedValueÚcolumns)r®   ÚtableÚreflected_tableÚstrict_typesr¸   Úreflected_cr<   r   r   r   Úassert_tables_equal–  s8   
þþÿ€
ÿz"ComparesTables.assert_tables_equalc                 C   s*   |j  |j ¡sJ d|j|j |j f ƒ‚d S )Nz7On column %r, type '%s' doesn't correspond to type '%s')rË   Ú_compare_type_affinityrÃ   )r®   Úc1Úc2r   r   r   rÌ   ·  s
   ÿÿz ComparesTables.assert_types_baseN)F)r¼   r½   r¾   rØ   rÌ   r   r   r   r   r¿   •  s    
!r¿   c                   @   sl   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zdd
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zejdd„ ƒZdd„ Zd	S )ÚAssertsExecutionResultsc                 G   s&   t |ƒ}tt|ƒƒ |  |||¡ d S r1   )rž   r]   r¨   Úassert_list)r®   r°   Úclass_Úobjectsr   r   r   Úassert_result¿  s   z%AssertsExecutionResults.assert_resultc                 C   sL   |   t|ƒt|ƒkd|j ¡ tdt|ƒƒD ]}|  ||| || ¡ qd S )Nz9result list is not the same size as test list, for class r   )r(   rÇ   r¼   ÚrangeÚ
assert_row)r®   r°   rÞ   Úlist_Úir   r   r   rÝ   Ä  s   þþÿz#AssertsExecutionResults.assert_listc              	   C   sª   |   |j|u dt|ƒ ¡ | ¡ D ]A\}}t|tƒr?t|d tƒr0|  t||ƒ|d |d ¡ q|  	|d t||ƒ|d ¡ q|   t||ƒ|kd|t||ƒ|f ¡ qd S )Nzitem class is not r   r   z'attribute %s value %s does not match %s)
r(   Ú	__class__r¨   Úitemsr   r«   rž   rÝ   rš   râ   )r®   rÞ   ÚrowobjÚdescÚkeyÚvaluer   r   r   râ   Î  s   ÿ
ÿþùz"AssertsExecutionResults.assert_rowc           	         sà   G dd„ dt ƒ‰t |¡}‡fdd„|D ƒ}t ‡fdd„|¡D ]}tdt|ƒjˆjf ƒ q t|ƒt|ƒkrCtdt|ƒt|ƒf ƒ tƒ ‰ ‡ ‡fd	d
„}|D ]}|D ]}|||ƒra| 	|¡  nqStdˆjt
|ƒf ƒ qOdS )zÉAs assert_result, but the order of objects is not considered.

        The algorithm is very expensive but not a big deal for the small
        numbers of rows that the test suite manipulates.
        c                   @   s   e Zd Zdd„ ZdS )zFAssertsExecutionResults.assert_unordered_result.<locals>.immutabledictc                 S   s   t | ƒS r1   )Úid©r®   r   r   r   Ú__hash__ç  s   zOAssertsExecutionResults.assert_unordered_result.<locals>.immutabledict.__hash__N)r¼   r½   r¾   rí   r   r   r   r   Úimmutabledictæ  s    rî   c                    s   h | ]}ˆ |ƒ’qS r   r   )r;   r‡   )rî   r   r   rÆ   ë  r˜   zBAssertsExecutionResults.assert_unordered_result.<locals>.<setcomp>c                    s
   t | ˆ ƒS r1   )r   )Úo)Úclsr   r   Ú<lambda>î  s   
 zAAssertsExecutionResults.assert_unordered_result.<locals>.<lambda>z#Unexpected type "%s", expected "%s"z+Unexpected object count "%s", expected "%s"c              	      st   |  ¡ D ]3\}}t|tƒr,zˆjt| |ƒ|d g|d ¢R Ž  W q ty+   Y  dS w t| |ˆ ƒ|kr7 dS qdS )Nr   r   FT)ræ   r   r«   Úassert_unordered_resultrš   ÚAssertionError)Úobjr#   ré   rê   )ÚNOVALUEr®   r   r   Ú_compare_itemý  s   
ÿÿÿÿzFAssertsExecutionResults.assert_unordered_result.<locals>._compare_itemz2Expected %s instance with attributes %s not found.T)Údictr   ÚIdentitySetÚitertools_filterfalser	   rË   r¼   rÇ   r¥   Úremover¨   )	r®   r°   rð   ÚexpectedÚfoundÚwrongrö   Úexpected_itemÚ
found_itemr   )rõ   rð   rî   r®   r   rò   ß  s@   
ÿÿÿÿÿ

þÿÿ€z/AssertsExecutionResults.assert_unordered_resultNc                 C   s   |d u r
ddl m} t |¡S )Nr   )r"   )rx   r"   r   Úassert_engine)r®   r"   r   r   r   Úsql_execution_asserter  s   
z.AssertsExecutionResults.sql_execution_asserterc                 G   s>   |   |¡�}|ƒ }W d   ƒ n1 sw   Y  |j|Ž  |S r1   ©r  r(   )r®   r"   r~   ÚrulesÚasserterr°   r   r   r   Úassert_sql_execution  s
   ÿ
z,AssertsExecutionResults.assert_sql_executionc                 C   sZ   g }|D ]}t |tƒrtjdd„ | ¡ D ƒŽ }ntj|Ž }| |¡ q| j||g|¢R Ž S )Nc                 S   s   g | ]
\}}t  ||¡‘qS r   )r   ÚCompiledSQL)r;   ÚkÚvr   r   r   r=   )  s    z6AssertsExecutionResults.assert_sql.<locals>.<listcomp>)r   r÷   r   ÚAllOfræ   r  Úappendr  )r®   r"   r~   r  ÚnewrulesÚruleÚnewruler   r   r   Ú
assert_sql#  s   
ÿ
z"AssertsExecutionResults.assert_sqlc                 C   s   |   ||t |¡¡ d S r1   )r  r   ÚCountStatements)r®   r"   r~   Úcountr   r   r   Úassert_sql_count1  s   ÿz(AssertsExecutionResults.assert_sql_countc           
         s¶   ‡ fdd„t ||ƒD ƒ}g }|D ]\}}}| | ¡ ¡ qz |ƒ W t ||ƒD ]\}	\}}}| d d d ¡ |	 t |¡¡ q&S t ||ƒD ]\}	\}}}| d d d ¡ |	 t |¡¡ qCw )Nc                    s    g | ]\}}ˆ   |¡||f‘qS r   )r  )r;   r"   r  rì   r   r   r=   7  s    ÿÿzEAssertsExecutionResults.assert_multiple_sql_count.<locals>.<listcomp>)rÈ   r
  Ú	__enter__Ú__exit__r(   r   r  )
r®   Údbsr~   ÚcountsÚrecsÚ	assertersÚctxr"   r  r  r   rì   r   Úassert_multiple_sql_count6  s   
þþþz1AssertsExecutionResults.assert_multiple_sql_countc                 g   s@   � |   |¡�}d V  W d   ƒ n1 sw   Y  |j|Ž  d S r1   r  )r®   r"   r  r  r   r   r   Úassert_executionE  s
   €ÿz(AssertsExecutionResults.assert_executionc                 C   s   |   |t |¡¡S r1   )r  r   r  )r®   r"   r  r   r   r   Úassert_statement_countK  rp   z.AssertsExecutionResults.assert_statement_countr1   )r¼   r½   r¾   rà   rÝ   râ   rò   r  r  r  r  r  Ú
contextlibÚcontextmanagerr  r  r   r   r   r   rÜ   ¾  s    

8
rÜ   )TTFr1   )7Ú
__future__r   r  r7   rP   rx   r   r   r   r   rY   Ú
exclusionsr   r	   r   r   r   r   r   r   rÍ   Úenginer   r   r   r   r   r  r$   r0   r3   r5   r6   r   rW   r\   rV   rd   rf   rh   ri   ro   rq   rm   rr   rs   rt   rw   r{   r€   rˆ   r¥   r‰   r¿   rÜ   r   r   r   r   Ú<module>   sd   
ÿ-
*










	W)