o
    y¬´\ó  ã                   @   s–   d dl m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 G dd„ dejƒZG dd„ deƒZdS )é    )ÚdequeNé   )Úconfig)Úfixtures)Ú	profilingé   )Úcreate_engine)ÚMetaData)Úutil)ÚSessionc                   @   s:   e Zd Zejdd„ ƒZdd„ Zdd„ Zdd„ Zd	d
„ Z	dS )ÚReplayFixtureTestc                 o   s   � d V  d S ©N© )ÚselfÚargÚkwr   r   úS/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/testing/replay_fixture.pyÚ
_dummy_ctx   s   €
zReplayFixtureTest._dummy_ctxc                    s  t ƒ ‰tjjj‰ ‡ ‡fdd„}ttjj|dd�}t|ƒ| _|| _	t
|ƒ| _|  ¡  z| j| jd� W |  ¡  | ¡  n	|  ¡  | ¡  w ‡fdd„}ttjj|dd�}t|ƒ| _|| _	t
|ƒ| _|  ¡  z| jtjd� W | j ¡  | ¡  d S | j ¡  | ¡  w )Nc                      s   ˆ  ˆ ƒ ¡S r   )Úrecorderr   ©ÚcreatorÚdbapi_sessionr   r   r      ó   z3ReplayFixtureTest.test_invocation.<locals>.recorderF)r   Úuse_native_hstore)Úctxc                      s   ˆ   ¡ S r   )Úplayerr   )r   r   r   r   )   s   z1ReplayFixtureTest.test_invocation.<locals>.player)ÚReplayableSessionr   ÚdbÚpoolÚ_creatorr   Úurlr	   ÚmetadataÚenginer   ÚsessionÚsetup_engineÚ
_run_stepsr   Úteardown_engineÚdisposer   Úcount_functionsÚclose)r   r   r"   r   r   r   r   Útest_invocation   s<   

ÿ


ÿ

ÿ



ÿ
z!ReplayFixtureTest.test_invocationc                 C   ó   d S r   r   ©r   r   r   r   r$   ;   ó   zReplayFixtureTest.setup_enginec                 C   r+   r   r   r,   r   r   r   r&   >   r-   z!ReplayFixtureTest.teardown_enginec                 C   s   t ƒ ‚r   )ÚNotImplementedError)r   r   r   r   r   r%   A   s   zReplayFixtureTest._run_stepsN)
Ú__name__Ú
__module__Ú__qualname__Ú
contextlibÚcontextmanagerr   r*   r$   r&   r%   r   r   r   r   r      s    
(r   c                   @   s¼   e Zd ZdZeƒ Zeƒ Zejr#e	dd„ e
eƒD ƒƒ dd„ dD ƒ¡Zne	dd„ e
eƒD ƒƒ dd„ e ¡ D ƒ¡ dd„ d	D ƒ¡Zd
d„ Zdd„ Zdd„ ZG dd„ deƒZG dd„ deƒZdS )r   a  A simple record/playback tool.

    This is *not* a mock testing class.  It only records a session for later
    playback and makes no assertions on call consistency whatsoever.  It's
    unlikely to be suitable for anything other than DB-API recording.

    c                 C   ó    g | ]}|  d ¡stt|ƒ‘qS ©Ú_©Ú
startswithÚgetattrÚtypes©Ú.0Útr   r   r   Ú
<listcomp>S   s     zReplayableSession.<listcomp>c                 C   ó   g | ]}t t|ƒ‘qS r   ©r9   r:   r;   r   r   r   r>   U   ó    ÿÿ)ÚFunctionTypeÚBuiltinFunctionTypeÚ
MethodTypeÚBuiltinMethodTypeÚ
LambdaTypeÚUnboundMethodTypec                 C   r4   r5   r7   r;   r   r   r   r>   d   s    ýÿc                 C   s"   g | ]}t |tƒst|ƒn|‘qS r   )Ú
isinstanceÚtyper;   r   r   r   r>   k   s    ÿÿc                 C   r?   r   r@   r;   r   r   r   r>   q   rA   )rB   rC   rD   rE   rF   c                 C   s   t ƒ | _d S r   )r   Úbufferr,   r   r   r   Ú__init__~   r   zReplayableSession.__init__c                 C   s   |   | j|¡S r   )ÚRecorderrJ   )r   Úbaser   r   r   r   �   s   zReplayableSession.recorderc                 C   s   |   | j¡S r   )ÚPlayerrJ   r,   r   r   r   r   „   r   zReplayableSession.playerc                   @   ó0   e Zd Zdd„ Zdd„ Zedd„ ƒZdd„ Zd	S )
zReplayableSession.Recorderc                 C   s   || _ || _d S r   )Ú_bufferÚ_subject)r   rJ   Úsubjectr   r   r   rK   ˆ   s   
z#ReplayableSession.Recorder.__init__c                    sZ   ‡ fdd„dD ƒ\}}||i |¤Ž}t |ƒtjvr&| tj¡ t ˆ ƒ||ƒS | |¡ |S )Nc                    ó   g | ]}t  ˆ |¡‘qS r   ©ÚobjectÚ__getattribute__©r<   Úxr,   r   r   r>   �   ó    
ÿÿz7ReplayableSession.Recorder.__call__.<locals>.<listcomp>©rQ   rP   )rI   r   ÚNativesÚappendÚCallable)r   Úargsr   rR   rJ   Úresultr   r,   r   Ú__call__Œ   s   

þ
z#ReplayableSession.Recorder.__call__c                 C   s   | j S r   )rQ   r,   r   r   r   Ú_sqla_unwrapš   s   z'ReplayableSession.Recorder._sqla_unwrapc                    s    zt  ˆ |¡W S  ty   Y nw ‡ fdd„dD ƒ\}}z
t|ƒ ||¡}W n ty4   | tj¡ ‚ w t|ƒtjvrI| tj¡ tˆ ƒ||ƒS | |¡ |S )Nc                    rS   r   rT   rW   r,   r   r   r>   ¤   rY   z?ReplayableSession.Recorder.__getattribute__.<locals>.<listcomp>rZ   )	rU   rV   ÚAttributeErrorrI   r\   r   ÚNoAttributer[   r]   )r   ÚkeyrR   rJ   r_   r   r,   r   rV   ž   s&   ÿ

þþ
z+ReplayableSession.Recorder.__getattribute__N©r/   r0   r1   rK   r`   Úpropertyra   rV   r   r   r   r   rL   ‡   s    
rL   c                   @   rO   )
zReplayableSession.Playerc                 C   s
   || _ d S r   )rP   )r   rJ   r   r   r   rK   ¶   s   
z!ReplayableSession.Player.__init__c                 O   s&   t  | d¡}| ¡ }|tju r| S |S ©NrP   )rU   rV   Úpopleftr   r]   )r   r^   r   rJ   r_   r   r   r   r`   ¹   s
   
z!ReplayableSession.Player.__call__c                 C   r+   r   r   r,   r   r   r   ra   Á   s   z%ReplayableSession.Player._sqla_unwrapc                 C   sZ   zt  | |¡W S  ty   Y nw t  | d¡}| ¡ }|tju r"| S |tju r+t|ƒ‚|S rg   )rU   rV   rb   rh   r   r]   rc   )r   rd   rJ   r_   r   r   r   rV   Å   s   ÿ

z)ReplayableSession.Player.__getattribute__Nre   r   r   r   r   rN   µ   s    
rN   N)r/   r0   r1   Ú__doc__rU   r]   rc   r
   Úpy2kÚsetÚdirr:   Ú
differencer[   ÚunionÚ__builtins__ÚvaluesrK   r   r   rL   rN   r   r   r   r   r   E   sF    ÿþÿþþÿþÿþÿò.r   )Úcollectionsr   r2   r:   Ú r   r   r   r   r	   r
   Úormr   ÚTestBaser   rU   r   r   r   r   r   Ú<module>   s    7