o
    Rc                     @   s  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( 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/G d/d0 d0ej+Z0G d1d2 d2ej+Z1G d3d4 d4ej+Z2G d5d6 d6eeej+Z3G d7d8 d8ej+Z4G d9d: d:ej+Z5G d;d< d<ej+Z6G d=d> d>ej+Z7G d?d@ d@ej+Z8G dAdB dBej+Z9G 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)util)values)DatabaseError)ProgrammingError)collections_abcc                   @   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 r5   FD:\Flask\env\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r3   
connectionr5   r5   r6   insert_data6   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connr5   r5   r6   _assert_result@      "zCollateTest._assert_resultc                 C   sB   t jt j}| t| jj| jjj	j
| ddg d S )N)r9   r:   )r   r<   )r   requiresZget_order_by_collationr   rN   r   r?   r+   order_bycr/   Zcollateasc)rK   Z	collationr5   r5   r6   test_collate_order_byD   s   z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr7   rC   rN   r   rP   Zorder_by_collationrT   r5   r5   r5   r6   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   pr1   r2   r5   r5   r6   r7   [   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 )Nr9   r   q1Zp3)r,   r[   r\   r]   r_   r   q2p2   Zq3p1r=   rA   r5   r5   r6   rC   g   s   
zOrderByLabelTest.insert_datac                 C   rD   rE   rF   rJ   r5   r5   r6   rN   r   rO   zOrderByLabelTest._assert_resultc                 C   s4   | j j}|jjd}| t||g d d S )Nlxr9   r   r   )r?   r+   rR   r[   labelrN   r   rQ   rK   r   re   r5   r5   r6   
test_plainv   s   zOrderByLabelTest.test_plainc                 C   s<   | j j}|jj|jj d}| t||g d d S )Nre   )ri         )	r?   r+   rR   r[   r\   rj   rN   r   rQ   rk   r5   r5   r6   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|||| dtdfdtdfdtdfg d S )	Nre   lyr   Zq1p3rn   Zq2p2rp   Zq3p1)r?   r+   rR   r[   r\   rj   r   lowerr]   r_   rN   r   rQ   descr$   u)rK   r   re   rr   r5   r5   r6   test_composed_multiple   s   &z'OrderByLabelTest.test_composed_multiplec                 C   s8   | j j}|jjd}| t|| g d d S )Nre   )ri   rh   rg   )	r?   r+   rR   r[   rj   rN   r   rQ   rt   rk   r5   r5   r6   test_plain_desc   s   "z OrderByLabelTest.test_plain_descc                 C   s@   | j j}|jj|jj d}| t||	 g d d S )Nre   )ro   rm   ri   )
r?   r+   rR   r[   r\   rj   rN   r   rQ   rt   rk   r5   r5   r6   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 )Nre   ))r9   r   )r9   rn   )r9   rp   )r?   r+   rR   r[   r\   rj   r   r   countr,   Zgroup_byrQ   rN   )rK   r   exprstmtr5   r5   r6   test_group_by_composed   s
   z'OrderByLabelTest.test_group_by_composedN)rU   rV   rW   __doc__rX   rY   r7   rC   rN   rl   rq   rv   rw   rx   r   rP   Zgroup_by_complex_expressionr|   r5   r5   r5   r6   rZ   P   s    


	rZ   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   ))r9   Zname1)r   Zname2)r   Zname3)	r%   r   r   r   r/   r   r>   r   all)rK   rB   Z
value_exprr5   r5   r6   test_tuples   s   
z ValuesExpressionTest.test_tuplesN)rU   rV   rW   __requires__rX   r   r5   r5   r5   r6   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-   r[   r\   r   r   r   r2   r5   r5   r6   r7         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 )Nr9   r   r,   r[   r\   r   rc   rn      r=   rA   r5   r5   r6   rC      s   





z FetchLimitOffsetTest.insert_datar5   Fc                 C   sV   |r| || }tt|t| tt|t| d S t| || | d S rE   )r>   rI   r   lenset)rK   rB   r   rL   paramsset_Z	query_resr5   r5   r6   rN      s
   z#FetchLimitOffsetTest._assert_resultc                 C   s(   t jjdd}t||| | d S )NT)Zclose_with_result)r   rG   rH   r   Zexec_driver_sqlrI   rK   r   rL   r   rM   r5   r5   r6   _assert_result_str   s   z'FetchLimitOffsetTest._assert_result_strc                 C   sN   | j j}t||jj}| ||dddg | ||dg d d S Nr   r9   r9   r   r   r   r   r   r   r   r   r   rc   )r?   r+   r   rQ   rR   r,   rN   limit)rK   rB   r   r{   r5   r5   r6   test_simple_limit   s   z&FetchLimitOffsetTest.test_simple_limitc                 C   sL   | j j}t|jjd }tt|t|  }| 	||dg d S )Nr9   rg   )
r?   r+   r   rR   r,   r   Zscalar_subqueryr#   ZsubqueryrN   )rK   rB   r   r{   ru   r5   r5   r6    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+   rN   r   rQ   rR   r,   fetchrK   rB   r   r5   r5   r6   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   rc   rc   rn   rn   rc   r   r   r   r   r?   r+   rN   r   rQ   rR   r,   offsetr   r5   r5   r6   test_simple_offset   r   z'FetchLimitOffsetTest.test_simple_offset)r   r   r   r9   r   r   )r   r   r   )r   r9   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_optionsrN   r   rQ   rR   r,   r   r   )rK   rB   r   r   Zassert_datar   r   expectedr5   r5   r6   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   r9   r   r   r   r   	r?   r+   rN   r   rQ   rR   r,   r   r   r   r5   r5   r6   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+   rN   r   r   r   r5   r5   r6   test_fetch_offset_no_order2  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   r9   r   r   r   r   r   r   r5   r5   r6   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   r9   literal_bindsT)dialectcompile_kwargsr   r   N)r?   r+   r   rQ   rR   r,   r   r   compiler   rG   r   strr   rK   r   r{   sqlr5   r5   r6   test_limit_offset_nobindsK     z.FetchLimitOffsetTest.test_limit_offset_nobindsc                 C   r   r   )r?   r+   r   rQ   rR   r,   r   r   r   r   rG   r   r   r   r   r5   r5   r6   test_fetch_offset_nobindsX  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+   rN   r   rQ   rR   r,   r   r   r   r5   r5   r6   test_bound_limite     
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   r9   )	r?   r+   rN   r   rQ   rR   r,   r   r   r   r5   r5   r6   test_bound_offsetv  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   r9   )r   r   r   r   r   )
r?   r+   rN   r   rQ   rR   r,   r   r   r   r   r5   r5   r6   test_bound_limit_offset  &   







z,FetchLimitOffsetTest.test_bound_limit_offsetc                 C   r   )Nfr   r   r   r   r9   )r   r   r   r   r   )
r?   r+   rN   r   rQ   rR   r,   r   r   r   r   r5   r5   r6   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+   rN   r   rQ   rR   r,   r   r   r   r5   r5   r6   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+   rN   r   rQ   rR   r,   r   r   r   r5   r5   r6   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+   rN   r   rQ   rR   r,   r   r   r   r   r5   r5   r6   test_expr_limit_offset  s   
z+FetchLimitOffsetTest.test_expr_limit_offsetc                 C   r   r   )
r?   r+   rN   r   rQ   rR   r,   r   r   r   r   r5   r5   r6   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+   rN   r   rQ   rR   r,   r   r   r   r   r5   r5   r6   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   r9   r   r   r   r5   r5   r6   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 )	Nr9   T	with_tiesr   r   r   r   r   	r?   r+   rN   r   rQ   rR   r[   rt   r   r   r5   r5   r6   test_simple_fetch_ties  s   
z+FetchLimitOffsetTest.test_simple_fetch_tiesc                 C   s\   | j j}|t||jjjdddd	 }t
|d d t
t|tg d d S )Nr   Tr   r   r   r   r?   r+   r>   r   rQ   rR   r[   r   r   rI   r   r   rK   rB   r   far5   r5   r6   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   r9   r   r   r   r   r   )	r?   r+   rN   r   rQ   rR   r[   r   r   r   r5   r5   r6   #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   r5   r5   r6   test_simple_fetch_percentB  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   r9   r   r   r   r   r5   r5   r6   test_fetch_offset_percentK  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   r5   r5   r6   test_simple_fetch_percent_tiesX  s   
z3FetchLimitOffsetTest.test_simple_fetch_percent_tiesc                 C   s^   | j j}|t||jjjddddd	 }t
|d d t
t|tg d d S )Nr   Tr   r   r   r   r   r   r   r5   r5   r6   test_fetch_offset_percent_tiese  s   
z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r5   Fr5   )0rU   rV   rW   rX   rY   r7   rC   rN   r   r   r   r   rP   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   r5   r5   r5   r6   r      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 )JoinTestTr5   c                 C   F   t j }t||| | W d    d S 1 sw   Y  d S rE   rF   r   r5   r5   r6   rN   w     "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.idFZnullable)r   r   r   r   r2   r5   r5   r6   r7   {  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,   r9   r   r   rc   rn   )r,   r   )r>   r?   r   r@   r   rA   r5   r5   r6   rC     s   
 
zJoinTest.insert_datac                 C   J   |  dd\}}t|||||jj|jj}| |g d d S Nr   r   ))r9   r9   r9   )r9   r   r9   )r   rc   r   )r   rn   r   r?   r   select_fromjoinrQ   rR   r,   rN   rK   r   r   r{   r5   r5   r6   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 r5   r5   ).0r   r   rR   r5   r5   r6   
<listcomp>  s    z1JoinTest.test_inner_join_true.<locals>.<listcomp>)rg   rh   ri   rc   rm   ))r9   r9   r   )rc   r   )rn   r   )r?   r   r   r   r    rQ   rR   r,   rN   	itertoolsproductr   r5   r5   r6   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   rQ   rR   r,   rN   r   r5   r5   r6   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   ))r9   NN)r   NN)r   NN)rc   NN)rn   NN)	r?   r   r   Z	outerjoinr   rQ   rR   r,   rN   r   r5   r5   r6   test_outer_join_false  s   zJoinTest.test_outer_join_falsec                 C   r   r   r   r   r5   r5   r6   test_outer_join_fk  r   zJoinTest.test_outer_join_fkNr   )rU   rV   rW   rX   rN   rY   r7   rC   r   r   r   r   r  r5   r5   r5   r6   r   t  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   r2   r5   r5   r6   r7     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 )Nr9   r   r   r   rc   rn   r=   rA   r5   r5   r6   rC     s   




zCompoundSelectTest.insert_datar5   c                 C   r   rE   rF   r   r5   r5   r6   rN     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   whererR   r,   r#   rN   rQ   selected_columnsrK   r   s1s2u1r5   r5   r6   test_plain_union  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  rR   r,   r#   aliasrN   rQ   r  r  r5   r5   r6   test_select_from_plain_union  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   r9   r   r   r   )r?   r+   r   r  rR   r,   r   rQ   r#   rN   r  r  r5   r5   r6   &test_limit_offset_selectable_in_unions	  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  rR   r,   rQ   r#   r   rN   r  r  r5   r5   r6   "test_order_by_selectable_in_unions  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  rR   r,   distinctr#   r   rN   rQ   r  r  r5   r5   r6   "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  rR   r,   r   rQ   r#   r  rN   r  r5   r5   r6   &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  rR   r,   r   rQ   r  r#   rN   r  r  r5   r5   r6   .test_limit_offset_aliased_selectable_in_unions6  s&   
	
	zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsNr   )rU   rV   rW   rX   rY   r7   rC   rN   r
  r  r   rP   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  r5   r5   r5   r6   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-   r[   r\   zr^   r1   r2   r5   r5   r6   r7   V     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 Nr9   r   z1)r,   r[   r\   r  r   z2rc   z3rn   z4r=   rA   r5   r5   r6   rC   a     
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   rR   r,   r  r[   r   assert_compilerK   r   r{   r5   r5   r6   test_compilem  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   r"  r$  r5   r5   r6   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 = 10r5   )r?   r+   r   rR   r,   r  r[   r   sql_execution_asserterr   rG   rH   r>   dictassert_r
   r   
positionalrK   r   r{   ZasserterrM   r5   r5   r6   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!  )rn   r   rp   r'  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r5   )r?   r+   r   rR   r,   r  r[   r	   r   r(  r   rG   rH   r>   r)  r*  r
   r   r+  r,  r5   r5   r6   +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.  )rn   r   )      r'  zbSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.y) IN (%s(5, 10), (12, 18))VALUES  r5   )r?   r+   r   rR   r,   r  r!   r[   r\   r	   r   r(  r   rG   rH   r>   r)  r*  r
   r   tuple_in_valuesr+  r,  r5   r5   r6   1test_execute_tuple_expanding_plus_literal_execute  (   
zGPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_executec              	   C   r1  )Nr]   Tr.  )rn   r  )r2  r  r'  zfSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.z) IN (%s(5, 'z1'), (12, 'z3'))r4  r5  r5   )r?   r+   r   rR   r,   r  r!   r[   r  r	   r   r(  r   rG   rH   r>   r)  r*  r
   r   r6  r+  r,  r5   r5   r6   ?test_execute_tuple_expanding_plus_literal_heterogeneous_execute  r8  zUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rU   rV   rW   rX   r   rY   r7   rC   r%  r&  r-  r0  r   rP   tuple_inr7  r9  r5   r5   r5   r6   r  O  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  r1   r2   r5   r5   r6   r7     r  z"ExpandingBoundInTest.define_tablesc                 C   r  r  r=   rA   r5   r5   r6   rC     r  z ExpandingBoundInTest.insert_datar5   c                 C   r   rE   rF   r   r5   r5   r6   rN     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   rR   r,   r  r[   r	   r   r\   rQ   rN   r$  r5   r5   r6   "test_multiple_empty_sets_bindparam  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 rE   )r?   r+   r   rR   r,   r  r[   r	   r\   rQ   rN   r$  r5   r5   r6   test_multiple_empty_sets_direct
  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   rR   r,   r  r!   r[   r  r	   r   rQ   rN   r$  r5   r5   r6   )test_empty_heterogeneous_tuples_bindparam     

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 rE   )
r   rR   r,   r  r!   r[   r  r	   rQ   rN   valr   r{   rK   r   r5   r6   go$  
   

zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.go)r   r  )r   r  )rc   r  rh   ri   r   r?   r+   rK   rH  r5   rG  r6   &test_empty_heterogeneous_tuples_direct   
   
z;ExpandingBoundInTest.test_empty_heterogeneous_tuples_directc                 C   r>  r?  r?   r+   r   rR   r,   r  r!   r[   r\   r	   r   rQ   rN   r$  r5   r5   r6   'test_empty_homogeneous_tuples_bindparam0  rB  z<ExpandingBoundInTest.test_empty_homogeneous_tuples_bindparamc                    rC  )Nc                    rD  rE   )
r   rR   r,   r  r!   r[   r\   r	   rQ   rN   rE  rG  r5   r6   rH  >  rI  zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go))r9   r   r   r   r   rc   rf   rL  rM  r5   rG  r6   $test_empty_homogeneous_tuples_direct:  rO  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]   rK  r   r   rc   r   r?   r+   r   rR   r,   r  r[   r	   r   rQ   rN   r$  r5   r5   r6   test_bound_in_scalar_bindparamJ  s   

 z3ExpandingBoundInTest.test_bound_in_scalar_bindparamc                 C   sF   | j j}t|jj|jjg d|jj}| 	|g d d S )NrU  rK  
r?   r+   r   rR   r,   r  r[   r	   rQ   rN   r$  r5   r5   r6   test_bound_in_scalar_directS  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   rh   ri   r?   r+   r   rR   r,   r  r[   r	   not_inrQ   rN   r$  r5   r5   r6   !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   rZ  r$  r5   r5   r6   !test_empty_in_plus_notempty_notinf  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/  rK  r  r  r  r   N)r   
bindparamsr   r   rN   rK   r{   r5   r5   r6   test_typed_str_inp  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....

        r^  r]   Tr/  rK  ra  r   Nr   rb  r   rN   rc  r5   r5   r6   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]   rK  rR  rS  )rc   rn   r   rP  r$  r5   r5   r6   !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 )Nri  rK  )r?   r+   r   rR   r,   r  r!   r[   r\   r	   rQ   rN   r$  r5   r5   r6   test_bound_in_two_tuple_direct  s   

z3ExpandingBoundInTest.test_bound_in_two_tuple_directc                 C   rh  )Nr]   rK  rJ  r   r@  r$  r5   r5   r6   /test_bound_in_heterogeneous_two_tuple_bindparam  s   



zDExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_bindparamc                 C   rk  )NrJ  rK  )r?   r+   r   rR   r,   r  r!   r[   r  r	   rQ   rN   r$  r5   r5   r6   ,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]   Tre  rK  rJ  r   rf  rc  r5   r5   r6   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 rE   _datarK   r/   r5   r5   r6   __init__     
zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   
   t | jS rE   iterrt  rK   r5   r5   r6   __iter__  rw  zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   
   | j | S rE   rs  rK   idxr5   r5   r6   __getitem__  rw  ztExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   rx  rE   r   rt  r{  r5   r5   r6   __len__  rw  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrU   rV   rW   rv  r|  r  r  r5   r5   r5   r6   
LikeATuple  
    r  ro  r]   Tr_  rK  r   r  r   r  rc   r  r   )	r(   Sequencer   rb  r   r"   r   r   rN   rK   r  r{   r5   r5   r6   ?test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple  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                   @   rq  )
zgExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuplec                 W   rr  rE   rs  ru  r5   r5   r6   rv    rw  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   rx  rE   ry  r{  r5   r5   r6   r|     rw  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   r}  rE   rs  r~  r5   r5   r6   r    rw  zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   rx  rE   r  r{  r5   r5   r6   r    rw  zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__Nr  r5   r5   r5   r6   r    r  r  ro  r]   Tre  rK  r   r  r   r  rc   r  r   )r(   r  r   rb  r   rN   r  r5   r5   r6   >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 r?  rV  r$  r5   r5   r6   (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 rE   rX  r$  r5   r5   r6   %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]   rg   rh   ri   r   r   )r?   r+   r   rR   r,   r  r[   r[  r   rQ   rN   r$  r5   r5   r6   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   rR   r,   r  r[   r[  rQ   rN   r$  r5   r5   r6   .test_empty_set_against_integer_negation_direct/     $zCExpandingBoundInTest.test_empty_set_against_integer_negation_directc                 C   r  r?  )r?   r+   r   rR   r,   r  r  r	   r   rQ   rN   r$  r5   r5   r6   'test_empty_set_against_string_bindparam6  r  z<ExpandingBoundInTest.test_empty_set_against_string_bindparamc                 C   r  rE   )
r?   r+   r   rR   r,   r  r  r	   rQ   rN   r$  r5   r5   r6   $test_empty_set_against_string_direct?  r  z9ExpandingBoundInTest.test_empty_set_against_string_directc                 C   r  r  )r?   r+   r   rR   r,   r  r  r[  r   rQ   rN   r$  r5   r5   r6   0test_empty_set_against_string_negation_bindparamD  r  zEExpandingBoundInTest.test_empty_set_against_string_negation_bindparamc                 C   r  r  )
r?   r+   r   rR   r,   r  r  r[  rQ   rN   r$  r5   r5   r6   -test_empty_set_against_string_negation_directM  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foor5   )valueZelse_r   Fr   )	r   r   r   r	   r   r    r   r>   fetchonerK   rB   r{   r5   r5   r6   )test_null_in_empty_set_is_false_bindparamT  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  r5   r5   r6   &test_null_in_empty_set_is_false_direct`  s   
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directNr   ))rU   rV   rW   rX   rY   r7   rC   rN   r<  r=  r   rP   Ztuple_in_w_emptyrA  rN  rQ  rT  rW  rY  r\  r]  rd  rg  r:  rj  rl  rm  rn  rp  r  r  r  r  r  r  r  r  r  r  r  r  r5   r5   r5   r6   r;    s^    




	

	
		



	



!
 				r;  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^   r1   r2   r5   r5   r6   r7   s  r8   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 )Nr9   Zabcdefgr;   r   zab/cdefgr   zab%cdefgrc   Zab_cdefgrn   zabcde/fgr   zabcde%fgrp   zab#cdefg   Zab9cdefg	   zabcde#fgr   Zabcd9fg   r=   rA   r5   r5   r6   rC   |  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 r5   r5   )r   r  r5   r5   r6   	<setcomp>  s    z*LikeFunctionsTest._test.<locals>.<setcomp>)r?   r+   r   rG   rH   r>   r   rR   r,   r  r   )rK   rz   r   r+   rM   rowsr5   r5   r6   _test  s   zLikeFunctionsTest._testc                 C   &   | j jjj}| |dh d d S )Nab%c
   r9   r   r   rc   rn   r   rp   r  r  r   r?   r+   rR   r/   r  
startswithrK   colr5   r5   r6   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  r5   r5   r6   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+   rR   r/   r  r  r   r  r5   r5   r6   test_startswith_sqlexpr  s
   z)LikeFunctionsTest.test_startswith_sqlexprc                 C   r  )Nzab##c#escaperp   r  r  r5   r5   r6   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#crp   r  r  r5   r5   r6   !test_startswith_autoescape_escape     z3LikeFunctionsTest.test_startswith_autoescape_escapec                 C   r  )Ne%fg	   r9   r   r   rc   rn   r   rp   r  r  r?   r+   rR   r/   r  endswithr  r5   r5   r6   test_endswith_unescaped  r  z)LikeFunctionsTest.test_endswith_unescapedc                 C   r  )Nz'e%fg'r  )r?   r+   rR   r/   r  r  r   r  r5   r5   r6   test_endswith_sqlexpr  s   z'LikeFunctionsTest.test_endswith_sqlexprc                 C   r  )Nr  Tr  r   r  r  r5   r5   r6   test_endswith_autoescape  r  z*LikeFunctionsTest.test_endswith_autoescapec                 C   r  )Nze##fgr  r  r  r  r  r5   r5   r6   test_endswith_escape  r  z&LikeFunctionsTest.test_endswith_escapec                 C   r  )Nr  Tr  r  r   ze#fgr  r  r  r5   r5   r6   test_endswith_autoescape_escape  r  z1LikeFunctionsTest.test_endswith_autoescape_escapec                 C   r  )Nb%cder  r?   r+   rR   r/   r  containsr  r5   r5   r6   test_contains_unescaped  r  z)LikeFunctionsTest.test_contains_unescapedc                 C   r  )Nr  Tr  r   r  r  r5   r5   r6   test_contains_autoescape  r  z*LikeFunctionsTest.test_contains_autoescapec                 C   r  )Nzb##cder  r  rp   r  r  r5   r5   r6   test_contains_escape  r  z&LikeFunctionsTest.test_contains_escapec                 C   r  )Nzb%cdTr  r  r   zb#cdrp   r  r  r5   r5   r6   test_contains_autoescape_escape  r  z1LikeFunctionsTest.test_contains_autoescape_escapec                 C   s(   | j jjj}| |d h d d S )Na.cde>   r   r   rc   rp   r  r   r?   r+   rR   r/   r  regexp_matchr  r5   r5   r6   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   r9   rn   r   r  )r?   r+   rR   r/   r  regexp_replacer  r  r5   r5   r6   test_regexp_replace  s   z%LikeFunctionsTest.test_regexp_replacer  r  abc>   r9   rn   r   r  r   z^abcZ9cder  z^ar9   r  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S rE   r  )rK   r   r   r  r5   r5   r6   test_regexp_match  s   z#LikeFunctionsTest.test_regexp_match)"rU   rV   rW   rX   run_insertsrun_deletesrY   r7   rC   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rP   r  r  r  r  r   r   ranger  r5   r5   r5   r6   r  m  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   r2   r5   r5   r6   r7     s   z ComputedColumnTest.define_tablesc                 C   s(   | | jj ddddddg d S )Nr9   r   )r,   r  *   )r>   r?   r  r@   rA   r5   r5   r6   rC     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*)r9   r   r0   r   )r   r       )r   rG   rH   r>   r   r   r   r?   r  rQ   rR   r,   rI   r   rK   rM   resr5   r5   r6   test_select_all  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)r0   r   )r  r  )r   rG   rH   r>   r   r?   r  rR   r  r  r   rQ   r,   rI   r   r  r5   r5   r6   test_select_columns  s   
"z&ComputedColumnTest.test_select_columnsN)
rU   rV   rW   rX   r   rY   r7   rC   r  r  r5   r5   r5   r6   r    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-   rt   r0   tbl_br   i)	incrementr  ZminvalueZmaxvaluer   r   r   r   r   r2   r5   r5   r6   r7   &  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 )Nrt   r   r   r  rR   r,   rt   )r>   r?   r  r@   r  rA   r5   r5   r6   rC   A  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  rR   )r>   r   r   r   r?   r  rQ   rR   r,   rI   r   r  rK   rB   r  r5   r5   r6   r  P  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  rR   r,   rQ   rI   r   r  r5   r5   r6   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@   r5   rB   rK   r5   r6   fnh  s   

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r&   r'   )rK   rB   r  r5   r  r6   test_insert_always_errorf  s   z+IdentityColumnTest.test_insert_always_errorN)rU   rV   rW   rX   r   r  r  rY   r7   rC   r  r  r   rP   Zidentity_columns_standardr  r5   r5   r5   r6   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autoincrementrt   r0   r  r2   r5   r5   r6   r7   u  s   z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi}| | jj  }t|d d S )Nrt   row)r9   r  )r>   r?   r  r@   r   firstr   r  r5   r5   r6    test_autoincrement_with_identity  s   z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rU   rV   rW   rX   r   rY   r7   r  r5   r5   r5   r6   r  q  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^   r1   r2   r5   r5   r6   r7     r8   zExistsTest.define_tablesc              	   C   s8   | | jj ddddddddddddg d S )Nr9   	some datar;   r   r   rc   zsome other data)r>   r?   r  r@   rA   r5   r5   r6   rC     s   
zExistsTest.insert_datac              	   C   s@   | j j}t|ttdt |jj	dk
 dg d S )Nr9   r  rg   r?   r  r   r>   r   r   r  r   rR   r/   rI   rK   rB   r  r5   r5   r6   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 )Nr9   zno datar  r  r5   r5   r6   test_select_exists_false  s   z#ExistsTest.test_select_exists_falseN)	rU   rV   rW   rX   rY   r7   rC   r  r  r5   r5   r5   r6   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_deprecatedr#  )rK   Zstmr5   r5   r6   test_distinct_on  s   "zDistinctOnTest.test_distinct_onN)	rU   rV   rW   rX   r   Zfails_ifrP   Zsupports_distinct_onr
  r5   r5   r5   r6   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   r2   r5   r5   r6   r7     s   z'IsOrIsNotDistinctFromTest.define_tables)Zboth_int_differentr   r9   r9   )Zboth_int_samer9   r9   r   )Zone_null_firstNr9   r9   )Zone_null_secondr   Nr9   )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 )Nr9   )r,   r  r  r   )r?   r  r>   r@   r   r  rR   r  Zis_distinct_fromr  rI   r   r   Zis_not_distinct_from)rK   Zcol_a_valueZcol_b_valueZexpected_row_count_for_isrB   r  rL   Zexpected_row_count_for_is_notr5   r5   r6   test_is_or_is_not_distinct_from  s2   z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rU   rV   rW   rX   r   rY   r7   r   r   r  r5   r5   r5   r6   r    s    
		r  )<r   r5  r   r   r   r   Z
assertionsr   r   r	   Z	assertsqlr
   Zschemar   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'   r(   Z
TablesTestr)   rZ   ZTestBaser~   r   r   r  r  r;  r  r  r  r  r  r	  r  r5   r5   r5   r6   <module>   s~    &M   Jd
w     	+Q/