o
    Rc,                     @   s   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jZG dd dejZG dd dejZdZdS )   )config)engines)fixtures)eq_)requirements)Column)Table   )Integer)literal)literal_column)select)Stringc                   @   sR   e Zd ZdZdZdZddiZedd Zdd	 Z	d
d Z
dd Zejdd ZdS )LastrowidTesteachT)Zimplements_get_lastrowidautoincrement_insertimplicit_returningFc              	   C   sL   t d|tdtdddtdtd t d|tdtddd	tdtd d S )
N
autoinc_pkidTprimary_keyZtest_needs_autoincrementdata2   	manual_pkFr   Zautoincrementr   r   r
   r   clsmetadata r   FD:\Flask\env\Lib\site-packages\sqlalchemy/testing/suite/test_insert.pydefine_tables   s   	zLastrowidTest.define_tablesc                 C   (   | |  }t||jjdf d S N	some dataexecuter   firstr   dialectZdefault_sequence_baseselftableconnrowr   r   r    _assert_round_trip*      z LastrowidTest._assert_round_tripc                 C   .   | | jj tdd | | jj| d S Nr$   r   r&   tablesr   insertdictr.   r*   
connectionr   r   r    test_autoincrement_on_insert4      z*LastrowidTest.test_autoincrement_on_insertc                 C   B   | | jj tdd}|t| jjjj}t	|j
|f d S r1   r&   r4   r   r5   r6   scalarr   cr   r   inserted_primary_keyr*   r8   rpkr   r   r    test_last_inserted_id;   
   z#LastrowidTest.test_last_inserted_idc                 C   sD   | | jj tdd}|j}|t| jjjj	}t
|| d S r1   )r&   r4   r   r5   r6   	lastrowidr=   r   r>   r   r   )r*   r8   rA   rE   rB   r   r   r    test_native_lastrowid_autoincC   s   z+LastrowidTest.test_native_lastrowid_autoincN)__name__
__module____qualname__run_deletes__backend____requires____engine_options__classmethodr!   r.   r9   rC   r   Zdbapi_lastrowidrF   r   r   r   r    r      s    

r   c                   @   s   e Zd ZdZdZedd Zejdd Z	ej
dd Zejd	d
 Zejdd Zejdd Zejdd Zejdd Zejdd ZdS )InsertBehaviorTestr   Tc                 C   s   t d|tdtdddtdtd t d|tdtddd	tdtd t d
|tdtdddtdtdtdtddtdttdtdtd d d S )Nr   r   Tr   r   r   r   Fr   includes_defaultsx   )defaulty2)type_r   )r   r   r
   r   r   r   r   r   r   r    r!   Q   s8   z InsertBehaviorTest.define_tablesc                 C   s   t jjrtjddid}ntj}| }|| j	j
 tdd}W d    n1 s,w   Y  |js6J |jr;J |js@J |jrK| d u sMJ d S d S )Nr   F)optionsr$   r2   )r   	returningenabledr   Ztesting_enginer   dbbeginr&   r4   r   r5   r6   _soft_closedclosed	is_insertreturns_rowsfetchone)r*   Zenginer,   rA   r   r   r    test_autoclose_on_insertp   s   



z+InsertBehaviorTest.test_autoclose_on_insertc                 C   sd   | | jj tdd}|jsJ |jrJ |jsJ |js!J t	|
 d  t	| dg d S )Nr$   r2   r   )r&   r4   r   r5   r6   r\   r]   r^   r_   r   r`   keysr*   r8   rA   r   r   r    +test_autoclose_on_insert_implicit_returning   s   



z>InsertBehaviorTest.test_autoclose_on_insert_implicit_returningc                 C   s`   | | jj }|jsJ |jrJ | | jj | jjjj	d k}t
t| d d S )N   r&   r4   r   r5   r\   r]   r   wherer>   r   r   lenallrc   r   r   r    test_empty_insert   s   

z$InsertBehaviorTest.test_empty_insertc                 C   sh   | | jj i i i g}|jsJ |jrJ | | jj | jjjj	d k}t
t| d d S )Nr	   rf   rc   r   r   r    test_empty_insert_multiple   s   

z-InsertBehaviorTest.test_empty_insert_multiplec                 C   s   | j j}| j j}|| tdddtdddtdddg || dt|jj	
|jj	ddg}t|jd	 |t|jj	|jj	}t| d
dg d S )Nre   data1r   r   r   data2r	   data3r2   Nrn   ro   )r4   r   r   r&   r5   r6   from_selectr   r>   r   rg   in_r   r?   order_byfetchallr*   r8   Z	src_tableZ
dest_tableresultr   r   r    test_insert_from_select_autoinc   s,   


		z2InsertBehaviorTest.test_insert_from_select_autoincc                 C   s|   | j j}| j j}|| dt|jj	|jj
ddg}t|jd |t|jj|jj}t| g  d S )Nr2   rn   ro   rp   )r4   r   r   r&   r5   rs   r   r>   r   rg   rt   r   r?   ru   rv   rw   r   r   r    'test_insert_from_select_autoinc_no_rows   s   z:InsertBehaviorTest.test_insert_from_select_autoinc_no_rowsc                 C   s   | j j}|| tdddtdddtdddg ||  dt|jj	d |jj
|jj
ddg t|t|jj
|jj
 g d	 d S )
Nre   rl   rm   r   rn   r	   ro   rR   ))rl   rq   rq   rr   rr   )r4   r   r&   r5   r6   inliners   r   r>   r   r   rg   rt   r   ru   rv   r*   r8   r+   r   r   r    test_insert_from_select   s2   


	z*InsertBehaviorTest.test_insert_from_selectc                 C   s   | j j}|| tdddtdddtdddg ||  dt|jj	d |jj
|jj
ddg t|t||jj
|jj	 g d	 d S )
Nre   rl   rm   r   rn   r	   ro   rR   ))re   rl   rR      )r   rn   rR   r~   )   rn   rR   r~   )r	   ro   rR   r~   )   ro   rR   r~   )r4   rP   r&   r5   r6   r{   rs   r   r>   r   r   rg   rt   r   ru   rv   r|   r   r   r    %test_insert_from_select_with_defaults  s2   


	z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rG   rH   rI   rJ   rK   rN   r!   r   r   ra   rX   rd   Zempty_insertsrj   Zempty_inserts_executemanyrk   Zinsert_from_selectry   rz   r}   r   r   r   r   r    rO   M   s*    







rO   c                   @   sZ   e Zd ZdZdZdZddiZdd Zedd Z	e
jd	d
 Zdd Zdd Zdd ZdS )ReturningTestr   )rX   r   Tr   c                 C   r"   r#   r%   r)   r   r   r    r.   7  r/   z ReturningTest._assert_round_tripc              	   C   s(   t d|tdtdddtdtd d S )Nr   r   Tr   r   r   r   r   r   r   r    r!   A  s   zReturningTest.define_tablesc                 C   T   | j j}|| |jjtdd}| d }|	t
|jj}t|| d S Nr$   r2       r4   r   r&   r5   rX   r>   r   r6   r'   r=   r   r   r*   r8   r+   rA   rB   Z
fetched_pkr   r   r    %test_explicit_returning_pk_autocommitL  s   z3ReturningTest.test_explicit_returning_pk_autocommitc                 C   r   r   r   r   r   r   r    (test_explicit_returning_pk_no_autocommitV  s   z6ReturningTest.test_explicit_returning_pk_no_autocommitc                 C   r0   r1   r3   r7   r   r   r    /test_autoincrement_on_insert_implicit_returning_  r:   z=ReturningTest.test_autoincrement_on_insert_implicit_returningc                 C   r;   r1   r<   r@   r   r   r    (test_last_inserted_id_implicit_returningf  rD   z6ReturningTest.test_last_inserted_id_implicit_returningN)rG   rH   rI   Zrun_create_tablesrL   rK   rM   r.   rN   r!   r   Zfetch_rows_post_commitr   r   r   r   r   r   r   r    r   0  s    



		r   )r   rO   r   N) r   r   r   Z
assertionsr   r   Zschemar   r   r
   r   r   r   r   Z
TablesTestr   rO   r   __all__r   r   r   r    <module>   s"    > d?