o
    iC                     @   s6  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 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 )     )DecimalN   )testing   )fixtures)eq_)requirements)Column)Table   )Double)Float)Identity)Integer)literal)literal_column)Numeric)select)String)BYTEA)LargeBinary)UUID)Uuidc                   @   sJ   e Zd ZdZdZdZedd Zdd Zdd	 Z	d
d Z
ejdd ZdS )LastrowidTesteachT)implements_get_lastrowidautoincrement_insertc              	   C   sT   t d|tdtdddtdtddd t d	|tdtddd
tdtddd d S )N
autoinc_pkidTprimary_keytest_needs_autoincrementdata2   F)implicit_returning	manual_pkr    autoincrementr
   r	   r   r   clsmetadata r,   d/var/www/html/LicenciasMIG/venv/lib/python3.10/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   dialectdefault_sequence_baseselftableconnrowr,   r,   r-   _assert_round_trip6      z LastrowidTest._assert_round_tripc                 C   .   | | jj tdd | | jj| d S Nr1   r"   r3   tablesr   insertdictr<   r8   
connectionr,   r,   r-   test_autoincrement_on_insert@      z*LastrowidTest.test_autoincrement_on_insertc                 C   B   | | jj tdd}|t| jjjj}t	|j
|f d S r?   r3   rB   r   rC   rD   scalarr   cr   r   inserted_primary_keyr8   rF   rpkr,   r,   r-   test_last_inserted_idF   
   z#LastrowidTest.test_last_inserted_idc                 C   sD   | | jj tdd}|j}|t| jjjj	}t
|| d S r?   )r3   rB   r   rC   rD   	lastrowidrK   r   rL   r   r   )r8   rF   rO   rS   rP   r,   r,   r-   test_native_lastrowid_autoincM   s   z+LastrowidTest.test_native_lastrowid_autoincN)__name__
__module____qualname__run_deletes__backend____requires__classmethodr.   r<   rG   rQ   r   dbapi_lastrowidrT   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.   [   s8   z InsertBehaviorTest.define_tablesc                 C   sV   | | jj tdd}|jsJ |jrJ |jsJ |jr'|	 d u s)J d S d S r?   )
r3   rB   r   rC   rD   _soft_closedclosed	is_insertreturns_rowsfetchoner8   rF   rO   r,   r,   r-   test_autoclose_on_insertz   s   


z+InsertBehaviorTest.test_autoclose_on_insertc                 C   sh   | | jj  tdd}|jsJ |jrJ |jsJ |j	s#J t
| d  t
| dg d S )Nr1   r@   r   )r3   rB   r   rC   return_defaultsrD   re   rf   rg   rh   r   ri   keysrj   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 )Nr   r3   rB   r   rC   re   rf   r   whererL   r   r   lenallrj   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   ro   rj   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 )Nr   data1r   r"   r   data2r   data3r@   Nrw   rx   )rB   r%   r   r3   rC   rD   from_selectr   rL   r"   rp   in_r   rM   order_byfetchallr8   rF   	src_table
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 )Nr@   rw   rx   ry   )rB   r%   r   r3   rC   r|   r   rL   r"   rp   r}   r   rM   r~   r   r   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 )
Nr   ru   rv   r   rw   r   rx   r`   ))ru   rz   rz   r{   r{   )rB   r%   r3   rC   rD   inliner|   r   rL   r   r"   rp   r}   r   r~   r   r8   rF   r9   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 )
Nr   ru   rv   r   rw   r   rx   r`   ))r   ru   r`      )r   rw   r`   r   )   rw   r`   r   )r   rx   r`   r   )   rx   r`   r   )rB   r^   r3   rC   rD   r   r|   r   rL   r   r"   rp   r}   r   r~   r   r   r,   r,   r-   %test_insert_from_select_with_defaults  s2   


	z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rU   rV   rW   rX   rY   r[   r.   r   r   rk   insert_returningrn   empty_insertsrs   empty_inserts_executemanyrt   insert_from_selectr   r   r   r   r,   r,   r,   r-   r]   W   s*    







r]   c                   @   s  e Zd ZdZdZdZdd Zedd Ze	j
dd	 Zd
d Zdd Zdd Ze	jdd Zeje ddfedddejjfe ddfedddejjfeddddddejjfeddddeddfddedddgedddgdd  Zejd!edd"e fd#eddd$ee fd%edd"e ejj fd&e! e ejj fd'e" d(fd)e" d*fd+e# d*e$d,fd-d.d/	edddgedddgejj%d0d1 Z&d2S )3ReturningTestr   )r   r   Tc                 C   r/   r0   r2   r7   r,   r,   r-   r<   ;  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.   E  s   zReturningTest.define_tablesc                 C   T   | j j}|| |jjtdd}| d }|	t
|jj}t|| d S Nr1   r@   r   rB   r   r3   rC   	returningrL   r   rD   r4   rK   r   r   r8   rF   r9   rO   rP   
fetched_pkr,   r,   r-   %test_explicit_returning_pk_autocommitP  s   z3ReturningTest.test_explicit_returning_pk_autocommitc                 C   r   r   r   r   r,   r,   r-   (test_explicit_returning_pk_no_autocommitZ  s   z6ReturningTest.test_explicit_returning_pk_no_autocommitc                 C   r>   r?   rA   rE   r,   r,   r-   /test_autoincrement_on_insert_implicit_returningd  rH   z=ReturningTest.test_autoincrement_on_insert_implicit_returningc                 C   rI   r?   rJ   rN   r,   r,   r-   (test_last_inserted_id_implicit_returningj  rR   z6ReturningTest.test_last_inserted_id_implicit_returningc              	   C   sp   | | jj | jjjjddiddiddiddiddig}| }| t| jjjj}t	||  d S )Nr"   d1d2d3d4d5)
r3   rB   r   rC   r   rL   r   rr   r   r   )r8   rF   rO   rallpksr,   r,   r-   test_insertmanyvalues_returningq  s   
z-ReturningTest.test_insertmanyvalues_returninggxXM|Z!@5   g_Q!@Fr         )	precisionscale	asdecimalz	8.5514716ztype_,value,do_rounding)argnamessort_by_parameter_ordermultiple_rowsc              	      s  t d|tdtt ddtd|}|| || j|jj	|jj
t|d|r4 fddtd	D nd i}	|rAtd
d}
ntd
d}
|rptdd |	D  fdd|
D  tdd |t|jj
D t dh dS tt|	 fdd|
D  tt|t|jj
 h dS )zvtest #9701.

        this tests insertmanyvalues as well as decimal / floating point
        RETURNING types

        f_tr   Tr    valuer   c                       g | ]}d  iqS r   r,   .0ir   r,   r-   
<listcomp>      z6ReturningTest.test_insert_w_floats.<locals>.<listcomp>
   r      r   c                 S   s   h | ]\}}|t |d fqS r`   round)r   id_val_r,   r,   r-   	<setcomp>  s    z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>c                    s   h | ]	}|t  d fqS r   r   r   r   r   r,   r-   r     s    c                 S   s   h | ]}t |d qS r   r   )r   r   r,   r,   r-   r     s    r`   c                       h | ]}| fqS r,   r,   r   r   r,   r-   r     r   N)r
   r	   r   r   creater3   rC   r   rL   r   r   boolranger   scalarsr   r   set)r8   rF   r+   r   rd   r   do_roundingr   tr   i_ranger,   r   r-   test_insert_w_floats  sN   /




z"ReturningTest.test_insert_w_floatsnon_native_uuid)native_uuidnon_native_uuid_str)as_uuidr   generic_native_uuidr   LargeBinary1s   this is binaryLargeBinary2s   7zPG BYTEA
postgresqlztype_,valueiaa)r   r   c           
   	      s   t d|tdtt ddtd|}|| || j|jj	|jj
t|d|r4 fddtd	D nd i}|rAtd
d}	ntd
d}	tt| fdd|	D  tt|t|jj
 h dS )a  test #9739, #9808 (similar to #9701).

        this tests insertmanyvalues in conjunction with various datatypes.

        These tests are particularly for the asyncpg driver which needs
        most types to be explicitly cast for the new IMV format

        d_tr   Tr   r   r   c                    r   r   r,   r   r   r,   r-   r   /  r   z>ReturningTest.test_imv_returning_datatypes.<locals>.<listcomp>r   r   r   r   c                    r   r,   r,   r   r   r,   r-   r   ;  r   z=ReturningTest.test_imv_returning_datatypes.<locals>.<setcomp>N)r
   r	   r   r   r   r3   rC   r   rL   r   r   r   r   r   r   r   r   )
r8   rF   r+   r   rd   r   r   r   r   r   r,   r   r-   test_imv_returning_datatypes  s8   0

z*ReturningTest.test_imv_returning_datatypesN)'rU   rV   rW   run_create_tablesrZ   rY   r<   r[   r.   r   fetch_rows_post_commitr   r   r   r   insert_executemany_returningr   r   combinationsr   requires-float_or_double_precision_behaves_genericallyr   r   literal_float_coercionr   	variationr   r   uuiduuid4struuid_data_typer   r   r   only_onr   r   r,   r,   r,   r-   r   6  s    



	



M


r   )r   r]   r   )!decimalr   r    r   r   
assertionsr   configr   schemar	   r
   r   r   r   r   r   r   r   r   r   dialects.postgresqlr   typesr   r   r   
TablesTestr   r]   r   __all__r,   r,   r,   r-   <module>   s8   < `  