o
    E6d/                     @   s  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 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/Z0G d-d. d.ej,Z1G d/d0 d0ej,Z2G d1d2 d2ej,Z3G d3d4 d4ej,Z4G d5d6 d6eeej,Z5G d7d8 d8ej,Z6G d9d: d:ej,Z7G d;d< d<ej,Z8G d=d> d>ej,Z9G d?d@ d@ej,Z:G dAdB dBej,Z;G dCdD dDeej,Z<G dEdF dFej,Z=dS )G    N   )AssertsCompiledSQL)AssertsExecutionResults)config)fixtures)assert_raises)eq_)in_)	CursorSQL)Column)Table   )	bindparam)case)column)Computed)exists)false)
ForeignKey)func)Identity)Integer)literal)literal_column)null)select)String)table)testing)text)true)tuple_)	TupleType)union)values)DatabaseError)ProgrammingErrorc                   @   s@   e Zd ZdZedd Zedd Zdd Zej	j
dd	 Zd
S )CollateTestTc                 C   &   t d|tdtddtdtd d S )N
some_tableidTprimary_keydatad   r   r   r   r   clsmetadata r3   {C:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/testing/suite/test_select.pydefine_tables.      zCollateTest.define_tablesc                 C   s(   | | jj ddddddg d S )N   collate data1r*   r-   r   collate data2executetablesr)   insertr1   
connectionr3   r3   r4   insert_data7   s   
zCollateTest.insert_datac                 C   D   t j }t|| | W d    d S 1 sw   Y  d S Nr   dbconnectr   r<   fetchallselfr   resultconnr3   r3   r4   _assert_resultA      "zCollateTest._assert_resultc                 C   sB   t jt j}| t| jj| jjj	j
| ddg d S )N)r7   r8   )r   r:   )r   requiresZget_order_by_collationr   rL   r   r=   r)   order_bycr-   Zcollateasc)rI   Z	collationr3   r3   r4   test_collate_order_byE   s   z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr5   rA   rL   r   rN   Zorder_by_collationrR   r3   r3   r3   r4   r'   +   s    

	r'   c                   @   sl   e Zd ZdZdZedd Zedd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zejjdd ZdS )OrderByLabelTestzTest the dialect sends appropriate ORDER BY expressions when
    labels are used.

    This essentially exercises the "supports_simple_order_by_label"
    setting.

    Tc                 C   sB   t d|tdtddtdttdttdtdtd	td d S )
Nr)   r*   Tr+   xyq2   pr/   r0   r3   r3   r4   r5   \   s   zOrderByLabelTest.define_tablesc                 C   sB   | | jj ddddddddddddddd	d
ddg d S )Nr7   r   q1Zp3)r*   rY   rZ   r[   r]   r   q2p2   Zq3p1r;   r?   r3   r3   r4   rA   h   s   
zOrderByLabelTest.insert_datac                 C   rB   rC   rD   rH   r3   r3   r4   rL   s   rM   zOrderByLabelTest._assert_resultc                 C   s4   | j j}|jjd}| t||g d d S )Nlxr7   r   r   )r=   r)   rP   rY   labelrL   r   rO   rI   r   rc   r3   r3   r4   
test_plainw   s   zOrderByLabelTest.test_plainc                 C   s<   | j j}|jj|jj d}| t||g d d S )Nrc   )rg         )	r=   r)   rP   rY   rZ   rh   rL   r   rO   ri   r3   r3   r4   test_composed_int|   s   z"OrderByLabelTest.test_composed_intc                 C   s`   | j j}|jj|jj d}t|jj|jj	 d}| 
t|||| g d d S )Nrc   ly))r   Zq1p3)rl   Zq2p2)rn   Zq3p1)r=   r)   rP   rY   rZ   rh   r   lowerr[   r]   rL   r   rO   desc)rI   r   rc   rp   r3   r3   r4   test_composed_multiple   s   z'OrderByLabelTest.test_composed_multiplec                 C   s8   | j j}|jjd}| t|| g d d S )Nrc   )rg   rf   re   )	r=   r)   rP   rY   rh   rL   r   rO   rr   ri   r3   r3   r4   test_plain_desc   s   "z OrderByLabelTest.test_plain_descc                 C   s@   | j j}|jj|jj d}| t||	 g d d S )Nrc   )rm   rk   rg   )
r=   r)   rP   rY   rZ   rh   rL   r   rO   rr   ri   r3   r3   r4   test_composed_int_desc   s   "z'OrderByLabelTest.test_composed_int_descc                 C   sR   | j j}|jj|jj d}tt|jj	|
||}| |g d d S )Nrc   ))r7   r   )r7   rl   )r7   rn   )r=   r)   rP   rY   rZ   rh   r   r   countr*   Zgroup_byrO   rL   )rI   r   exprstmtr3   r3   r4   test_group_by_composed   s
   z'OrderByLabelTest.test_group_by_composedN)rS   rT   rU   __doc__rV   rW   r5   rA   rL   rj   ro   rs   rt   ru   r   rN   Zgroup_by_complex_expressionry   r3   r3   r3   r4   rX   Q   s    


	rX   c                   @   s   e Zd ZdZdZdd ZdS )ValuesExpressionTest)Ztable_value_constructorTc                 C   sD   t tdttdtddg d}t|t| g d d S )Nr*   nameZ	my_values)r|   ))r7   Zname1)r   Zname2)r   Zname3)	r$   r   r   r   r-   r   r<   r   all)rI   r@   Z
value_exprr3   r3   r4   test_tuples   s   
z ValuesExpressionTest.test_tuplesN)rS   rT   rU   __requires__rV   r~   r3   r3   r3   r4   r{      s    r{   c                   @   s4  e Zd ZdZedd Zedd Z	dHdd	ZdId
dZdd Z	dd Z
ejjdd Zejjdd Zejg dg dg dddejjdd Zejjdd Zejjdd Zejjdd  Zejjd!d" Zejjd#d$ Zejjd%d& Zejjd'd( Zejjd)d* Zejjd+d, Zejjd-d. Zejjd/d0 Z ejjd1d2 Z!ejjejj"d3d4 Z#ejjd5d6 Z$ejjd7d8 Z%ejj&d9d: Z'ejj&ejj(d;d< Z)ejj&ejj(d=d> Z*ejj+d?d@ Z,ejj+ejj(dAdB Z-ejj&ejj+dCdD Z.ejj&ejj+ejj(dEdF Z/dGS )JFetchLimitOffsetTestTc                 C   *   t d|tdtddtdttdt d S Nr)   r*   Tr+   rY   rZ   r   r   r   r0   r3   r3   r4   r5         z"FetchLimitOffsetTest.define_tablesc                 C   sJ   | | jj ddddddddddddddddddddg d S )Nr7   r   r*   rY   rZ   r   ra   rl      r;   r?   r3   r3   r4   rA      s   





z FetchLimitOffsetTest.insert_datar3   Fc                 C   sV   |r| || }tt|t| tt|t| d S t| || | d S rC   )r<   rG   r   lenset)rI   r@   r   rJ   paramsset_Z	query_resr3   r3   r4   rL      s
   z#FetchLimitOffsetTest._assert_resultc                 C   F   t j }t||| | W d    d S 1 sw   Y  d S rC   )r   rE   rF   r   Zexec_driver_sqlrG   rI   r   rJ   r   rK   r3   r3   r4   _assert_result_str      "z'FetchLimitOffsetTest._assert_result_strc                 C   sN   | j j}t||jj}| ||dddg | ||dg d d S Nr   r7   r7   r   r   r   r   r   r   r   r   r   ra   )r=   r)   r   rO   rP   r*   rL   limit)rI   r@   r   rx   r3   r3   r4   test_simple_limit   s   z&FetchLimitOffsetTest.test_simple_limitc                 C   sL   | j j}t|jjd }tt|t|  }| 	||dg d S )Nr7   re   )
r=   r)   r   rP   r*   r   Zscalar_subqueryr#   subqueryrL   )rI   r@   r   rx   ur3   r3   r4    test_limit_render_multiple_times   s   z5FetchLimitOffsetTest.test_limit_render_multiple_timesc                 C   sX   | j j}| |t||jjdddg | |t||jjdg d d S r   r=   r)   rL   r   rO   rP   r*   fetchrI   r@   r   r3   r3   r4   test_simple_fetch      z&FetchLimitOffsetTest.test_simple_fetchc                 C   sX   | j j}| |t||jjdg d | |t||jjdddg d S )Nr   r   ra   ra   rl   rl   ra   r   r   r   r   r=   r)   rL   r   rO   rP   r*   offsetr   r3   r3   r4   test_simple_offset  r   z'FetchLimitOffsetTest.test_simple_offset)r   r   r   r7   r   r   )r   r   r   )r   r7   r   r   cases)argnamesc                 C   sf   | j j}|ji d}g d}|D ] \}}||||  }| |t||jj|	|| qd S )N)Zcompiled_cacher   r   r   r   r   )
r=   r)   Zexecution_optionsrL   r   rO   rP   r*   r   r   )rI   r@   r   r   Zassert_datar   r   expectedr3   r3   r4   test_simple_limit_offset  s   z-FetchLimitOffsetTest.test_simple_limit_offsetc                 C   sd   | j j}| |t||jjddddg | |t||jjddg d d S )Nr   r7   r   r   r   r   	r=   r)   rL   r   rO   rP   r*   r   r   r   r3   r3   r4   test_simple_fetch_offset$  s   z-FetchLimitOffsetTest.test_simple_fetch_offsetc                 C   s,   | j j}| j|t|dg ddd d S )N
   r   Tr   )r=   r)   rL   r   r   r   r3   r3   r4   test_fetch_offset_no_order3  s   
z/FetchLimitOffsetTest.test_fetch_offset_no_orderc                 C   sX   | j j}| |t||jjdg d | |t||jjdg d d S )Nr   r   r7   r   r   r   r   r   r   r3   r3   r4   test_simple_offset_zero=  s   z,FetchLimitOffsetTest.test_simple_offset_zeroc                 C   X   | j j}t||jjdd}|jt	j
jddid}t|}| |ddg dS 	z7test that 'literal binds' mode works - no bound params.r   r7   literal_bindsT)dialectcompile_kwargsr   r   N)r=   r)   r   rO   rP   r*   r   r   compiler   rE   r   strr   rI   r   rx   sqlr3   r3   r4   test_limit_offset_nobindsL     z.FetchLimitOffsetTest.test_limit_offset_nobindsc                 C   r   r   )r=   r)   r   rO   rP   r*   r   r   r   r   rE   r   r   r   r   r3   r3   r4   test_fetch_offset_nobindsY  r   z.FetchLimitOffsetTest.test_fetch_offset_nobindsc                 C   sp   | j j}| j|t||jjtdddgddid | j|t||jjtdg dddid d S )Nlr   r   r   r   r   r   )	r=   r)   rL   r   rO   rP   r*   r   r   r   r3   r3   r4   test_bound_limitf     
z%FetchLimitOffsetTest.test_bound_limitc                 C   sp   | j j}| j|t||jjtdg dddid | j|t||jjtdg dddid d S )Nor   r   r   r   r7   )	r=   r)   rL   r   rO   rP   r*   r   r   r   r3   r3   r4   test_bound_offsetw  r   z&FetchLimitOffsetTest.test_bound_offsetc                 C      | j j}| j|t||jjtd	tdddgdddd | j|t||jjtd	tdg d	d
ddd d S )Nr   r   r   r   r   r7   )r   r   r   r   r   )
r=   r)   rL   r   rO   rP   r*   r   r   r   r   r3   r3   r4   test_bound_limit_offset  &   







z,FetchLimitOffsetTest.test_bound_limit_offsetc                 C   r   )Nfr   r   r   r   r7   )r   r   r   r   r   )
r=   r)   rL   r   rO   rP   r*   r   r   r   r   r3   r3   r4   test_bound_fetch_offset  r   z,FetchLimitOffsetTest.test_bound_fetch_offsetc                 C   s>   | j j}| |t||jjtdtd ddg d S )N12r   r   )	r=   r)   rL   r   rO   rP   r*   r   r   r   r3   r3   r4   test_expr_offset     
z%FetchLimitOffsetTest.test_expr_offsetc                 C   s>   | j j}| |t||jjtdtd g d d S )Nr   r   r   )	r=   r)   rL   r   rO   rP   r*   r   r   r   r3   r3   r4   test_expr_limit  r   z$FetchLimitOffsetTest.test_expr_limitc                 C   P   | j j}| |t||jjtdtd 	tdtd ddg d S Nr   r   r   
r=   r)   rL   r   rO   rP   r*   r   r   r   r   r3   r3   r4   test_expr_limit_offset  s   
z+FetchLimitOffsetTest.test_expr_limit_offsetc                 C   r   r   )
r=   r)   rL   r   rO   rP   r*   r   r   r   r   r3   r3   r4   test_expr_fetch_offset  s   
z+FetchLimitOffsetTest.test_expr_fetch_offsetc                 C   s|   | j j}| |t||jjdt	dt	d ddg | |t||jjdt	dt	d g d d S )Nr   r   r   r   r   r   )
r=   r)   rL   r   rO   rP   r*   r   r   r   r   r3   r3   r4   test_simple_limit_expr_offset  s"   
	
z2FetchLimitOffsetTest.test_simple_limit_expr_offsetc                 C   s|   | j j}| |t||jjtdtd 	dddg | |t||jjtdtd 	dddg d S )Nr   r   r   r   r7   r   r   r   r3   r3   r4   test_expr_limit_simple_offset  s"   
	
z2FetchLimitOffsetTest.test_expr_limit_simple_offsetc                 C   sp   | j j}| j|t||jj jdddddgdd | j|t||jj jdddg ddd d S )	Nr7   T	with_tiesr   r   r   r   r   	r=   r)   rL   r   rO   rP   rY   rr   r   r   r3   r3   r4   test_simple_fetch_ties  s   
z+FetchLimitOffsetTest.test_simple_fetch_tiesc                 C   sX   | j j}|t||jjjdddd	 }t
|d d t
t|h d d S )Nr   Tr   r   r      r   r   r   r=   r)   r<   r   rO   rP   rY   r   r   rG   r   r   rI   r@   r   far3   r3   r4   test_fetch_offset_ties   s   
z+FetchLimitOffsetTest.test_fetch_offset_tiesc                 C   sl   | j j}| |t||jjjddddddg | |t||jjjdddddd	g d S )
Nr   Tr   r7   r   r   r   r   r   )	r=   r)   rL   r   rO   rP   rY   r   r   r   r3   r3   r4   #test_fetch_offset_ties_exact_number-  s&   
	
z8FetchLimitOffsetTest.test_fetch_offset_ties_exact_numberc                 C   s4   | j j}| |t||jjjddddg d S )N   Tpercentr   r   r   r3   r3   r4   test_simple_fetch_percentC  s   z.FetchLimitOffsetTest.test_simple_fetch_percentc                 C   s<   | j j}| |t||jjjddddddg d S )N(   Tr   r7   r   r   r   r   r3   r3   r4   test_fetch_offset_percentL  s   
z.FetchLimitOffsetTest.test_fetch_offset_percentc                 C   s@   | j j}| j|t||jj jddddddgdd d S )Nr   Tr   r   r   r   r   r   r   r3   r3   r4   test_simple_fetch_percent_tiesY  s   
z3FetchLimitOffsetTest.test_simple_fetch_percent_tiesc                 C   sZ   | j j}|t||jjjddddd	 }t
|d d t
t|h d d S )Nr   Tr   r   r   r   r   r   r   r3   r3   r4   test_fetch_offset_percent_tiesf  s   
z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r3   Fr3   )0rS   rT   rU   rV   rW   r5   rA   rL   r   r   r   r   rN   Zfetch_firstr   r   r   combinationsr   r   Zfetch_no_order_byr   r   r   r   Zbound_limit_offsetr   r   r   r   Zsql_expression_limit_offsetr   r   r   Zfetch_expressionr   r   r   Z
fetch_tiesr   Zfetch_offset_with_optionsr   r   Zfetch_percentr   r   r   r   r3   r3   r3   r4   r      s    
	






	















r   c                   @   sH   e Zd ZdZdZdZedd Zedd Zdd	 Z	d
d Z
dd ZdS )SameNamedSchemaTableTestztests for #7471T)Zschemasc              	   C   sB   t d|tdtddtjd t d|tdtddtdtdd d S )	Nr)   r*   Tr+   )schemasome_table_idFZnullable)r   r   r   r   test_schemar0   r3   r3   r4   r5   |  s    z&SameNamedSchemaTableTest.define_tablesc                 C   sD   |  ddtj \}}|| ddi || ddd d S )Nr)   %s.some_tabler*   r7   )r*   r   )r=   r   r   r<   r>   )r1   r@   r)   some_table_schemar3   r3   r4   rA     s
   
z$SameNamedSchemaTableTest.insert_datac              	   C   sJ   |  ddtj \}}t|t|||||jj|jj	k
 d d S )Nr)   r   r7   r7   r7   )r=   r   r   r   r<   r   	join_fromrP   r   r*   firstrI   r@   r)   r   r3   r3   r4   test_simple_join_both_tables  s   

z5SameNamedSchemaTableTest.test_simple_join_both_tablesc              	   C   sV   |  ddtj \}}t|t||||jj|jj	k
|jj	dk d d S )Nr)   r   r7   r7   r7   )r=   r   r   r   r<   r   r   rP   r   r*   wherer   r   r3   r3   r4   !test_simple_join_whereclause_only  s    
z:SameNamedSchemaTableTest.test_simple_join_whereclause_onlyc              	   C   s   |  ddtj \}}t||||jj|jjk|jjdk	 }t
|t||jj|||jj|jjk|jjdk d d S )Nr)   r   r7   r   )r=   r   r   r   r   rP   r   r*   r   r   r   r<   r   )rI   r@   r)   r   Zsubqr3   r3   r4   test_subquery  s2   
z&SameNamedSchemaTableTest.test_subqueryN)rS   rT   rU   rz   rV   r   rW   r5   rA   r   r   r   r3   r3   r3   r4   r   u  s    

r   c                   @   sZ   e Zd ZdZdddZedd Zedd Zd	d
 Zdd Z	dd Z
dd Zdd ZdS )JoinTestTr3   c                 C   r   rC   rD   r   r3   r3   r4   rL     r   zJoinTest._assert_resultc              	   C   s@   t d|tdtdd t d|tdtddtdtddd	 d S )
Nar*   Tr+   ba_idza.idFr   )r   r   r   r   r0   r3   r3   r4   r5     s   zJoinTest.define_tablesc              	   C   sj   | | jj ddiddiddiddiddig | | jj ddddddddddddg d S )Nr*   r7   r   r   ra   rl   )r*   r   )r<   r=   r   r>   r   r?   r3   r3   r4   rA     s   
 
zJoinTest.insert_datac                 C   J   |  dd\}}t|||||jj|jj}| |g d d S Nr   r   )r   )r7   r   r7   )r   ra   r   )r   rl   r   r=   r   select_fromjoinrO   rP   r*   rL   rI   r   r   rx   r3   r3   r4   test_inner_join_fk     &zJoinTest.test_inner_join_fkc              	   C   sd   |  dd\}}t||||t |jj|jj}| |dd t	
g dg dD  d S )Nr   r   c                 S   s    g | ]\\}\}}|||fqS r3   r3   ).0r   r   rP   r3   r3   r4   
<listcomp>  s    z1JoinTest.test_inner_join_true.<locals>.<listcomp>)re   rf   rg   ra   rk   )r   r   )ra   r   )rl   r   )r=   r   r  r  r    rO   rP   r*   rL   	itertoolsproductr  r3   r3   r4   test_inner_join_true  s   zJoinTest.test_inner_join_truec                 C   sJ   |  dd\}}t||||t |jj|jj}| |g  d S )Nr   r   )	r=   r   r  r  r   rO   rP   r*   rL   r  r3   r3   r4   test_inner_join_false  s   zJoinTest.test_inner_join_falsec                 C   sN   |  dd\}}t||||t |jj|jj}| |g d d S )Nr   r   ))r7   NN)r   NN)r   NN)ra   NN)rl   NN)	r=   r   r  Z	outerjoinr   rO   rP   r*   rL   r  r3   r3   r4   test_outer_join_false   s   zJoinTest.test_outer_join_falsec                 C   r   r  r  r  r3   r3   r4   test_outer_join_fk4  r  zJoinTest.test_outer_join_fkNr   )rS   rT   rU   rV   rL   rW   r5   rA   r  r  r  r  r  r3   r3   r3   r4   r     s    

	
r   c                   @   s   e Zd ZdZedd Zedd ZdddZd	d
 Zdd Z	e
jje
jjdd Ze
jjdd Zdd Ze
jjdd Zdd ZdS )CompoundSelectTestTc                 C   r   r   r   r0   r3   r3   r4   r5   ?  r   z CompoundSelectTest.define_tablesc              
   C   s@   | | jj ddddddddddddddddg d S )Nr7   r   r   r   ra   rl   r;   r?   r3   r3   r4   rA   I  s   




zCompoundSelectTest.insert_datar3   c                 C   r   rC   rD   r   r3   r3   r4   rL   U  r   z!CompoundSelectTest._assert_resultc                 C   s\   | j j}t||jjdk}t||jjdk}t||}| ||j	jddg d S Nr   r   r   r   )
r=   r)   r   r   rP   r*   r#   rL   rO   selected_columnsrI   r   s1s2u1r3   r3   r4   test_plain_unionY  s   
z#CompoundSelectTest.test_plain_unionc                 C   sd   | j j}t||jjdk}t||jjdk}t||  }| |	|j
jddg d S r  )r=   r)   r   r   rP   r*   r#   aliasrL   rO   r  r  r3   r3   r4   test_select_from_plain_unionc  s   z/CompoundSelectTest.test_select_from_plain_unionc                 C   s   | j j}t||jjdkd|jj}t||jjdkd|jj}t||d}| 	||j
jddg d S Nr   r7   r   r   r   )r=   r)   r   r   rP   r*   r   rO   r#   rL   r  r  r3   r3   r4   &test_limit_offset_selectable_in_unionsm  s   &&z9CompoundSelectTest.test_limit_offset_selectable_in_unionsc                 C   sv   | j j}t||jjdk|jj}t||jjdk|jj}t||d}| 	||j
jddg d S r  )r=   r)   r   r   rP   r*   rO   r#   r   rL   r  r  r3   r3   r4   "test_order_by_selectable_in_unionsy  s     z5CompoundSelectTest.test_order_by_selectable_in_unionsc                 C   sj   | j j}t||jjdk }t||jjdk }t||d}| 	|
|jjddg d S r  )r=   r)   r   r   rP   r*   distinctr#   r   rL   rO   r  r  r3   r3   r4   "test_distinct_selectable_in_unions  s   z5CompoundSelectTest.test_distinct_selectable_in_unionsc                 C   s   | j j}t||jjdkd|jj}t||jjdkd|jj}t||	 }| 
| d|jjddg d S r  )r=   r)   r   r   rP   r*   r   rO   r#   r  rL   r  r3   r3   r4   &test_limit_offset_in_unions_from_alias  s   &&z9CompoundSelectTest.test_limit_offset_in_unions_from_aliasc                 C   s   | j j}t||jjdkd|jj  }t||jjdkd|jj  }t	||d}| 
||jjddg d S r  )r=   r)   r   r   rP   r*   r   rO   r  r#   rL   r  r  r3   r3   r4   .test_limit_offset_aliased_selectable_in_unions  s&   
	
	zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsNr   )rS   rT   rU   rV   rW   r5   rA   rL   r  r  r   rN   Zorder_by_col_from_unionZ/parens_in_union_contained_select_w_limit_offsetr  Z0parens_in_union_contained_select_wo_limit_offsetr  r  r   r!  r3   r3   r3   r4   r  <  s$    
	








r  c                   @   sl   e Zd ZdZdZedd Zedd Zdd Zd	d
 Z	dd Z
dd Zejjdd Zejjdd ZdS )PostCompileParamsTestT)Zstandard_cursor_sqlc              
   C   6   t d|tdtddtdttdttdtd d S 	Nr)   r*   Tr+   rY   rZ   zr\   r/   r0   r3   r3   r4   r5        z#PostCompileParamsTest.define_tablesc                 C   H   | | jj dddddddddddddddddd	d
dg d S Nr7   r   z1)r*   rY   rZ   r%  r   z2ra   z3rl   z4r;   r?   r3   r3   r4   rA        
z!PostCompileParamsTest.insert_datac                 C   s<   | j j}t|jj|jjtdddk}| |di  d S )Nr[   Tliteral_executezKSELECT some_table.id FROM some_table WHERE some_table.x = __[POSTCOMPILE_q]	r=   r)   r   rP   r*   r   rY   r   assert_compilerI   r   rx   r3   r3   r4   test_compile  s   z"PostCompileParamsTest.test_compilec                 C   sB   | j j}t|jj|jjtddddk}| j|di dd d S )Nr[   r   Tr.  z<SELECT some_table.id FROM some_table WHERE some_table.x = 10)r   r0  r2  r3   r3   r4   test_compile_literal_binds  s   
z0PostCompileParamsTest.test_compile_literal_bindsc              	   C   s   | j j}t|jj|jjtdddk}|  &}t	j
 }||tdd W d    n1 s3w   Y  W d    n1 sBw   Y  |tdt	j
jjrRdni  d S )Nr[   Tr.  r   r[   z>SELECT some_table.id 
FROM some_table 
WHERE some_table.x = 10r3   )r=   r)   r   rP   r*   r   rY   r   sql_execution_asserterr   rE   rF   r<   dictassert_r
   r   
positionalrI   r   rx   ZasserterrK   r3   r3   r4   test_execute  s    
z"PostCompileParamsTest.test_executec              	   C   s   | j j}t|jj|jjtdddd}| 	 (}t
j }||tg dd W d    n1 s7w   Y  W d    n1 sFw   Y  |tdt
jjjrVdni  d S )Nr[   T	expandingr/  )rl   r   rn   r5  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r3   )r=   r)   r   rP   r*   r   rY   r	   r   r6  r   rE   rF   r<   r7  r8  r
   r   r9  r:  r3   r3   r4   +test_execute_expanding_plus_literal_execute   s    
zAPostCompileParamsTest.test_execute_expanding_plus_literal_executec              	   C      | j j}t|jjt|jj|jj	t
dddd}|  (}tj }||tddgd W d    n1 s<w   Y  W d    n1 sKw   Y  |tdtjjjr[dnd	 tjjjrdd
ni  d S )Nr[   Tr<  )rl   r   )      r5  zbSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.y) IN (%s(5, 10), (12, 18))VALUES  r3   )r=   r)   r   rP   r*   r   r!   rY   rZ   r	   r   r6  r   rE   rF   r<   r7  r8  r
   r   tuple_in_valuesr9  r:  r3   r3   r4   1test_execute_tuple_expanding_plus_literal_execute  (   
zGPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_executec              	   C   r?  )Nr[   Tr<  )rl   r)  )r@  r+  r5  zfSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.z) IN (%s(5, 'z1'), (12, 'z3'))rB  rC  r3   )r=   r)   r   rP   r*   r   r!   rY   r%  r	   r   r6  r   rE   rF   r<   r7  r8  r
   r   rD  r9  r:  r3   r3   r4   ?test_execute_tuple_expanding_plus_literal_heterogeneous_execute+  rF  zUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rS   rT   rU   rV   r   rW   r5   rA   r3  r4  r;  r>  r   rN   tuple_inrE  rG  r3   r3   r3   r4   r"    s    



r"  c                   @   sr  e Zd ZdZedd Zedd ZdDddZd	d
 Zdd Z	e
jjdd Ze
jjdd Ze
jjdd Ze
jjdd Zdd Zdd Zdd Zdd Zdd Zdd  Ze
jjd!d" Ze
jjd#d$ Ze
jjd%d& Ze
jjd'd( Ze
jjd)d* Ze
jjd+d, Ze
jjd-d. Zd/d0 Zd1d2 Z d3d4 Z!d5d6 Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&d?d@ Z'dAdB Z(dCS )EExpandingBoundInTestTc              
   C   r#  r$  r/   r0   r3   r3   r4   r5   G  r&  z"ExpandingBoundInTest.define_tablesc                 C   r'  r(  r;   r?   r3   r3   r4   rA   R  r-  z ExpandingBoundInTest.insert_datar3   c                 C   r   rC   rD   r   r3   r3   r4   rL   ^  r   z#ExpandingBoundInTest._assert_resultc                 C   s`   | j j}t|jj|jjtd|jj	td
|jj}| j|g g g dd d S )Nr[   r]   )r[   r]   r   )r=   r)   r   rP   r*   r   rY   r	   r   rZ   rO   rL   r2  r3   r3   r4   "test_multiple_empty_sets_bindparamb  s   

z7ExpandingBoundInTest.test_multiple_empty_sets_bindparamc                 C   sN   | j j}t|jj|jjg |jjg 	|jj}| 
|g  d S rC   )r=   r)   r   rP   r*   r   rY   r	   rZ   rO   rL   r2  r3   r3   r4   test_multiple_empty_sets_directn  s   

z4ExpandingBoundInTest.test_multiple_empty_sets_directc                 C   T   | j j}t|jjt|jj|jj	t
d|jj}| j|g dg id d S Nr[   r   r=   r)   r   rP   r*   r   r!   rY   r%  r	   r   rO   rL   r2  r3   r3   r4   )test_empty_heterogeneous_tuples_bindparamz     

z>ExpandingBoundInTest.test_empty_heterogeneous_tuples_bindparamc                    @    j j fdd}|g g  |g dg d |g g  d S )Nc                    @   t jjtjjjj| jj} 	|| d S rC   )
r   rP   r*   r   r!   rY   r%  r	   rO   rL   valr   rx   rI   r   r3   r4   go  
   

zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.go)r   r*  )r   r+  )ra   r,  rf   rg   r
  r=   r)   rI   rV  r3   rU  r4   &test_empty_heterogeneous_tuples_direct  
   
z;ExpandingBoundInTest.test_empty_heterogeneous_tuples_directc                 C   rL  rM  r=   r)   r   rP   r*   r   r!   rY   rZ   r	   r   rO   rL   r2  r3   r3   r4   'test_empty_homogeneous_tuples_bindparam  rP  z<ExpandingBoundInTest.test_empty_homogeneous_tuples_bindparamc                    rQ  )Nc                    rR  rC   )
r   rP   r*   r   r!   rY   rZ   r	   rO   rL   rS  rU  r3   r4   rV    rW  zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go))r7   r   r   r   r   ra   rd   rZ  r[  r3   rU  r4   $test_empty_homogeneous_tuples_direct  r]  z9ExpandingBoundInTest.test_empty_homogeneous_tuples_directc                 C   sR   | j j}t|jj|jjtd	|jj}| j
|g ddg did d S )Nr[   rY  r   r   ra   r   r=   r)   r   rP   r*   r   rY   r	   r   rO   rL   r2  r3   r3   r4   test_bound_in_scalar_bindparam  s   

 z3ExpandingBoundInTest.test_bound_in_scalar_bindparamc                 C   sF   | j j}t|jj|jjg d|jj}| 	|g d d S )Nrc  rY  
r=   r)   r   rP   r*   r   rY   r	   rO   rL   r2  r3   r3   r4   test_bound_in_scalar_direct  s   

z0ExpandingBoundInTest.test_bound_in_scalar_directc                 C   sV   | j j}t|jj|jjddg|jjg 	|jj}| 
|ddg d S )Nr   r   rf   rg   r=   r)   r   rP   r*   r   rY   r	   not_inrO   rL   r2  r3   r3   r4   !test_nonempty_in_plus_empty_notin  s   

z6ExpandingBoundInTest.test_nonempty_in_plus_empty_notinc                 C   sR   | j j}t|jj|jjg |jjddg	|jj}| 
|g  d S )Nr   r   rh  r2  r3   r3   r4   !test_empty_in_plus_notempty_notin  s   

z6ExpandingBoundInTest.test_empty_in_plus_notempty_notinc                 C   s8   t dtdtdd}| j|g ddg did dS )	ztest related to #7292.

        as a type is given to the bound param, there is no ambiguity
        to the type of element.

        3select id FROM some_table WHERE z IN :q ORDER BY idr[   Ttype_r=  rY  r*  r+  r,  r   N)r   
bindparamsr   r   rL   rI   rx   r3   r3   r4   test_typed_str_in  s   

z&ExpandingBoundInTest.test_typed_str_inc                 C   s6   t dtddd}| j|g ddg did dS )	ztest related to #7292.

        for untyped expression, we look at the types of elements.
        Test for Sequence to detect tuple in.  but not strings or bytes!
        as always....

        rl  r[   Tr=  rY  ro  r   Nr   rp  r   rL   rq  r3   r3   r4   test_untyped_str_in  s   	

z(ExpandingBoundInTest.test_untyped_str_inc                 C   \   | j j}t|jjt|jj|jj	t
d|jj}| j|g ddg did d S )Nr[   rY  r`  ra  )ra   rl   r   r^  r2  r3   r3   r4   !test_bound_in_two_tuple_bindparam  s   


z6ExpandingBoundInTest.test_bound_in_two_tuple_bindparamc                 C   P   | j j}t|jjt|jj|jj	g d
|jj}| |g d d S )Nrw  rY  )r=   r)   r   rP   r*   r   r!   rY   rZ   r	   rO   rL   r2  r3   r3   r4   test_bound_in_two_tuple_direct  s   

z3ExpandingBoundInTest.test_bound_in_two_tuple_directc                 C   rv  )Nr[   rY  rX  r   rN  r2  r3   r3   r4   /test_bound_in_heterogeneous_two_tuple_bindparam  s   



zDExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_bindparamc                 C   ry  )NrX  rY  )r=   r)   r   rP   r*   r   r!   rY   r%  r	   rO   rL   r2  r3   r3   r4   ,test_bound_in_heterogeneous_two_tuple_direct  s   

	zAExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_directc                 C   s6   t dtddd}| j|g ddg did d S )N8select id FROM some_table WHERE (x, z) IN :q ORDER BY idr[   Trs  rY  rX  r   rt  rq  r3   r3   r4   4test_bound_in_heterogeneous_two_tuple_text_bindparam,  s   

zIExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparamc              	   C   sh   G dd dt j}tdtdtt t dd}| j|g dd|dd	|d
d|ddgid d S )Nc                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
zhExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuplec                 W   
   || _ d S rC   _datarI   r-   r3   r3   r4   __init__<     
zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   
   t | jS rC   iterr  rI   r3   r3   r4   __iter__?  r  zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   
   | j | S rC   r  rI   idxr3   r3   r4   __getitem__B  r  ztExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   r  rC   r   r  r  r3   r3   r4   __len__E  r  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrS   rT   rU   r  r  r  r  r3   r3   r3   r4   
LikeATuple;  
    r  r}  r[   Trm  rY  r   r*  r   r+  ra   r,  r   )	collections_abcSequencer   rp  r   r"   r   r   rL   rI   r  rx   r3   r3   r4   ?test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple9  s(   
zTExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuplec              	   C   s\   G dd dt j}tdtddd}| j|g dd|dd	|d
d|ddgid d S )Nc                   @   r  )
zgExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuplec                 W   r  rC   r  r  r3   r3   r4   r  a  r  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   r  rC   r  r  r3   r3   r4   r  d  r  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   r  rC   r  r  r3   r3   r4   r  g  r  zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   r  rC   r  r  r3   r3   r4   r  j  r  zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__Nr  r3   r3   r3   r4   r  `  r  r  r}  r[   Trs  rY  r   r*  r   r+  ra   r,  r   )r  r  r   rp  r   rL   r  r3   r3   r4   >test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple[  s    
zSExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuplec                 C   J   | j j}t|jj|jjtd	|jj}| j
|g dg id d S rM  rd  r2  r3   r3   r4   (test_empty_set_against_integer_bindparam|     

z=ExpandingBoundInTest.test_empty_set_against_integer_bindparamc                 C   >   | j j}t|jj|jjg |jj}| 	|g  d S rC   rf  r2  r3   r3   r4   %test_empty_set_against_integer_direct     &z:ExpandingBoundInTest.test_empty_set_against_integer_directc                 C   N   | j j}t|jj|jjtd	|jj}| j
|g ddg id d S Nr[   re   rf   rg   r
  r   )r=   r)   r   rP   r*   r   rY   ri  r   rO   rL   r2  r3   r3   r4   1test_empty_set_against_integer_negation_bindparam     

zFExpandingBoundInTest.test_empty_set_against_integer_negation_bindparamc                 C   B   | j j}t|jj|jjg |jj}| 	|g d d S Nr  )
r=   r)   r   rP   r*   r   rY   ri  rO   rL   r2  r3   r3   r4   .test_empty_set_against_integer_negation_direct     $zCExpandingBoundInTest.test_empty_set_against_integer_negation_directc                 C   r  rM  )r=   r)   r   rP   r*   r   r%  r	   r   rO   rL   r2  r3   r3   r4   'test_empty_set_against_string_bindparam  r  z<ExpandingBoundInTest.test_empty_set_against_string_bindparamc                 C   r  rC   )
r=   r)   r   rP   r*   r   r%  r	   rO   rL   r2  r3   r3   r4   $test_empty_set_against_string_direct  r  z9ExpandingBoundInTest.test_empty_set_against_string_directc                 C   r  r  )r=   r)   r   rP   r*   r   r%  ri  r   rO   rL   r2  r3   r3   r4   0test_empty_set_against_string_negation_bindparam  r  zEExpandingBoundInTest.test_empty_set_against_string_negation_bindparamc                 C   r  r  )
r=   r)   r   rP   r*   r   r%  ri  rO   rL   r2  r3   r3   r4   -test_empty_set_against_string_negation_direct  r  zBExpandingBoundInTest.test_empty_set_against_string_negation_directc                 C   sD   t tt tdddt ft d}t|| d d d S )Nfoor3   )valueZelse_r   Fr   )	r   r   r   r	   r   r    r   r<   fetchonerI   r@   rx   r3   r3   r4   )test_null_in_empty_set_is_false_bindparam  s   	z>ExpandingBoundInTest.test_null_in_empty_set_is_false_bindparamc                 C   s<   t tt g t ft d}t|| d d d S )Nr  r   r  )r   r   r   r	   r    r   r<   r  r  r3   r3   r4   &test_null_in_empty_set_is_false_direct  s   
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directNr   ))rS   rT   rU   rV   rW   r5   rA   rL   rJ  rK  r   rN   Ztuple_in_w_emptyrO  r\  r_  rb  re  rg  rj  rk  rr  ru  rH  rx  rz  r{  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r3   r3   r3   r4   rI  D  s^    




	

	
		



	



!
 				rI  c                   @   s.  e Zd ZdZdZdZedd Zedd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zejjd&d' Zejjd(d) Zejjed*h d+fd,h d-fd.h d-fd/d0hfd1ee d2d3fd4ee d2d3fd5e fd6d7 Z!dS )8LikeFunctionsTestTonceNc                 C   r(   )Nr)   r*   Tr+   r-   r\   r/   r0   r3   r3   r4   r5     r6   zLikeFunctionsTest.define_tablesc                 C   sp   | | jj ddddddddddd	dd
ddddddddddddddddddd dg d S )Nr7   Zabcdefgr9   r   zab/cdefgr   zab%cdefgra   Zab_cdefgrl   zabcde/fgr   zabcde%fgrn   zab#cdefg   Zab9cdefg	   zabcde#fgr   Zabcd9fg   r;   r?   r3   r3   r4   rA     s   
zLikeFunctionsTest.insert_datac                 C   sb   | j j}tj }dd |t|jj	|D }W d    n1 s%w   Y  t
|| d S )Nc                 S   s   h | ]\}|qS r3   r3   )r  r  r3   r3   r4   	<setcomp>  s    z*LikeFunctionsTest._test.<locals>.<setcomp>)r=   r)   r   rE   rF   r<   r   rP   r*   r   r   )rI   rw   r   r)   rK   rowsr3   r3   r4   _test  s   zLikeFunctionsTest._testc                 C   &   | j jjj}| |dh d d S )Nab%c
   r7   r   r   ra   rl   r   rn   r  r  r   r=   r)   rP   r-   r  
startswithrI   colr3   r3   r4   test_startswith_unescaped     z+LikeFunctionsTest.test_startswith_unescapedc                 C   (   | j jjj}| |jddddh d S )Nr  T
autoescaper   r  r  r3   r3   r4   test_startswith_autoescape     z,LikeFunctionsTest.test_startswith_autoescapec                 C   *   | j jjj}| |tdh d d S )Nz'ab%c'r  )r=   r)   rP   r-   r  r  r   r  r3   r3   r4   test_startswith_sqlexpr  s
   z)LikeFunctionsTest.test_startswith_sqlexprc                 C   r  )Nzab##c#escapern   r  r  r3   r3   r4   test_startswith_escape  r  z(LikeFunctionsTest.test_startswith_escapec                 C   D   | j jjj}| |jdddddh | |jdddddh d S )Nr  Tr  r  r  r   zab#crn   r  r  r3   r3   r4   !test_startswith_autoescape_escape     z3LikeFunctionsTest.test_startswith_autoescape_escapec                 C   r  )Ne%fg	   r7   r   r   ra   rl   r   rn   r  r  r=   r)   rP   r-   r  endswithr  r3   r3   r4   test_endswith_unescaped  r  z)LikeFunctionsTest.test_endswith_unescapedc                 C   r  )Nz'e%fg'r  )r=   r)   rP   r-   r  r  r   r  r3   r3   r4   test_endswith_sqlexpr  s   z'LikeFunctionsTest.test_endswith_sqlexprc                 C   r  )Nr  Tr  r   r  r  r3   r3   r4   test_endswith_autoescape   r  z*LikeFunctionsTest.test_endswith_autoescapec                 C   r  )Nze##fgr  r  r  r  r  r3   r3   r4   test_endswith_escape$  r  z&LikeFunctionsTest.test_endswith_escapec                 C   r  )Nr  Tr  r  r   ze#fgr  r  r  r3   r3   r4   test_endswith_autoescape_escape(  r  z1LikeFunctionsTest.test_endswith_autoescape_escapec                 C   r  )Nb%cder  r=   r)   rP   r-   r  containsr  r3   r3   r4   test_contains_unescaped-  r  z)LikeFunctionsTest.test_contains_unescapedc                 C   r  )Nr  Tr  r   r  r  r3   r3   r4   test_contains_autoescape1  r  z*LikeFunctionsTest.test_contains_autoescapec                 C   r  )Nzb##cder  r  rn   r  r  r3   r3   r4   test_contains_escape5  r  z&LikeFunctionsTest.test_contains_escapec                 C   r  )Nzb%cdTr  r  r   zb#cdrn   r  r  r3   r3   r4   test_contains_autoescape_escape9  r  z1LikeFunctionsTest.test_contains_autoescape_escapec                 C   s(   | j jjj}| |d h d d S )Na.cde>   r   r   ra   rn   r  r   r=   r)   rP   r-   r  regexp_matchr  r3   r3   r4   test_not_regexp_match>  s   z'LikeFunctionsTest.test_not_regexp_matchc                 C   s.   | j jjj}| |dddh d d S )Nr  ZFOO   r7   rl   r   r  )r=   r)   rP   r-   r  regexp_replacer  r  r3   r3   r4   test_regexp_replaceC  s   z%LikeFunctionsTest.test_regexp_replacer  r  abc>   r7   rl   r   r  r   z^abcZ9cder  z^ar7   r  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S rC   r  )rI   r   r   r  r3   r3   r4   test_regexp_matchJ  s   z#LikeFunctionsTest.test_regexp_match)"rS   rT   rU   rV   run_insertsrun_deletesrW   r5   rA   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rN   r  r  r  r  r   r   ranger  r3   r3   r3   r4   r    sL    






	r  c                   @   s<   e Zd ZdZdZedd Zedd Zdd Zd	d
 Z	dS )ComputedColumnTestT)Zcomputed_columnsc                 C   s>   t d|tdtddtdttdttdtdttd	 d S )
Nsquarer*   Tr+   sideareazside * side	perimeterz4 * side)r   r   r   r   r0   r3   r3   r4   r5   ]  s   z ComputedColumnTest.define_tablesc                 C   s(   | | jj ddddddg d S )Nr7   r   )r*   r  *   )r<   r=   r  r>   r?   r3   r3   r4   rA   h  s   
zComputedColumnTest.insert_datac                 C   sl   t j '}|ttd| jj	| jjj
j }t|ddg W d    d S 1 s/w   Y  d S )N*)r7   r   r.   r   )r   r       )r   rE   rF   r<   r   r   r  r=   r  rO   rP   r*   rG   r   rI   rK   resr3   r3   r4   test_select_allo  s   

"z"ComputedColumnTest.test_select_allc                 C   sz   t j .}|t| jjjj| jjjj	
| jj| jjjj }t|ddg W d    d S 1 s6w   Y  d S )N)r.   r   )r  r  )r   rE   rF   r<   r   r=   r  rP   r  r  r  rO   r*   rG   r   r  r3   r3   r4   test_select_columnsx  s   
"z&ComputedColumnTest.test_select_columnsN)
rS   rT   rU   rV   r   rW   r5   rA   r  r  r3   r3   r3   r4   r  Y  s    


	r  c                   @   sT   e Zd ZdZdZdZdZedd Zedd Z	dd	 Z
d
d Zejjdd ZdS )IdentityColumnTestT)Zidentity_columnsr  c                 C   sd   t d|tdttdddddddtdtd t d	|tdttd
ddddddtdtd d S )Ntbl_ar*   Tr  )alwaysstartZ
nominvalueZ
nomaxvaluer+   rr   r.   tbl_br   i)	incrementr   ZminvalueZmaxvaluer   r   r   r   r   r0   r3   r3   r4   r5     s0   z IdentityColumnTest.define_tablesc                 C   s`   | | jj ddiddig | | jj ddiddig | | jj dddg d S )Nrr   r   r   r  rP   r*   rr   )r<   r=   r  r>   r  r?   r3   r3   r4   rA     s   



zIdentityColumnTest.insert_datac                 C   s|   | ttd| jj| jjjj	 }t
|ddg | ttd| jj| jjjj	 }t
|g d d S )Nr  )r  r   )+   r   ))r  r   )r   r   )r  rP   )r<   r   r   r  r=   r  rO   rP   r*   rG   r   r  rI   r@   r  r3   r3   r4   r    s    



z"IdentityColumnTest.test_select_allc                 C   s:   | t| jjjj| jjjj }t|ddg d S )N)r  )r  )	r<   r   r=   r  rP   r*   rO   rG   r   r  r3   r3   r4   r    s   z&IdentityColumnTest.test_select_columnsc                    s     fdd}t ttf| d S )Nc                      s      jj dddg d S )N   r   r  )r<   r=   r  r>   r3   r@   rI   r3   r4   fn  s   

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r%   r&   )rI   r@   r
  r3   r	  r4   test_insert_always_error  s   z+IdentityColumnTest.test_insert_always_errorN)rS   rT   rU   rV   r   r  r  rW   r5   rA   r  r  r   rN   Zidentity_columns_standardr  r3   r3   r3   r4   r    s    

r  c                   @   s(   e Zd ZdZdZedd Zdd ZdS )IdentityAutoincrementTestT)Zautoincrement_without_sequencec              
   C   s,   t d|tdtt dddtdtd d S )Ntblr*   T)r,   Zautoincrementrr   r.   r  r0   r3   r3   r4   r5     s   z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi}| | jj  }t|d d S )Nrr   row)r7   r  )r<   r=   r  r>   r   r   r   r  r3   r3   r4    test_autoincrement_with_identity  s   z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rS   rT   rU   rV   r   rW   r5   r  r3   r3   r3   r4   r    s    
r  c                   @   s8   e Zd ZdZedd Zedd Zdd Zdd	 Zd
S )
ExistsTestTc                 C   r(   )Nstuffr*   Tr+   r-   r\   r/   r0   r3   r3   r4   r5     r6   zExistsTest.define_tablesc              	   C   s8   | | jj ddddddddddddg d S )Nr7   	some datar9   r   r   ra   zsome other data)r<   r=   r  r>   r?   r3   r3   r4   rA     s   
zExistsTest.insert_datac              	   C   s@   | j j}t|ttdt |jj	dk
 dg d S )Nr7   r  re   r=   r  r   r<   r   r   r   r   rP   r-   rG   rI   r@   r  r3   r3   r4   test_select_exists  s   zExistsTest.test_select_existsc              	   C   s>   | j j}t|ttdt |jj	dk
 g  d S )Nr7   zno datar  r  r3   r3   r4   test_select_exists_false  s   z#ExistsTest.test_select_exists_falseN)	rS   rT   rU   rV   rW   r5   rA   r  r  r3   r3   r3   r4   r    s    

r  c                   @   s&   e Zd ZdZeejjdd ZdS )DistinctOnTestTc                 C   sX   t dtdtd}td | |d W d    d S 1 s%w   Y  d S )Nr  r[   r  z:DISTINCT ON is currently supported only by the PostgreSQL zSELECT DISTINCT * FROM foo)r   r  r   r  r   r   Zexpect_deprecatedr1  )rI   Zstmr3   r3   r4   test_distinct_on  s   "zDistinctOnTest.test_distinct_onN)	rS   rT   rU   rV   r   Zfails_ifrN   Zsupports_distinct_onr  r3   r3   r3   r4   r    s    r  c                	   @   s@   e Zd ZdZdZedd Zejddddd	d
dddd Z	dS )IsOrIsNotDistinctFromTestT)Zsupports_is_distinct_fromc              
   C   s2   t d|tdtddtdtddtdtdd d S )Nis_distinct_testr*   Tr+   col_ar   col_br   r0   r3   r3   r4   r5   ,  s   z'IsOrIsNotDistinctFromTest.define_tables)Zboth_int_differentr   r7   r7   )Zboth_int_samer7   r7   r   )Zone_null_firstNr7   r7   )Zone_null_secondr   Nr7   )Z	both_nullNNr   Ziaaaz3col_a_value, col_b_value, expected_row_count_for_is)Zid_r   c                 C   s   | j j}|| d||dg || |jj|jj	
 }tt|| |dkr1dnd}|| |jj|jj	
 }tt|| d S )Nr7   )r*   r  r  r   )r=   r  r<   r>   r   r   rP   r  Zis_distinct_fromr  rG   r   r   Zis_not_distinct_from)rI   Zcol_a_valueZcol_b_valueZexpected_row_count_for_isr@   r  rJ   Zexpected_row_count_for_is_notr3   r3   r4   test_is_or_is_not_distinct_from6  s2   z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rS   rT   rU   rV   r   rW   r5   r   r   r  r3   r3   r3   r4   r  (  s    
		r  )>collections.abcr  r  r  rC  r   r   r   r   Z
assertionsr   r   r	   Z	assertsqlr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   excr%   r&   Z
TablesTestr'   rX   ZTestBaser{   r   r   r   r  r"  rI  r  r  r  r  r  r  r  r3   r3   r3   r4   <module>   s~   &M   Jcd
w     	+P/