U
    cc                     @   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   s&   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 r4   H/tmp/pip-unpacked-wheel-8u86ls_i/sqlalchemy/testing/suite/test_select.pydefine_tables-   s    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r2   
connectionr4   r4   r5   insert_data6   s    
zCollateTest.insert_datac              	   C   s.   t j }t|| | W 5 Q R X d S Nr   dbconnectr   r<   fetchallselfr   resultconnr4   r4   r5   _assert_result@   s    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   rK   r   r=   r*   order_bycr.   ZcollateZasc)rH   Z	collationr4   r4   r5   test_collate_order_byD   s    z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr6   rA   rK   r   rL   Zorder_by_collationrO   r4   r4   r4   r5   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   pr0   r1   r4   r4   r5   r6   [   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   Zq1Zp3)r+   rV   rW   rX   rZ   r   Zq2p2   Zq3p1r;   r?   r4   r4   r5   rA   g   s    
zOrderByLabelTest.insert_datac              	   C   s.   t j }t|| | W 5 Q R X d S rB   rC   rG   r4   r4   r5   rK   r   s    zOrderByLabelTest._assert_resultc                 C   s6   | j j}|jjd}| t||dddg d S )Nlxr7   r   r   )r=   r*   rN   rV   labelrK   r   rM   rH   r   r^   r4   r4   r5   
test_plainv   s    zOrderByLabelTest.test_plainc                 C   s>   | j j}|jj|jj d}| t||dddg d S )Nr^   ra         )	r=   r*   rN   rV   rW   rb   rK   r   rM   rc   r4   r4   r5   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 )	Nr^   lyr   Zq1p3rf   Zq2p2rh   Zq3p1)r=   r*   rN   rV   rW   rb   r   lowerrX   rZ   rK   r   rM   descr$   u)rH   r   r^   rj   r4   r4   r5   test_composed_multiple   s    &z'OrderByLabelTest.test_composed_multiplec                 C   s:   | j j}|jjd}| t|| dddg d S )Nr^   ra   r`   r_   )	r=   r*   rN   rV   rb   rK   r   rM   rl   rc   r4   r4   r5   test_plain_desc   s    z OrderByLabelTest.test_plain_descc                 C   sB   | j j}|jj|jj d}| t||	 dddg d S )Nr^   rg   re   ra   )
r=   r*   rN   rV   rW   rb   rK   r   rM   rl   rc   r4   r4   r5   test_composed_int_desc   s    z'OrderByLabelTest.test_composed_int_descc                 C   sT   | j j}|jj|jj d}tt|jj	|
||}| |dddg d S )Nr^   )r7   r   )r7   rf   )r7   rh   )r=   r*   rN   rV   rW   rb   r   r   countr+   Zgroup_byrM   rK   )rH   r   exprstmtr4   r4   r5   test_group_by_composed   s
    z'OrderByLabelTest.test_group_by_composedN)rP   rQ   rR   __doc__rS   rT   r6   rA   rK   rd   ri   rn   ro   rp   r   rL   Zgroup_by_complex_expressionrt   r4   r4   r4   r5   rU   P   s   


	rU   c                   @   s   e Zd ZdZdZdd ZdS )ValuesExpressionTest)Ztable_value_constructorTc                 C   sH   t tdttdtdddddg}t|t| dddg d S )Nr+   nameZ	my_values)rw   )r7   Zname1)r   Zname2)r   Zname3)	r%   r   r   r   r.   r   r<   r   all)rH   r@   Z
value_exprr4   r4   r5   test_tuples   s      z ValuesExpressionTest.test_tuplesN)rP   rQ   rR   __requires__rS   ry   r4   r4   r4   r5   rv      s   rv   c                   @   s8  e Zd ZdZedd Zedd ZdIdd	ZdJd
dZdd Z	dd Z
ejjdd Zejjdd Zejdddgdddgdddg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d0d1 Z ejjd2d3 Z!ejjejj"d4d5 Z#ejjd6d7 Z$ejjd8d9 Z%ejj&d:d; Z'ejj&ejj(d<d= Z)ejj&ejj(d>d? Z*ejj+d@dA Z,ejj+ejj(dBdC Z-ejj&ejj+dDdE Z.ejj&ejj+ejj(dFdG Z/dHS )KFetchLimitOffsetTestTc                 C   s*   t d|tdtddtdttdt d S Nr*   r+   Tr,   rV   rW   r   r   r   r1   r4   r4   r5   r6      s    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+   rV   rW   r   r\   rf      r;   r?   r4   r4   r5   rA      s    





z FetchLimitOffsetTest.insert_datar4   Fc                 C   sT   |r:| || }tt|t| tt|t| nt| || | d S rB   )r<   rF   r   lenset)rH   r@   r   rI   paramsset_Z	query_resr4   r4   r5   rK      s
    z#FetchLimitOffsetTest._assert_resultc                 C   s(   t jjdd}t||| | d S )NT)Zclose_with_result)r   rD   rE   r   Zexec_driver_sqlrF   rH   r   rI   r   rJ   r4   r4   r5   _assert_result_str   s    z'FetchLimitOffsetTest._assert_result_strc                 C   sP   | j j}t||jj}| ||dddg | ||ddddg d S Nr   r7   r7   r   r   r   r   r   r   r   r\   )r=   r*   r   rM   rN   r+   rK   limit)rH   r@   r   rs   r4   r4   r5   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   r_   )
r=   r*   r   rN   r+   r   Zscalar_subqueryr#   ZsubqueryrK   )rH   r@   r   rs   rm   r4   r4   r5    test_limit_render_multiple_times   s    z5FetchLimitOffsetTest.test_limit_render_multiple_timesc                 C   sZ   | j j}| |t||jjdddg | |t||jjddddg d S r   r=   r*   rK   r   rM   rN   r+   fetchrH   r@   r   r4   r4   r5   test_simple_fetch   s    z&FetchLimitOffsetTest.test_simple_fetchc                 C   sZ   | j j}| |t||jjddddg | |t||jjdddg d S )Nr   r   r\   r\   rf   rf   r\   r   r   r=   r*   rK   r   rM   rN   r+   offsetr   r4   r4   r5   test_simple_offset   s    z'FetchLimitOffsetTest.test_simple_offset)r   r   r   r7   )r   r   )r   r7   cases)argnamesc                 C   sl   | j j}|ji d}dddddg}|D ]@\}}||||  }| |t||jj|	|| q&d S )N)Zcompiled_cacher   r   r   r   r   )
r=   r*   Zexecution_optionsrK   r   rM   rN   r+   r   r   )rH   r@   r   r   Zassert_datar   r   expectedr4   r4   r5   test_simple_limit_offset  s    z-FetchLimitOffsetTest.test_simple_limit_offsetc                 C   sf   | j j}| |t||jjddddg | |t||jjdddddg d S )Nr   r7   r   r   r   r   r   	r=   r*   rK   r   rM   rN   r+   r   r   r   r4   r4   r5   test_simple_fetch_offset#  s    z-FetchLimitOffsetTest.test_simple_fetch_offsetc                 C   s2   | j j}| j|t|ddddddgdd d S )	N
   r   r   r   r   r   Tr   )r=   r*   rK   r   r   r   r4   r4   r5   test_fetch_offset_no_order2  s    z/FetchLimitOffsetTest.test_fetch_offset_no_orderc              	   C   sb   | j j}| |t||jjddddddg | |t||jjdddddg d S )Nr   r   r   r   r   r   r7   r   r   r4   r4   r5   test_simple_offset_zero<  s    
z,FetchLimitOffsetTest.test_simple_offset_zeroc                 C   sX   | 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   rM   rN   r+   r   r   compiler   rD   r   strr   rH   r   rs   Zsqlr4   r4   r5   test_limit_offset_nobindsK  s     z.FetchLimitOffsetTest.test_limit_offset_nobindsc                 C   sX   | j j}t||jjdd}|jt	j
jddid}t|}| |ddg dS r   )r=   r*   r   rM   rN   r+   r   r   r   r   rD   r   r   r   r   r4   r4   r5   test_fetch_offset_nobindsX  s     z.FetchLimitOffsetTest.test_fetch_offset_nobindsc                 C   sr   | j j}| j|t||jjtdddgddid | j|t||jjtddddgddid d S )Nlr   r   r   r   r   r   )	r=   r*   rK   r   rM   rN   r+   r   r   r   r4   r4   r5   test_bound_limite  s    z%FetchLimitOffsetTest.test_bound_limitc                 C   sv   | j j}| j|t||jjtddddgddid | j|t||jjtdddddgddid d S )	Nor   r   r   r   r   r   r7   )	r=   r*   rK   r   rM   rN   r+   r   r   r   r4   r4   r5   test_bound_offsetv  s    
z&FetchLimitOffsetTest.test_bound_offsetc                 C   s   | 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dd	d
gdddd d S )Nr   r   r   r   r   r7   )r   r   r   r   r   r   )
r=   r*   rK   r   rM   rN   r+   r   r   r   r   r4   r4   r5   test_bound_limit_offset  s2    
z,FetchLimitOffsetTest.test_bound_limit_offsetc                 C   s   | 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dd	d
gdddd d S )Nfr   r   r   r   r7   )r   r   r   r   r   r   )
r=   r*   rK   r   rM   rN   r+   r   r   r   r   r4   r4   r5   test_bound_fetch_offset  s2    
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*   rK   r   rM   rN   r+   r   r   r   r4   r4   r5   test_expr_offset  s    z%FetchLimitOffsetTest.test_expr_offsetc                 C   s@   | j j}| |t||jjtdtd dddg d S )Nr   r   r   r   r   )	r=   r*   rK   r   rM   rN   r+   r   r   r   r4   r4   r5   test_expr_limit  s    z$FetchLimitOffsetTest.test_expr_limitc                 C   sP   | j j}| |t||jjtdtd 	tdtd ddg d S Nr   r   r   
r=   r*   rK   r   rM   rN   r+   r   r   r   r   r4   r4   r5   test_expr_limit_offset  s    z+FetchLimitOffsetTest.test_expr_limit_offsetc                 C   sP   | j j}| |t||jjtdtd 	tdtd ddg d S r   )
r=   r*   rK   r   rM   rN   r+   r   r   r   r   r4   r4   r5   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 dddg d S )Nr   r   r   r   r   r   )
r=   r*   rK   r   rM   rN   r+   r   r   r   r   r4   r4   r5   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   r4   r4   r5   test_expr_limit_simple_offset  s.    	z2FetchLimitOffsetTest.test_expr_limit_simple_offsetc                 C   sr   | j j}| j|t||jj jdddddgdd | j|t||jj jddddddgdd d S )	Nr7   T	with_tiesr   r   r   r   r   	r=   r*   rK   r   rM   rN   rV   rl   r   r   r4   r4   r5   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dddg d S )Nr   Tr   r   r   r   r   r=   r*   r<   r   rM   rN   rV   r   r   rF   r   r   rH   r@   r   far4   r4   r5   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*   rK   r   rM   rN   rV   r   r   r   r4   r4   r5   #test_fetch_offset_ties_exact_number,  s2     	 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   r4   r4   r5   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   r7   r   r   r   r   r4   r4   r5   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   r4   r4   r5   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dddg d S )	Nr   Tr   r   r   r   r   r   r   r   r4   r4   r5   test_fetch_offset_percent_tiese  s      z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r4   F)r4   )0rP   rQ   rR   rS   rT   r6   rA   rK   r   r   r   r   rL   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   r4   r4   r4   r5   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 )JoinTestTr4   c              	   C   s0   t j }t||| | W 5 Q R X d S rB   rC   r   r4   r4   r5   rK   w  s    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   r1   r4   r4   r5   r6   {  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   r\   rf   )r+   r   )r<   r=   r   r>   r   r?   r4   r4   r5   rA     s    
 
zJoinTest.insert_datac                 C   sN   |  dd\}}t|||||jj|jj}| |ddddg d S Nr   r   )r7   r7   r7   )r7   r   r7   )r   r\   r   )r   rf   r   r=   r   select_fromjoinrM   rN   r+   rK   rH   r   r   rs   r4   r4   r5   test_inner_join_fk  s    &zJoinTest.test_inner_join_fkc                 C   sn   |  dd\}}t||||t |jj|jj}| |dd t	
ddddd	gd
dddgD  d S )Nr   r   c                 S   s    g | ]\\}\}}|||fqS r4   r4   ).0r   r   rN   r4   r4   r5   
<listcomp>  s   z1JoinTest.test_inner_join_true.<locals>.<listcomp>r_   r`   ra   r\   re   )r7   r7   r   )r\   r   )rf   r   )r=   r   r   r   r    rM   rN   r+   rK   	itertoolsproductr   r4   r4   r5   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   rM   rN   r+   rK   r   r4   r4   r5   test_inner_join_false  s    
 zJoinTest.test_inner_join_falsec                 C   sT   |  dd\}}t||||t |jj|jj}| |dddddg d S )Nr   r   )r7   NN)r   NN)r   NN)r\   NN)rf   NN)	r=   r   r   Z	outerjoinr   rM   rN   r+   rK   r   r4   r4   r5   test_outer_join_false  s"    
 zJoinTest.test_outer_join_falsec                 C   sN   |  dd\}}t|||||jj|jj}| |ddddg d S r   r   r   r4   r4   r5   test_outer_join_fk  s    &zJoinTest.test_outer_join_fkN)r4   )rP   rQ   rR   rS   rK   rT   r6   rA   r   r   r   r   r   r4   r4   r4   r5   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   s*   t d|tdtddtdttdt d S r|   r}   r1   r4   r4   r5   r6     s    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   r\   rf   r;   r?   r4   r4   r5   rA     s    




zCompoundSelectTest.insert_datar4   c              	   C   s0   t j }t||| | W 5 Q R X d S rB   rC   r   r4   r4   r5   rK     s    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   whererN   r+   r#   rK   rM   selected_columnsrH   r   s1s2u1r4   r4   r5   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   rN   r+   r#   aliasrK   rM   r   r   r4   r4   r5   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   r7   r   r   r   )r=   r*   r   r   rN   r+   r   rM   r#   rK   r   r   r4   r4   r5   &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   rN   r+   rM   r#   r   rK   r   r   r4   r4   r5   "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   rN   r+   distinctr#   r   rK   rM   r   r   r4   r4   r5   "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   rN   r+   r   rM   r#   r   rK   r   r4   r4   r5   &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   rN   r+   r   rM   r   r#   rK   r   r   r4   r4   r5   .test_limit_offset_aliased_selectable_in_unions6  s,    

	

	 zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsN)r4   )rP   rQ   rR   rS   rT   r6   rA   rK   r   r   r   rL   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   r4   r4   r4   r5   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   s6   t d|tdtddtdttdttdtd d S 	Nr*   r+   Tr,   rV   rW   zrY   r0   r1   r4   r4   r5   r6   V  s    z#PostCompileParamsTest.define_tablesc                 C   sH   | | 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+   rV   rW   r   r   z2r\   z3rf   z4r;   r?   r4   r4   r5   rA   a  s    
z!PostCompileParamsTest.insert_datac                 C   s<   | j j}t|jj|jjtdddk}| |di  d S )NrX   Tliteral_executezKSELECT some_table.id FROM some_table WHERE some_table.x = __[POSTCOMPILE_q]	r=   r*   r   rN   r+   r   rV   r   assert_compilerH   r   rs   r4   r4   r5   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 )NrX   r   Tr   z<SELECT some_table.id FROM some_table WHERE some_table.x = 10)r   r   r  r4   r4   r5   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 5 Q R X W 5 Q R X |tdt	j
jjr|dni  d S )NrX   Tr   r   rX   z>SELECT some_table.id 
FROM some_table 
WHERE some_table.x = 10r4   )r=   r*   r   rN   r+   r   rV   r   sql_execution_asserterr   rD   rE   r<   dictassert_r
   r   
positionalrH   r   rs   ZasserterrJ   r4   r4   r5   test_execute  s    
&z"PostCompileParamsTest.test_executec              
   C   s   | j j}t|jj|jjtdddd}| 	 4}t
j }||tdddgd W 5 Q R X W 5 Q R X |tdt
jjjrd	ni  d S )
NrX   T	expandingr   rf   r   rh   r  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r4   )r=   r*   r   rN   r+   r   rV   r	   r   r  r   rD   rE   r<   r  r  r
   r   r  r	  r4   r4   r5   +test_execute_expanding_plus_literal_execute  s    
,zAPostCompileParamsTest.test_execute_expanding_plus_literal_executec              
   C   s   | j j}t|jjt|jj|jj	t
dddd}|  2}tj }||tddgd W 5 Q R X W 5 Q R X |tdtjjjrdnd	 tjjjrd
ni  d S )NrX   Tr  )rf   r   )      r  zbSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.y) IN (%s(5, 10), (12, 18))VALUES  r4   )r=   r*   r   rN   r+   r   r!   rV   rW   r	   r   r  r   rD   rE   r<   r  r  r
   r   tuple_in_valuesr  r	  r4   r4   r5   1test_execute_tuple_expanding_plus_literal_execute  s"    
*zGPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_executec              
   C   s   | j j}t|jjt|jj|jj	t
dddd}|  2}tj }||tddgd W 5 Q R X W 5 Q R X |tdtjjjrdnd	 tjjjrd
ni  d S )NrX   Tr  )rf   r   )r  r   r  zfSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.z) IN (%s(5, 'z1'), (12, 'z3'))r  r  r4   )r=   r*   r   rN   r+   r   r!   rV   r   r	   r   r  r   rD   rE   r<   r  r  r
   r   r  r  r	  r4   r4   r5   ?test_execute_tuple_expanding_plus_literal_heterogeneous_execute  s"    
*zUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rP   rQ   rR   rS   rz   rT   r6   rA   r  r  r
  r  r   rL   tuple_inr  r  r4   r4   r4   r5   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   s6   t d|tdtddtdttdttdtd d S r   r0   r1   r4   r4   r5   r6     s    z"ExpandingBoundInTest.define_tablesc                 C   sH   | | 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 r   r;   r?   r4   r4   r5   rA     s    
z ExpandingBoundInTest.insert_datar4   c              	   C   s0   t j }t||| | W 5 Q R X d S rB   rC   r   r4   r4   r5   rK     s    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 )NrX   rZ   )rX   rZ   r   )r=   r*   r   rN   r+   r   rV   r	   r   rW   rM   rK   r  r4   r4   r5   "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 rB   )r=   r*   r   rN   r+   r   rV   r	   rW   rM   rK   r  r4   r4   r5   test_multiple_empty_sets_direct
  s    z4ExpandingBoundInTest.test_multiple_empty_sets_directc                 C   sT   | j j}t|jjt|jj|jj	t
d|jj}| j|g dg id d S NrX   r   r=   r*   r   rN   r+   r   r!   rV   r   r	   r   rM   rK   r  r4   r4   r5   )test_empty_heterogeneous_tuples_bindparam  s    z>ExpandingBoundInTest.test_empty_heterogeneous_tuples_bindparamc                    sD    j j fdd}|g g  |dddgdddg |g g  d S )	Nc                    s@   t jjtjjjj| jj} 	|| d S rB   )
r   rN   r+   r   r!   rV   r   r	   rM   rK   valr   rs   rH   r   r4   r5   go$  s    zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.gor   r   r   r   r\   r   r`   ra   r   r=   r*   rH   r  r4   r  r5   &test_empty_heterogeneous_tuples_direct   s
    
z;ExpandingBoundInTest.test_empty_heterogeneous_tuples_directc                 C   sT   | j j}t|jjt|jj|jj	t
d|jj}| j|g dg id d S r  r=   r*   r   rN   r+   r   r!   rV   rW   r	   r   rM   rK   r  r4   r4   r5   'test_empty_homogeneous_tuples_bindparam0  s    z<ExpandingBoundInTest.test_empty_homogeneous_tuples_bindparamc                    sD    j j fdd}|g g  |dddgdddg |g g  d S )	Nc                    s@   t jjtjjjj| jj} 	|| d S rB   )
r   rN   r+   r   r!   rV   rW   r	   rM   rK   r  r  r4   r5   r  >  s    zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go)r7   r   r   r   r   r\   r_   r`   ra   r#  r$  r4   r  r5   $test_empty_homogeneous_tuples_direct:  s
    
z9ExpandingBoundInTest.test_empty_homogeneous_tuples_directc                 C   sV   | j j}t|jj|jjtd	|jj}| j
|dddgddddgid d S )	NrX   r`   ra   r   r   r   r\   r   r=   r*   r   rN   r+   r   rV   r	   r   rM   rK   r  r4   r4   r5   test_bound_in_scalar_bindparamJ  s    z3ExpandingBoundInTest.test_bound_in_scalar_bindparamc                 C   sJ   | j j}t|jj|jjdddg|jj}| 	|dddg d S )Nr   r   r\   r`   ra   r   
r=   r*   r   rN   r+   r   rV   r	   rM   rK   r  r4   r4   r5   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   r`   ra   r=   r*   r   rN   r+   r   rV   r	   not_inrM   rK   r  r4   r4   r5   !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   r/  r  r4   r4   r5   !test_empty_in_plus_notempty_notinf  s    z6ExpandingBoundInTest.test_empty_in_plus_notempty_notinc                 C   s<   t dtdtdd}| j|dddgddd	d
g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 idrX   Ttype_r  r`   ra   r   r   r   r   r   N)r   
bindparamsr   r   rK   rH   rs   r4   r4   r5   test_typed_str_inp  s    z&ExpandingBoundInTest.test_typed_str_inc                 C   s:   t dtddd}| j|dddgddd	d
g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....

        r3  rX   Tr  r`   ra   r   r   r   r   r   Nr   r6  r   rK   r7  r4   r4   r5   test_untyped_str_in  s    	
z(ExpandingBoundInTest.test_untyped_str_inc                 C   s`   | j j}t|jjt|jj|jj	t
d|jj}| j|dddgddddgid d S )	NrX   r`   ra   r   r(  r)  r\   rf   r   r&  r  r4   r4   r5   !test_bound_in_two_tuple_bindparam  s      z6ExpandingBoundInTest.test_bound_in_two_tuple_bindparamc                 C   sT   | j j}t|jjt|jj|jj	dddg
|jj}| |dddg d S )Nr(  r)  r<  r`   ra   r   )r=   r*   r   rN   r+   r   r!   rV   rW   r	   rM   rK   r  r4   r4   r5   test_bound_in_two_tuple_direct  s    z3ExpandingBoundInTest.test_bound_in_two_tuple_directc                 C   s`   | j j}t|jjt|jj|jj	t
d|jj}| j|dddgddddgid d S )	NrX   r`   ra   r   r   r!  r"  r   r  r  r4   r4   r5   /test_bound_in_heterogeneous_two_tuple_bindparam  s    zDExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_bindparamc                 C   sT   | j j}t|jjt|jj|jj	dddg
|jj}| |dddg d S )Nr   r!  r"  r`   ra   r   )r=   r*   r   rN   r+   r   r!   rV   r   r	   rM   rK   r  r4   r4   r5   ,test_bound_in_heterogeneous_two_tuple_direct  s    	zAExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_directc                 C   s:   t dtddd}| j|dddgddd	d
gid d S )N8select id FROM some_table WHERE (x, z) IN :q ORDER BY idrX   Tr9  r`   ra   r   r   r!  r"  r   r:  r7  r4   r4   r5   4test_bound_in_heterogeneous_two_tuple_text_bindparam  s    
zIExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparamc              	   C   sj   G dd dt j}tdtdtt t dd}| j|ddd	gd|d
d|dd|ddgid d S )Nc                   @   s,   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   s
   || _ d S rB   _datarH   r.   r4   r4   r5   __init__  s    zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS rB   iterrD  rH   r4   r4   r5   __iter__  s    zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S rB   rC  rH   idxr4   r4   r5   __getitem__  s    ztExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS rB   r   rD  rI  r4   r4   r5   __len__  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrP   rQ   rR   rF  rJ  rM  rO  r4   r4   r4   r5   
LikeATuple  s   rQ  rA  rX   Tr4  r`   ra   r   r   r   r   r   r\   r   r   )	r(   Sequencer   r6  r   r"   r   r   rK   rH   rQ  rs   r4   r4   r5   ?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|ddd	gd|d
d|dd|ddgid d S )Nc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
zgExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuplec                 W   s
   || _ d S rB   rC  rE  r4   r4   r5   rF    s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS rB   rG  rI  r4   r4   r5   rJ     s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S rB   rC  rK  r4   r4   r5   rM    s    zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS rB   rN  rI  r4   r4   r5   rO    s    zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__NrP  r4   r4   r4   r5   rQ    s   rQ  rA  rX   Tr9  r`   ra   r   r   r   r   r   r\   r   r   )r(   rR  r   r6  r   rK   rS  r4   r4   r5   >test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple  s     
zSExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuplec                 C   sJ   | j j}t|jj|jjtd	|jj}| j
|g dg id d S r  r+  r  r4   r4   r5   (test_empty_set_against_integer_bindparam  s    z=ExpandingBoundInTest.test_empty_set_against_integer_bindparamc                 C   s>   | j j}t|jj|jjg |jj}| 	|g  d S rB   r-  r  r4   r4   r5   %test_empty_set_against_integer_direct!  s    &z:ExpandingBoundInTest.test_empty_set_against_integer_directc                 C   sR   | j j}t|jj|jjtd	|jj}| j
|ddddgdg id d S NrX   r_   r`   ra   r   r   )r=   r*   r   rN   r+   r   rV   r0  r   rM   rK   r  r4   r4   r5   1test_empty_set_against_integer_negation_bindparam&  s    zFExpandingBoundInTest.test_empty_set_against_integer_negation_bindparamc                 C   sF   | j j}t|jj|jjg |jj}| 	|ddddg d S Nr_   r`   ra   r   )
r=   r*   r   rN   r+   r   rV   r0  rM   rK   r  r4   r4   r5   .test_empty_set_against_integer_negation_direct/  s    $zCExpandingBoundInTest.test_empty_set_against_integer_negation_directc                 C   sJ   | j j}t|jj|jjtd	|jj}| j
|g dg id d S r  )r=   r*   r   rN   r+   r   r   r	   r   rM   rK   r  r4   r4   r5   'test_empty_set_against_string_bindparam6  s    z<ExpandingBoundInTest.test_empty_set_against_string_bindparamc                 C   s>   | j j}t|jj|jjg |jj}| 	|g  d S rB   )
r=   r*   r   rN   r+   r   r   r	   rM   rK   r  r4   r4   r5   $test_empty_set_against_string_direct?  s    &z9ExpandingBoundInTest.test_empty_set_against_string_directc                 C   sR   | j j}t|jj|jjtd	|jj}| j
|ddddgdg id d S rX  )r=   r*   r   rN   r+   r   r   r0  r   rM   rK   r  r4   r4   r5   0test_empty_set_against_string_negation_bindparamD  s    zEExpandingBoundInTest.test_empty_set_against_string_negation_bindparamc                 C   sF   | j j}t|jj|jjg |jj}| 	|ddddg d S rZ  )
r=   r*   r   rN   r+   r   r   r0  rM   rK   r  r4   r4   r5   -test_empty_set_against_string_negation_directM  s    $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foor4   )valueZelse_r   Fr   )	r   r   r   r	   r   r    r   r<   fetchonerH   r@   rs   r4   r4   r5   )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 )Nrb  r   rc  )r   r   r   r	   r    r   r<   rd  re  r4   r4   r5   &test_null_in_empty_set_is_false_direct`  s    
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directN)r4   ))rP   rQ   rR   rS   rT   r6   rA   rK   r  r  r   rL   Ztuple_in_w_emptyr  r%  r'  r*  r,  r.  r1  r2  r8  r;  r  r=  r>  r?  r@  rB  rT  rU  rV  rW  rY  r[  r\  r]  r^  r_  rf  rg  r4   r4   r4   r5   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*d+d,d-d.hfd/d+d,d-d.d0hfd1d+d,d-d.d0hfd2d3hfd4ee d+d5fd6ee d+d5fd7e fd8d9 Z!dS ):LikeFunctionsTestTonceNc                 C   s&   t d|tdtddtdtd d S )Nr*   r+   Tr,   r.   rY   r0   r1   r4   r4   r5   r6   s  s    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%cdefgr\   Zab_cdefgrf   zabcde/fgr   zabcde%fgrh   zab#cdefg   Zab9cdefg	   zabcde#fgr   Zabcd9fg   r;   r?   r4   r4   r5   rA   |  s    
zLikeFunctionsTest.insert_datac              	   C   sN   | j j}tj (}dd |t|jj	|D }W 5 Q R X t
|| d S )Nc                 S   s   h | ]
\}|qS r4   r4   )r   ra  r4   r4   r5   	<setcomp>  s   z*LikeFunctionsTest._test.<locals>.<setcomp>)r=   r*   r   rD   rE   r<   r   rN   r+   r   r   )rH   rr   r   r*   rJ   Zrowsr4   r4   r5   _test  s    zLikeFunctionsTest._testc                 C   s6   | j jjj}| |ddddddddd	d
dh
 d S )Nab%cr7   r   r   r\   rf   r   rh   rj  rk  r   r=   r*   rN   r.   rn  
startswithrH   colr4   r4   r5   test_startswith_unescaped  s    z+LikeFunctionsTest.test_startswith_unescapedc                 C   s(   | j jjj}| |jddddh d S )Nro  T
autoescaper   rp  rr  r4   r4   r5   test_startswith_autoescape  s    z,LikeFunctionsTest.test_startswith_autoescapec                 C   s:   | j jjj}| |tddddddddd	d
dh
 d S )Nz'ab%c'r7   r   r   r\   rf   r   rh   rj  rk  r   )r=   r*   rN   r.   rn  rq  r   rr  r4   r4   r5   test_startswith_sqlexpr  s
    z)LikeFunctionsTest.test_startswith_sqlexprc                 C   s(   | j jjj}| |jddddh d S )Nzab##c#escaperh   rp  rr  r4   r4   r5   test_startswith_escape  s    z(LikeFunctionsTest.test_startswith_escapec                 C   sD   | j jjj}| |jdddddh | |jdddddh d S )Nro  Try  rv  r{  r   zab#crh   rp  rr  r4   r4   r5   !test_startswith_autoescape_escape  s    z3LikeFunctionsTest.test_startswith_autoescape_escapec                 C   s4   | j jjj}| |ddddddddd	d
h	 d S )Ne%fgr7   r   r   r\   rf   r   rh   rj  rk  r=   r*   rN   r.   rn  endswithrr  r4   r4   r5   test_endswith_unescaped  s    z)LikeFunctionsTest.test_endswith_unescapedc                 C   s8   | j jjj}| |tddddddddd	d
h	 d S )Nz'e%fg'r7   r   r   r\   rf   r   rh   rj  rk  )r=   r*   rN   r.   rn  r  r   rr  r4   r4   r5   test_endswith_sqlexpr  s
     z'LikeFunctionsTest.test_endswith_sqlexprc                 C   s(   | j jjj}| |jddddh d S )Nr  Tru  r   r  rr  r4   r4   r5   test_endswith_autoescape  s    z*LikeFunctionsTest.test_endswith_autoescapec                 C   s(   | j jjj}| |jddddh d S )Nze##fgry  rz  rk  r  rr  r4   r4   r5   test_endswith_escape  s    z&LikeFunctionsTest.test_endswith_escapec                 C   sD   | j jjj}| |jdddddh | |jdddddh d S )Nr  Try  r}  r   ze#fgrk  r  rr  r4   r4   r5   test_endswith_autoescape_escape  s    z1LikeFunctionsTest.test_endswith_autoescape_escapec                 C   s4   | j jjj}| |ddddddddd	d
h	 d S )Nb%cder7   r   r   r\   rf   r   rh   rj  rk  r=   r*   rN   r.   rn  containsrr  r4   r4   r5   test_contains_unescaped  s    z)LikeFunctionsTest.test_contains_unescapedc                 C   s(   | j jjj}| |jddddh d S )Nr  Tru  r   r  rr  r4   r4   r5   test_contains_autoescape  s    z*LikeFunctionsTest.test_contains_autoescapec                 C   s(   | j jjj}| |jddddh d S )Nzb##cdery  rz  rh   r  rr  r4   r4   r5   test_contains_escape  s    z&LikeFunctionsTest.test_contains_escapec                 C   sD   | j jjj}| |jdddddh | |jdddddh d S )Nzb%cdTry  r}  r   zb#cdrh   r  rr  r4   r4   r5   test_contains_autoescape_escape  s    z1LikeFunctionsTest.test_contains_autoescape_escapec              	   C   s0   | j jjj}| |d ddddddh d S )Na.cder   r   r\   rh   rj  r   r=   r*   rN   r.   rn  regexp_matchrr  r4   r4   r5   test_not_regexp_match  s    z'LikeFunctionsTest.test_not_regexp_matchc                 C   s2   | j jjj}| |dddddddh d S )Nr  ZFOOr7   rf   r   rk  )r=   r*   rN   r.   rn  regexp_replacer  rr  r4   r4   r5   test_regexp_replace  s
     
z%LikeFunctionsTest.test_regexp_replacer  r7   rf   r   rk  abcr   z^abcZ9cderj  z^arl  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S rB   r  )rH   r   r   rs  r4   r4   r5   test_regexp_match  s    z#LikeFunctionsTest.test_regexp_match)"rP   rQ   rR   rS   run_insertsrun_deletesrT   r6   rA   rn  rt  rw  rx  r|  r~  r  r  r  r  r  r  r  r  r  r   rL   r  r  r  r  r   r   ranger  r4   r4   r4   r5   rh  m  sJ   



	rh  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   r1   r4   r4   r5   r6     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?   r4   r4   r5   rA     s    
zComputedColumnTest.insert_datac              	   C   sV   t j B}|ttd| jj	| jjj
j }t|ddg W 5 Q R X d S )N*)r7   r   r/   r   )r   r       )r   rD   rE   r<   r   r   r   r=   r  rM   rN   r+   rF   r   rH   rJ   resr4   r4   r5   test_select_all  s    
z"ComputedColumnTest.test_select_allc              	   C   sd   t j P}|t| jjjj| jjjj	
| jj| jjjj }t|ddg W 5 Q R X d S )N)r/   r   )r  r  )r   rD   rE   r<   r   r=   r  rN   r  r  r   rM   r+   rF   r   r  r4   r4   r5   test_select_columns  s    
 

z&ComputedColumnTest.test_select_columnsN)
rP   rQ   rR   rS   rz   rT   r6   rA   r  r  r4   r4   r4   r5   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_columnsri  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,   rl   r/   tbl_br   i)	incrementr  ZminvalueZmaxvaluer   r   r   r   r   r1   r4   r4   r5   r6   &  s6       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 )Nrl   r   r   r  rN   r+   rl   )r<   r=   r  r>   r  r?   r4   r4   r5   rA   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
|dddg d S )Nr  )r  r   )+   r   )r  r   )r   r   )r  rN   )r<   r   r   r   r=   r  rM   rN   r+   rF   r   r  rH   r@   r  r4   r4   r5   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  rN   r+   rM   rF   r   r  r4   r4   r5   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>   r4   r@   rH   r4   r5   fnh  s    

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r&   r'   )rH   r@   r  r4   r  r5   test_insert_always_errorf  s    z+IdentityColumnTest.test_insert_always_errorN)rP   rQ   rR   rS   rz   r  r  rT   r6   rA   r  r  r   rL   Zidentity_columns_standardr  r4   r4   r4   r5   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autoincrementrl   r/   r  r1   r4   r4   r5   r6   u  s    z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi}| | jj  }t|d d S )Nrl   row)r7   r  )r<   r=   r  r>   r   firstr   r  r4   r4   r5    test_autoincrement_with_identity  s    z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rP   rQ   rR   rS   rz   rT   r6   r  r4   r4   r4   r5   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   s&   t d|tdtddtdtd d S )Nstuffr+   Tr,   r.   rY   r0   r1   r4   r4   r5   r6     s    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   r\   zsome other data)r<   r=   r  r>   r?   r4   r4   r5   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  r_   r=   r  r   r<   r   r   r   r   rN   r.   rF   rH   r@   r  r4   r4   r5   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  r4   r4   r5   test_select_exists_false  s    z#ExistsTest.test_select_exists_falseN)	rP   rQ   rR   rS   rT   r6   rA   r  r  r4   r4   r4   r5   r    s   

r  c                   @   s&   e Zd ZdZeejjdd ZdS )DistinctOnTestTc              	   C   sB   t dtdtd}td | |d W 5 Q R X d S )Nr  rX   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   )rH   Zstmr4   r4   r5   test_distinct_on  s
    zDistinctOnTest.test_distinct_onN)	rP   rQ   rR   rS   r   Zfails_ifrL   Zsupports_distinct_onr  r4   r4   r4   r5   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}   r1   r4   r4   r5   r6     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rbdnd}|| |jj|jj	
 }tt|| d S )Nr7   )r+   r  r  r   )r=   r  r<   r>   r   r   rN   r  Zis_distinct_fromr  rF   r   r   Zis_not_distinct_from)rH   Zcol_a_valueZcol_b_valueZexpected_row_count_for_isr@   r  rI   Zexpected_row_count_for_is_notr4   r4   r5   test_is_or_is_not_distinct_from  s*    z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rP   rQ   rR   rS   rz   rT   r6   r   r   r  r4   r4   r4   r5   r    s   
		r  )<r   r  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)   rU   ZTestBaserv   r{   r   r   r   r  rh  r  r  r  r  r  r  r4   r4   r4   r5   <module>   s   &M   Jdw
       	+Q/