U
    r\j                     @   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   [/root/pica-gateway/venv/lib/python3.8/site-packages/sqlalchemy/testing/suite/test_select.pydefine_tables3   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_data<   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_resultF   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collateasc)rH   Z	collationr4   r4   r5   test_collate_order_byJ   s    z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr6   rA   rK   r   rL   Zorder_by_collationrP   r4   r4   r4   r5   r)   0   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   a   s    zOrderByLabelTest.define_tablesc                 C   sB   | | jj ddddddddddddddd	d
ddg d S )Nr7   r   q1Zp3)r+   rW   rX   rY   r[   r   q2Zp2   Zq3p1r;   r?   r4   r4   r5   rA   m   s    
zOrderByLabelTest.insert_datac              	   C   s.   t j }t|| | W 5 Q R X d S rB   rC   rG   r4   r4   r5   rK   x   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   rW   labelrK   r   rM   rH   r   r`   r4   r4   r5   
test_plain|   s    zOrderByLabelTest.test_plainc                 C   s>   | j j}|jj|jj d}| t||dddg d S )Nr`   rc         )	r=   r*   rN   rW   rX   rd   rK   r   rM   re   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q1p3rh   Zq2p2rj   Zq3p1)r=   r*   rN   rW   rX   rd   r   lowerrY   r[   rK   r   rM   descr$   u)rH   r   r`   rl   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`   rc   rb   ra   )	r=   r*   rN   rW   rd   rK   r   rM   rn   re   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`   ri   rg   rc   )
r=   r*   rN   rW   rX   rd   rK   r   rM   rn   re   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   rh   )r7   rj   )r=   r*   rN   rW   rX   rd   r   r   countr+   Zgroup_byrM   rK   )rH   r   exprstmtr4   r4   r5   test_group_by_composed   s
    z'OrderByLabelTest.test_group_by_composedN)rQ   rR   rS   __doc__rT   rU   r6   rA   rK   rf   rk   rp   rq   rr   r   rL   Zgroup_by_complex_expressionrv   r4   r4   r4   r5   rV   V   s   


	rV   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)ry   )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)rQ   rR   rS   __requires__rT   r{   r4   r4   r4   r5   rx      s   rx   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,   rW   rX   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+   rW   rX   r   r^   rh      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   ru   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   ra   )
r=   r*   r   rN   r+   r   Zscalar_subqueryr#   ZsubqueryrK   )rH   r@   r   ru   ro   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^   rh   rh   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_order8  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_zeroB  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   ru   sqlr4   r4   r5   test_limit_offset_nobindsQ  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_nobinds^  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_limitk  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_offset|  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   rW   rn   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   rW   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   rW   r   r   r   r4   r4   r5   #test_fetch_offset_ties_exact_number2  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_percentH  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_percentQ  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_ties^  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_tiesk  s      z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r4   F)r4   )0rQ   rR   rS   rT   rU   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   }  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^   rh   )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   rh   r   r=   r   select_fromjoinrM   rN   r+   rK   rH   r   r   ru   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>ra   rb   rc   r^   rg   )r7   r7   r   )r^   r   )rh   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)rh   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   )rQ   rR   rS   rT   rK   rU   r6   rA   r   r   r   r   r   r4   r4   r4   r5   r   z  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^   rh   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_alias0  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_unions<  s,    

	

	 zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsN)r4   )rQ   rR   rS   rT   rU   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,   rW   rX   zrZ   r0   r1   r4   r4   r5   r6   \  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+   rW   rX   r   r   z2r^   z3rh   z4r;   r?   r4   r4   r5   rA   g  s    
z!PostCompileParamsTest.insert_datac                 C   s<   | j j}t|jj|jjtdddk}| |di  d S )NrY   Tliteral_executezKSELECT some_table.id FROM some_table WHERE some_table.x = __[POSTCOMPILE_q]	r=   r*   r   rN   r+   r   rW   r   assert_compilerH   r   ru   r4   r4   r5   test_compiles  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 )NrY   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 )NrY   Tr   r   rY   z>SELECT some_table.id 
FROM some_table 
WHERE some_table.x = 10r4   )r=   r*   r   rN   r+   r   rW   r   sql_execution_asserterr   rD   rE   r<   dictassert_r
   r   
positionalrH   r   ru   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 )
NrY   T	expandingr  rh   r   rj   r  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r4   )r=   r*   r   rN   r+   r   rW   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 )NrY   Tr  )rh   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!   rW   rX   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 )NrY   Tr  )rh   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!   rW   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)rQ   rR   rS   rT   r|   rU   r6   rA   r  r  r  r  r   rL   tuple_inr  r  r4   r4   r4   r5   r   U  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 )NrY   r[   )rY   r[   r   )r=   r*   r   rN   r+   r   rW   r	   r   rX   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   rW   r	   rX   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 NrY   r   r=   r*   r   rN   r+   r   r!   rW   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!   rW   r   r	   rM   rK   valr   ru   rH   r   r4   r5   go*  s    zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.gor   r   r   r   r^   r   rb   rc   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!   rW   rX   r	   r   rM   rK   r  r4   r4   r5   'test_empty_homogeneous_tuples_bindparam6  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!   rW   rX   r	   rM   rK   r  r!  r4   r5   r"  D  s    zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go)r7   r   r   r   r   r^   ra   rb   rc   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 )	NrY   rb   rc   r   r   r   r^   r   r=   r*   r   rN   r+   r   rW   r	   r   rM   rK   r  r4   r4   r5   test_bound_in_scalar_bindparamP  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^   rb   rc   r   
r=   r*   r   rN   r+   r   rW   r	   rM   rK   r  r4   r4   r5   test_bound_in_scalar_directY  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   rb   rc   r=   r*   r   rN   r+   r   rW   r	   not_inrM   rK   r  r4   r4   r5   !test_nonempty_in_plus_empty_notinb  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   r2  r  r4   r4   r5   !test_empty_in_plus_notempty_notinl  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 idrY   Ttype_r  rb   rc   r   r   r   r   r   N)r   
bindparamsr   r   rK   rH   ru   r4   r4   r5   test_typed_str_inv  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....

        r6  rY   Tr  rb   rc   r   r   r   r   r   Nr   r9  r   rK   r:  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 )	NrY   rb   rc   r   r+  r,  r^   rh   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?  rb   rc   r   )r=   r*   r   rN   r+   r   r!   rW   rX   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 )	NrY   rb   rc   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%  rb   rc   r   )r=   r*   r   rN   r+   r   r!   rW   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 idrY   Tr<  rb   rc   r   r#  r$  r%  r   r=  r:  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   iterrG  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   rF  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   rG  rL  r4   r4   r5   __len__  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrQ   rR   rS   rI  rM  rP  rR  r4   r4   r4   r5   
LikeATuple  s   rT  rD  rY   Tr7  rb   rc   r   r   r   r   r   r^   r   r   )	r(   Sequencer   r9  r   r"   r   r   rK   rH   rT  ru   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   rF  rH  r4   r4   r5   rI    s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS rB   rJ  rL  r4   r4   r5   rM    s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S rB   rF  rN  r4   r4   r5   rP  	  s    zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS rB   rQ  rL  r4   r4   r5   rR    s    zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__NrS  r4   r4   r4   r5   rT    s   rT  rD  rY   Tr<  rb   rc   r   r   r   r   r   r^   r   r   )r(   rU  r   r9  r   rK   rV  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   r0  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 NrY   ra   rb   rc   r   r   )r=   r*   r   rN   r+   r   rW   r3  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 Nra   rb   rc   r   )
r=   r*   r   rN   r+   r   rW   r3  rM   rK   r  r4   r4   r5   .test_empty_set_against_integer_negation_direct5  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_bindparam<  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_directE  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 r[  )r=   r*   r   rN   r+   r   r   r3  r   rM   rK   r  r4   r4   r5   0test_empty_set_against_string_negation_bindparamJ  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 r]  )
r=   r*   r   rN   r+   r   r   r3  rM   rK   r  r4   r4   r5   -test_empty_set_against_string_negation_directS  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@   ru   r4   r4   r5   )test_null_in_empty_set_is_false_bindparamZ  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 )Nre  r   rf  )r   r   r   r	   r    r   r<   rg  rh  r4   r4   r5   &test_null_in_empty_set_is_false_directf  s    
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directN)r4   ))rQ   rR   rS   rT   rU   r6   rA   rK   r  r  r   rL   Ztuple_in_w_emptyr  r(  r*  r-  r/  r1  r4  r5  r;  r>  r  r@  rA  rB  rC  rE  rW  rX  rY  rZ  r\  r^  r_  r`  ra  rb  ri  rj  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.   rZ   r0   r1   r4   r4   r5   r6   y  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_cdefgrh   zabcde/fgr   zabcde%fgrj   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   rd  r4   r4   r5   	<setcomp>  s   z*LikeFunctionsTest._test.<locals>.<setcomp>)r=   r*   r   rD   rE   r<   r   rN   r+   r   r   )rH   rt   r   r*   rJ   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^   rh   r   rj   rm  rn  r   r=   r*   rN   r.   rr  
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 )Nrs  T
autoescaper   rt  rv  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^   rh   r   rj   rm  rn  r   )r=   r*   rN   r.   rr  ru  r   rv  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#escaperj   rt  rv  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 )Nrs  Tr}  rz  r  r   zab#crj   rt  rv  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^   rh   r   rj   rm  rn  r=   r*   rN   r.   rr  endswithrv  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^   rh   r   rj   rm  rn  )r=   r*   rN   r.   rr  r  r   rv  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  Try  r   r  rv  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##fgr}  r~  rn  r  rv  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  Tr}  r  r   ze#fgrn  r  rv  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^   rh   r   rj   rm  rn  r=   r*   rN   r.   rr  containsrv  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  Try  r   r  rv  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##cder}  r~  rj   r  rv  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%cdTr}  r  r   zb#cdrj   r  rv  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^   rj   rm  r   r=   r*   rN   r.   rr  regexp_matchrv  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   rh   r   rn  )r=   r*   rN   r.   rr  regexp_replacer  rv  r4   r4   r5   test_regexp_replace  s
     
z%LikeFunctionsTest.test_regexp_replacer  r7   rh   r   rn  abcr   z^abcZ9cderm  z^aro  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S rB   r  )rH   r   r   rw  r4   r4   r5   test_regexp_match  s    z#LikeFunctionsTest.test_regexp_match)"rQ   rR   rS   rT   run_insertsrun_deletesrU   r6   rA   rr  rx  r{  r|  r  r  r  r  r  r  r  r  r  r  r  r   rL   r  r  r  r  r   r   ranger  r4   r4   r4   r5   rk  s  sJ   



	rk  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)
rQ   rR   rS   rT   r|   rU   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_columnsrl  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,   rn   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 )Nrn   r   r   r  rN   r+   rn   )r<   r=   r  r>   r  r?   r4   r4   r5   rA   G  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  V  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  e  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   fnn  s    

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r&   r'   )rH   r@   r  r4   r  r5   test_insert_always_errorl  s    z+IdentityColumnTest.test_insert_always_errorN)rQ   rR   rS   rT   r|   r  r  rU   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autoincrementrn   r/   r  r1   r4   r4   r5   r6   {  s    z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi}| | jj  }t|d d S )Nrn   row)r7   r  )r<   r=   r  r>   r   firstr   r  r4   r4   r5    test_autoincrement_with_identity  s    z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rQ   rR   rS   rT   r|   rU   r6   r  r4   r4   r4   r5   r  w  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.   rZ   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  ra   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)	rQ   rR   rS   rT   rU   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  rY   rc  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)	rQ   rR   rS   rT   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)
rQ   rR   rS   rT   r|   rU   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)   rV   ZTestBaserx   r}   r   r   r   r  rk  r  r  r  r  r  r  r4   r4   r4   r5   <module>   s   &M   Jdw
       	+Q/