o
    E6dF                     @   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)Z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_keyZtest_needs_autoincrementdata2   F)Zimplicit_returning	manual_pkr   Zautoincrementr
   r	   r   r   clsmetadata r(   {C:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\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_trip6      z LastrowidTest._assert_round_tripc                 C   .   | | jj tdd | | jj| d S Nr-   r    r/   tablesr   insertdictr7   r3   
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:   r/   r=   r   r>   r?   scalarr   cr   r   inserted_primary_keyr3   rA   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:   )r/   r=   r   r>   r?   	lastrowidrF   r   rG   r   r   )r3   rA   rJ   rN   rK   r(   r(   r)   test_native_lastrowid_autoincM   s   z+LastrowidTest.test_native_lastrowid_autoincN)__name__
__module____qualname__run_deletes__backend____requires__classmethodr*   r7   rB   rL   r   Zdbapi_lastrowidrO   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:   )
r/   r=   r   r>   r?   _soft_closedclosed	is_insertreturns_rowsfetchoner3   rA   rJ   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 )Nr-   r;   r   )r/   r=   r   r>   Zreturn_defaultsr?   r_   r`   ra   rb   r   rc   keysrd   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   r/   r=   r   r>   r_   r`   r   whererG   r   r   lenallrd   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   rh   rd   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rp   rq   )r=   r"   r   r/   r>   r?   from_selectr   rG   r    ri   in_r   rH   order_byfetchallr3   rA   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 )Nr;   rp   rq   rr   )r=   r"   r   r/   r>   ru   r   rG   r    ri   rv   r   rH   rw   rx   ry   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   rn   ro   r   rp   r   rq   rZ   ))rn   rs   rs   rt   rt   )r=   r"   r/   r>   r?   inlineru   r   rG   r   r    ri   rv   r   rw   rx   r3   rA   r4   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   rn   ro   r   rp   r   rq   rZ   ))r   rn   rZ      )r   rp   rZ   r   )   rp   rZ   r   )r   rq   rZ   r   )   rq   rZ   r   )r=   rX   r/   r>   r?   r}   ru   r   rG   r   r    ri   rv   r   rw   rx   r~   r(   r(   r)   %test_insert_from_select_with_defaults  s2   


	z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rP   rQ   rR   rS   rT   rV   r*   r   r   re   insert_returningrg   Zempty_insertsrl   Zempty_inserts_executemanyrm   Zinsert_from_selectr{   r|   r   r   r(   r(   r(   r)   rW   W   s*    







rW   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+   r,   r.   r2   r(   r(   r)   r7   ;  r8   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 Nr-   r;   r   r=   r   r/   r>   	returningrG   r   r?   r0   rF   r   r   r3   rA   r4   rJ   rK   Z
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   r9   r:   r<   r@   r(   r(   r)   /test_autoincrement_on_insert_implicit_returningd  rC   z=ReturningTest.test_autoincrement_on_insert_implicit_returningc                 C   rD   r:   rE   rI   r(   r(   r)   (test_last_inserted_id_implicit_returningj  rM   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    Zd1Zd2Zd3Zd4Zd5)
r/   r=   r   r>   r   rG   r   rk   r   r   )r3   rA   rJ   ZrallZpksr(   r(   r)   test_insertmanyvalues_returningq  s   
z-ReturningTest.test_insertmanyvalues_returninggxXM|Z!@5   g_Q!@Fr         )	precisionscaleZ	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

        Z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 rZ   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    rZ   c                       h | ]}| fqS r(   r(   r   r   r(   r)   r     r   N)r
   r	   r   r   creater/   r>   r   rG   r   r   boolranger   scalarsr   r   set)r3   rA   r'   r   r^   r   Zdo_roundingr   trz   i_ranger(   r   r)   test_insert_w_floats  sN   /




z"ReturningTest.test_insert_w_floatsZnon_native_uuid)native_uuidZnon_native_uuid_str)Zas_uuidr   Zgeneric_native_uuidr   ZLargeBinary1s   this is binaryZLargeBinary2s   7zPG BYTEA
postgresqlztype_,valueZ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

        Z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   r/   r>   r   rG   r   r   r   r   r   r   r   r   )
r3   rA   r'   r   r^   r   r   r   rz   r   r(   r   r)   test_imv_returning_datatypes  s8   0

z*ReturningTest.test_imv_returning_datatypesN)'rP   rQ   rR   Zrun_create_tablesrU   rT   r7   rV   r*   r   Zfetch_rows_post_commitr   r   r   r   Zinsert_executemany_returningr   r   combinationsr   requiresZ-float_or_double_precision_behaves_genericallyr   r   Zliteral_float_coercionr   Z	variationr   r   uuiduuid4strZuuid_data_typer   r   r   Zonly_onr   r   r(   r(   r(   r)   r   6  s    



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