o
    [h                     @   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   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/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   Zuse_native_hstore)ctxc                      s      S r   )playerr   )r   r   r   r   )   s   z1ReplayFixtureTest.test_invocation.<locals>.player)ReplayableSessionr   dbpoolZ_creatorr   urlr	   metadataenginer   sessionsetup_engine
_run_stepsr   teardown_engineZdisposer   Z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   r5   r6   r7   r   r   r   r:   U       )FunctionTypeBuiltinFunctionType
MethodTypeBuiltinMethodType
LambdaTypeZUnboundMethodTypec                 C   r0   r1   r3   r7   r   r   r   r:   d   s    c                 C   s"   g | ]}t |tst|n|qS r   )
isinstancetyper7   r   r   r   r:   k   s    c                 C   r;   r   r<   r7   r   r   r   r:   q   r=   )r>   r?   r@   rA   rB   c                 C   s   t  | _d S r   )r   bufferr(   r   r   r   __init__~   r   zReplayableSession.__init__c                 C   s   |  | j|S r   )RecorderrE   )r   baser   r   r   r      s   zReplayableSession.recorderc                 C   s   |  | jS r   )PlayerrE   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   rE   subjectr   r   r   rF      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__r8   xr(   r   r   r:          
z7ReplayableSession.Recorder.__call__.<locals>.<listcomp>rL   rK   )rD   r   NativesappendCallable)r   argsr   rM   rE   resultr   r(   r   __call__   s   


z#ReplayableSession.Recorder.__call__c                 C   s   | j S r   )rL   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                    rN   r   rO   rR   r(   r   r   r:      rT   z?ReplayableSession.Recorder.__getattribute__.<locals>.<listcomp>rU   )	rP   rQ   AttributeErrorrD   rW   r   NoAttributerV   rX   )r   keyrM   rE   rZ   r   r(   r   rQ      s&   


z+ReplayableSession.Recorder.__getattribute__Nr+   r,   r-   rF   r[   propertyr\   rQ   r   r   r   r   rG      s    
rG   c                   @   rJ   )
zReplayableSession.Playerc                 C   s
   || _ d S r   )rK   )r   rE   r   r   r   rF      s   
z!ReplayableSession.Player.__init__c                 O   s&   t | d}| }|tju r| S |S NrK   )rP   rQ   popleftr   rX   )r   rY   r   rE   rZ   r   r   r   r[      s
   
z!ReplayableSession.Player.__call__c                 C   r'   r   r   r(   r   r   r   r\      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 rb   )rP   rQ   r]   rc   r   rX   r^   )r   r_   rE   rZ   r   r   r   rQ      s   

z)ReplayableSession.Player.__getattribute__Nr`   r   r   r   r   rI      s    
rI   N)r+   r,   r-   __doc__rP   rX   r^   r
   Zpy2ksetdirr6   
differencerV   union__builtins__valuesrF   r   r   rG   rI   r   r   r   r   r   E   sF    .r   )collectionsr   r.   r6    r   r   r   r   r	   r
   Zormr   ZTestBaser   rP   r   r   r   r   r   <module>   s    7