a
    •˜ëjÑ  ã                   @  s  d dl mZ d dlm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 G dd„ deƒZG dd„ dee	ejƒZG dd„ deƒZG dd„ dƒZeƒ Zdd„ Zdd„ Z dd „ Z!d!d"„ Z"dS )#é    )Úannotations)ÚAnyNé   )ÚTestBase)Ú
TablesTesté   )Ú
assertions)Úconfig)Úschema)ÚBasicEntity)ÚComparableEntity)Úadicté   )Úorm)ÚDeclarativeBase)Úevents)Úregistryc                   @  s   e Zd Zejdd„ ƒZdS )ÚORMTestc                 C  s   t ƒ S ©N)Úfixture_session©Úself© r   ú^/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/sqlalchemy/testing/fixtures/orm.pyr      s    zORMTest.fixture_sessionN)Ú__name__Ú
__module__Ú__qualname__r	   Úfixturer   r   r   r   r   r      s   r   c                   @  sÈ   e Zd ZU dZdZdZded< ejddd�ej	d	d
„ ƒƒZ
ejddd�dd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zed d!„ ƒZed"d#„ ƒZdS )$Ú
MappedTestÚonceÚeachNr   ÚclassesTÚclass)ÚautouseZscopec                 c  sT   |   ¡  | jd u rtƒ | _|  ¡  |  ¡  |  ¡  |  ¡  d V  |  ¡  |  ¡  d S r   )	Z_init_classr!   r   Ú_setup_once_tablesÚ_setup_once_classesÚ_setup_once_mappersZ_setup_once_insertsÚ_teardown_once_classZ_teardown_once_metadata_bind©Úclsr   r   r   Ú_setup_tables_test_class*   s    
z#MappedTest._setup_tables_test_classÚfunctionc                 c  sL   |   ¡  |  ¡  |  ¡  |  ¡  d V  tj ¡  |  ¡  |  ¡  |  	¡  d S r   )
Z_setup_each_tablesÚ_setup_each_classesÚ_setup_each_mappersZ_setup_each_insertsr   ÚsessionÚclose_all_sessionsÚ_teardown_each_mappersÚ_teardown_each_classesZ_teardown_each_tablesr   r   r   r   Ú_setup_tables_test_instance<   s    
z&MappedTest._setup_tables_test_instancec                 C  s   | j  ¡  d S r   )r!   Úclearr(   r   r   r   r'   J   s    zMappedTest._teardown_once_classc                 C  s   | j dkr|  | j¡ d S ©Nr   ©Úrun_setup_classesÚ_with_register_classesÚsetup_classesr(   r   r   r   r%   N   s    
zMappedTest._setup_once_classesc                 C  s*   | j dkr&|  ¡ \| _| _|  | j¡ d S r4   )Úrun_setup_mappersÚ_generate_registryÚmapper_registryÚmapperr7   Úsetup_mappersr(   r   r   r   r&   S   s    
zMappedTest._setup_once_mappersc                 C  s8   | j dkr|  ¡ \| j_| j_| j dkr4|  | j¡ d S )Nr   r    )r9   r:   Ú	__class__r;   r<   r7   r=   r   r   r   r   r-   Y   s    
ý
zMappedTest._setup_each_mappersc                 C  s   | j dkr|  | j¡ d S )Nr    r5   r   r   r   r   r,   c   s    
zMappedTest._setup_each_classesc                 C  s   t | jd�}||jfS )N)Úmetadata)r   Ú_tables_metadataZmap_imperatively)r)   Údeclr   r   r   r:   g   s    zMappedTest._generate_registryc                   sR   | j ‰ G ‡ fdd„dƒ}G dd„ dt|ƒ}G dd„ dt|ƒ}|| _|| _|ƒ  dS )z¥Run a setup method, framing the operation with a Base class
        that will catch new subclasses to be established within
        the "classes" registry.

        c                      s$   e Zd Zddœ‡ ‡fdd„Z‡  ZS )z0MappedTest._with_register_classes.<locals>._BaseÚNone©Úreturnc                   s$   ˆd usJ ‚| ˆ| j < tƒ  ¡  d S r   ©r   ÚsuperÚ__init_subclass__r(   ©r>   Úcls_registryr   r   rG   v   s    
zBMappedTest._with_register_classes.<locals>._Base.__init_subclass__)r   r   r   rG   Ú__classcell__r   ©rI   ©r>   r   Ú_Baseu   s   rM   c                   @  s   e Zd ZdS )z0MappedTest._with_register_classes.<locals>.BasicN©r   r   r   r   r   r   r   ÚBasic{   s   rO   c                   @  s   e Zd ZdS )z5MappedTest._with_register_classes.<locals>.ComparableNrN   r   r   r   r   Ú
Comparable~   s   rP   N)r!   r   r   rO   rP   )r)   ÚfnrM   rO   rP   r   rK   r   r7   l   s    z!MappedTest._with_register_classesc                 C  s   | j dkrt ¡  d S r4   )r9   r   Úclear_mappersr   r   r   r   r0   …   s    
z!MappedTest._teardown_each_mappersc                 C  s   | j dkr| j ¡  d S r4   )r6   r!   r3   r   r   r   r   r1   Œ   s    
z!MappedTest._teardown_each_classesc                 C  s   d S r   r   r(   r   r   r   r8   �   s    zMappedTest.setup_classesc                 C  s   d S r   r   r(   r   r   r   r=   ”   s    zMappedTest.setup_mappers)r   r   r   r6   r9   r!   Ú__annotations__r	   r   Zfixture_classmethodr*   r2   Úclassmethodr'   r%   r&   r-   r,   r:   r7   r0   r1   r8   r=   r   r   r   r   r   !   s4   








r   c                      s4   e Zd ZdZdZedd„ ƒZe‡ fdd„ƒZ‡  ZS )ÚDeclarativeMappedTestr   c                 C  s   d S r   r   r(   r   r   r   r$   �   s    z(DeclarativeMappedTest._setup_once_tablesc                   sN   ˆ j ‰G ‡ ‡fdd„dtƒ}|ˆ _tƒ  |¡ ˆ jjrJˆ jrJˆ j t	j
¡ d S )Nc                      sN   e Zd ZejZ”jZee	 
¡  e	 
d¡ddd¡iZddœ‡ ‡fdd„Z‡  ZS )	z?DeclarativeMappedTest._with_register_classes.<locals>._DeclBaseé2   ZmysqlZmariadbÚoraclerB   rC   c                   s,   ˆd usJ ‚| ˆ| j < tƒ jf i |¤Ž d S r   rE   )r)   ÚkwrH   r   r   rG   ®   s    
zQDeclarativeMappedTest._with_register_classes.<locals>._DeclBase.__init_subclass__)r   r   r   r
   ZTableZ__table_cls__r@   r?   ÚstrÚsaÚStringZwith_variantZtype_annotation_maprG   rJ   r   ©r)   rI   rL   r   Ú	_DeclBase¥   s   
ÿÿr]   )r!   r   ZDeclarativeBasicrF   r7   r@   ZtablesZrun_create_tablesZ
create_allr	   Údb)r)   rQ   r]   rL   r\   r   r7   ¡   s    z,DeclarativeMappedTest._with_register_classes)	r   r   r   r6   r9   rT   r$   r7   rJ   r   r   rL   r   rU   ™   s   
rU   c                   @  s    e Zd Zejdd�dd„ ƒZdS )ÚRemoveORMEventsGloballyT)r#   c                 c  s<   d V  t j ¡  t j ¡  t j ¡  t j ¡  t j ¡  d S r   )Ú
orm_eventsZMapperEventsÚ_clearZInstanceEventsZSessionEventsZInstrumentationEventsZQueryEventsr   r   r   r   Ú_remove_listeners¾   s    



z)RemoveORMEventsGlobally._remove_listenersN)r   r   r   r	   r   rb   r   r   r   r   r_   ½   s   
r_   c                  K  sF   |   dd¡ |   dd¡ |  dtj¡}tj|fi | ¤Ž}t |¡ |S )NZ	autoflushTZexpire_on_commitÚbind)Ú
setdefaultÚpopr	   r^   r   ÚSessionÚ_fixture_sessionsÚadd)rX   rc   Úsessr   r   r   r   Ë   s    
r   c                   C  s   t  ¡  t ¡  d S r   )r   r/   rg   r3   r   r   r   r   r/   Ö   s    r/   c                 C  s   t ƒ  t ¡  d S r   )r/   r   rR   r(   r   r   r   Ústop_test_class_inside_fixturesÜ   s    rj   c                   C  s   t r
tƒ  d S r   )rg   r/   r   r   r   r   Ú
after_testá   s    rk   )#Ú
__future__r   Útypingr   Z
sqlalchemyrZ   Úbaser   Zsqlr   Ú r   r	   r
   Úentitiesr   r   Úutilr   r   r   r   r`   r   r   ZAssertsExecutionResultsr   rU   r_   Úsetrg   r   r/   rj   rk   r   r   r   r   Ú<module>   s.   x$