U
    ovg$                     @   s  d dl mZ d dlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	l	mZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddlm#Z# dd lm$Z$ dd!lm%Z% dd"lm&Z& dd#lm'Z' dd$lm(Z( dd%l)m*Z* dd&l)m+Z+ G d'd( d(ej,Z-G d)d* d*ej,Z.G d+d, d,ej/Z0G d-d. d.ej,Z1G d/d0 d0ej,Z2G d1d2 d2ej,Z3G d3d4 d4ej,Z4G d5d6 d6eeej,Z5G d7d8 d8ej,Z6G d9d: d:ej,Z7G d;d< d<ej,Z8G d=d> d>ej,Z9G d?d@ d@ej,Z:G dAdB dBej,Z;G dCdD dDeej,Z<G dEdF dFej,Z=G dGdH dHej,Z>G dIdJ dJej,Z?dS )K    N   )AssertsCompiledSQL)AssertsExecutionResults)config)fixtures)assert_raises)eq_)in_)	CursorSQL)Column)Table   )	bindparam)case)column)Computed)exists)false)
ForeignKey)func)Identity)Integer)literal)literal_column)null)select)String)table)testing)text)true)tuple_)	TupleType)union)values)DatabaseError)ProgrammingErrorc                   @   s@   e Zd ZdZedd Zedd Zdd Zej	j
dd	 Zd
S )CollateTestTc                 C   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 r2   H/tmp/pip-unpacked-wheel-uqd9otp_/sqlalchemy/testing/suite/test_select.pydefine_tables4   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r0   
connectionr2   r2   r3   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connr2   r2   r3   _assert_resultG   s    zCollateTest._assert_resultc                 C   sB   t jt j}| t| jj| jjj	j
| ddg d S )N)r5   r6   )r   r8   )r   requiresZget_order_by_collationr   rI   r   r;   r(   order_bycr,   ZcollateZasc)rF   Z	collationr2   r2   r3   test_collate_order_byK   s    z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr4   r?   rI   r   rJ   Zorder_by_collationrM   r2   r2   r2   r3   r'   1   s   

	r'   c                   @   sl   e Zd ZdZdZedd Zedd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zejjdd ZdS )OrderByLabelTestzTest the dialect sends appropriate ORDER BY expressions when
    labels are used.

    This essentially exercises the "supports_simple_order_by_label"
    setting.

    Tc                 C   sB   t d|tdtddtdttdttdtdtd	td d S )
Nr(   r)   Tr*   xyq2   pr.   r/   r2   r2   r3   r4   b   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 )Nr5   r   Zq1Zp3)r)   rT   rU   rV   rX   r   Zq2p2   Zq3p1r9   r=   r2   r2   r3   r?   n   s    
zOrderByLabelTest.insert_datac              	   C   s.   t j }t|| | W 5 Q R X d S r@   rA   rE   r2   r2   r3   rI   y   s    zOrderByLabelTest._assert_resultc                 C   s6   | j j}|jjd}| t||dddg d S )Nlxr5   r   r   )r;   r(   rL   rT   labelrI   r   rK   rF   r   r\   r2   r2   r3   
test_plain}   s    zOrderByLabelTest.test_plainc                 C   s>   | j j}|jj|jj d}| t||dddg d S )Nr\   r_         )	r;   r(   rL   rT   rU   r`   rI   r   rK   ra   r2   r2   r3   test_composed_int   s    z"OrderByLabelTest.test_composed_intc                 C   sb   | j j}|jj|jj d}t|jj|jj	 d}| 
t|||| dddg d S )Nr\   ly)r   Zq1p3)rd   Zq2p2)rf   Zq3p1)r;   r(   rL   rT   rU   r`   r   lowerrV   rX   rI   r   rK   desc)rF   r   r\   rh   r2   r2   r3   test_composed_multiple   s    z'OrderByLabelTest.test_composed_multiplec                 C   s:   | j j}|jjd}| t|| dddg d S )Nr\   r_   r^   r]   )	r;   r(   rL   rT   r`   rI   r   rK   rj   ra   r2   r2   r3   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\   re   rc   r_   )
r;   r(   rL   rT   rU   r`   rI   r   rK   rj   ra   r2   r2   r3   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\   )r5   r   )r5   rd   )r5   rf   )r;   r(   rL   rT   rU   r`   r   r   countr)   Zgroup_byrK   rI   )rF   r   exprstmtr2   r2   r3   test_group_by_composed   s
    z'OrderByLabelTest.test_group_by_composedN)rN   rO   rP   __doc__rQ   rR   r4   r?   rI   rb   rg   rk   rl   rm   r   rJ   Zgroup_by_complex_expressionrq   r2   r2   r2   r3   rS   W   s   


	rS   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)rt   )r5   Zname1)r   Zname2)r   Zname3)	r$   r   r   r   r,   r   r:   r   all)rF   r>   Z
value_exprr2   r2   r3   test_tuples   s      z ValuesExpressionTest.test_tuplesN)rN   rO   rP   __requires__rQ   rv   r2   r2   r2   r3   rs      s   rs   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*   rT   rU   r   r   r   r/   r2   r2   r3   r4      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 )Nr5   r   r)   rT   rU   r   rZ   rd      r9   r=   r2   r2   r3   r?      s    





z FetchLimitOffsetTest.insert_datar2   Fc                 C   sT   |r:| || }tt|t| tt|t| nt| || | d S r@   )r:   rD   r   lenset)rF   r>   r   rG   paramsset_Z	query_resr2   r2   r3   rI      s
    z#FetchLimitOffsetTest._assert_resultc              	   C   s0   t j }t||| | W 5 Q R X d S r@   )r   rB   rC   r   Zexec_driver_sqlrD   rF   r   rG   r   rH   r2   r2   r3   _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   r5   r5   r   r   r   r   r   r   r   rZ   )r;   r(   r   rK   rL   r)   rI   limit)rF   r>   r   rp   r2   r2   r3   test_simple_limit   s    z&FetchLimitOffsetTest.test_simple_limitc                 C   sL   | j j}t|jjd }tt|t|  }| 	||dg d S )Nr5   r]   )
r;   r(   r   rL   r)   r   Zscalar_subqueryr#   subqueryrI   )rF   r>   r   rp   ur2   r2   r3    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(   rI   r   rK   rL   r)   fetchrF   r>   r   r2   r2   r3   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   rZ   rZ   rd   rd   rZ   r|   r   r;   r(   rI   r   rK   rL   r)   offsetr   r2   r2   r3   test_simple_offset  s    z'FetchLimitOffsetTest.test_simple_offset)r   r   r   r5   )r   r   )r   r5   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_optionsrI   r   rK   rL   r)   r   r   )rF   r>   r   r   Zassert_datar   r   expectedr2   r2   r3   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   r5   r   r   r   r   r   	r;   r(   rI   r   rK   rL   r)   r   r   r   r2   r2   r3   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(   rI   r   r   r   r2   r2   r3   test_fetch_offset_no_order9  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   r5   r   r   r2   r2   r3   test_simple_offset_zeroC  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   r5   literal_bindsT)dialectcompile_kwargsr   r   N)r;   r(   r   rK   rL   r)   r   r   compiler   rB   r   strr   rF   r   rp   Zsqlr2   r2   r3   test_limit_offset_nobindsR  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   rK   rL   r)   r   r   r   r   rB   r   r   r   r   r2   r2   r3   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(   rI   r   rK   rL   r)   r   r   r   r2   r2   r3   test_bound_limitl  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   r5   )	r;   r(   rI   r   rK   rL   r)   r   r   r   r2   r2   r3   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   r5   )r   r   r   r   r   r   )
r;   r(   rI   r   rK   rL   r)   r   r   r   r   r2   r2   r3   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   r5   )r   r   r   r   r   r   )
r;   r(   rI   r   rK   rL   r)   r   r   r   r   r2   r2   r3   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(   rI   r   rK   rL   r)   r   r   r   r2   r2   r3   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(   rI   r   rK   rL   r)   r   r   r   r2   r2   r3   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(   rI   r   rK   rL   r)   r   r   r   r   r2   r2   r3   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(   rI   r   rK   rL   r)   r   r   r   r   r2   r2   r3   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(   rI   r   rK   rL   r)   r   r   r   r   r2   r2   r3   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   r5   r   r   r   r2   r2   r3   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 )	Nr5   T	with_tiesr   r   r   r   r   	r;   r(   rI   r   rK   rL   rT   rj   r   r   r2   r2   r3   test_simple_fetch_ties  s    z+FetchLimitOffsetTest.test_simple_fetch_tiesc                 C   sZ   | j j}|t||jjjdddd	 }t
|d d t
t|dddh d S )Nr   Tr   r   r   r   r   r;   r(   r:   r   rK   rL   rT   r   r   rD   r   r~   rF   r>   r   far2   r2   r3   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   r5   r   r   r   r   r   )	r;   r(   rI   r   rK   rL   rT   r   r   r   r2   r2   r3   #test_fetch_offset_ties_exact_number3  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   r2   r2   r3   test_simple_fetch_percentI  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   r5   r   r   r   r   r2   r2   r3   test_fetch_offset_percentR  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   r2   r2   r3   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|dddh d S )	Nr   Tr   r   r   r   r   r   r   r   r2   r2   r3   test_fetch_offset_percent_tiesl  s      z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r2   F)r2   )0rN   rO   rP   rQ   rR   r4   r?   rI   r   r   r   r   rJ   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   r2   r2   r2   r3   rx      s   
	
   





	















rx   c                   @   sH   e Zd ZdZdZdZedd Zedd Zdd	 Z	d
d Z
dd ZdS )SameNamedSchemaTableTestztests for #7471T)Zschemasc              	   C   sB   t d|tdtddtjd t d|tdtddtdtdd d S )	Nr(   r)   Tr*   )schemasome_table_idFZnullable)r   r   r   r   test_schemar/   r2   r2   r3   r4     s     z&SameNamedSchemaTableTest.define_tablesc                 C   sD   |  ddtj \}}|| ddi || ddd d S )Nr(   %s.some_tabler)   r5   )r)   r   )r;   r   r   r:   r<   )r0   r>   r(   some_table_schemar2   r2   r3   r?     s     z$SameNamedSchemaTableTest.insert_datac              	   C   sJ   |  ddtj \}}t|t|||||jj|jj	k
 d d S )Nr(   r   r5   r5   r5   )r;   r   r   r   r:   r   	join_fromrL   r   r)   firstrF   r>   r(   r   r2   r2   r3   test_simple_join_both_tables  s     
z5SameNamedSchemaTableTest.test_simple_join_both_tablesc              	   C   sV   |  ddtj \}}t|t||||jj|jj	k
|jj	dk d d S )Nr(   r   r5   r5   r5   )r;   r   r   r   r:   r   r   rL   r   r)   wherer   r   r2   r2   r3   !test_simple_join_whereclause_only  s      
	z:SameNamedSchemaTableTest.test_simple_join_whereclause_onlyc              	   C   s   |  ddtj \}}t||||jj|jjk|jjdk	 }t
|t||jj|||jj|jjk|jjdk d d S )Nr(   r   r5   r   )r;   r   r   r   r   rL   r   r)   r   r   r   r:   r   )rF   r>   r(   r   Zsubqr2   r2   r3   test_subquery  s0     

	z&SameNamedSchemaTableTest.test_subqueryN)rN   rO   rP   rr   rQ   rw   rR   r4   r?   r   r   r   r2   r2   r2   r3   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 )JoinTestTr2   c              	   C   s0   t j }t||| | W 5 Q R X d S r@   rA   r   r2   r2   r3   rI     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.idFr   )r   r   r   r   r/   r2   r2   r3   r4     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)   r5   r   r   rZ   rd   )r)   r   )r:   r;   r   r<   r   r=   r2   r2   r3   r?     s    
 
zJoinTest.insert_datac                 C   sN   |  dd\}}t|||||jj|jj}| |ddddg d S Nr   r   r   )r5   r   r5   )r   rZ   r   )r   rd   r   r;   r   select_fromjoinrK   rL   r)   rI   rF   r   r   rp   r2   r2   r3   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 r2   r2   ).0r   r   rL   r2   r2   r3   
<listcomp>  s   z1JoinTest.test_inner_join_true.<locals>.<listcomp>r]   r^   r_   rZ   rc   r   r   )rZ   r   )rd   r   )r;   r   r   r   r    rK   rL   r)   rI   	itertoolsproductr   r2   r2   r3   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   rK   rL   r)   rI   r   r2   r2   r3   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   )r5   NN)r   NN)r   NN)rZ   NN)rd   NN)	r;   r   r   Z	outerjoinr   rK   rL   r)   rI   r   r2   r2   r3   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   r2   r2   r3   test_outer_join_fk:  s    &zJoinTest.test_outer_join_fkN)r2   )rN   rO   rP   rQ   rI   rR   r4   r?   r   r   r   r   r   r2   r2   r2   r3   r     s   

	
r   c                   @   s   e Zd ZdZedd Zedd ZdddZd	d
 Zdd Z	e
jje
jjdd Ze
jjdd Zdd Ze
jjdd Zdd ZdS )CompoundSelectTestTc                 C   s*   t d|tdtddtdttdt d S ry   rz   r/   r2   r2   r3   r4   E  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 )Nr5   r   r{   r   rZ   rd   r9   r=   r2   r2   r3   r?   O  s    




zCompoundSelectTest.insert_datar2   c              	   C   s0   t j }t||| | W 5 Q R X d S r@   rA   r   r2   r2   r3   rI   [  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   r   rL   r)   r#   rI   rK   selected_columnsrF   r   s1s2u1r2   r2   r3   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   rL   r)   r#   aliasrI   rK   r   r   r2   r2   r3   test_select_from_plain_unioni  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   r5   r   r   r   )r;   r(   r   r   rL   r)   r   rK   r#   rI   r   r   r2   r2   r3   &test_limit_offset_selectable_in_unionss  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   rL   r)   rK   r#   r   rI   r   r   r2   r2   r3   "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   rL   r)   distinctr#   r   rI   rK   r   r   r2   r2   r3   "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   rL   r)   r   rK   r#   r   rI   r   r2   r2   r3   &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   rL   r)   r   rK   r   r#   rI   r   r   r2   r2   r3   .test_limit_offset_aliased_selectable_in_unions  s,    

	

	 zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsN)r2   )rN   rO   rP   rQ   rR   r4   r?   rI   r   r   r   rJ   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  r2   r2   r2   r3   r   B  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*   rT   rU   zrW   r.   r/   r2   r2   r3   r4     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 Nr5   r   z1)r)   rT   rU   r  r   z2rZ   z3rd   z4r9   r=   r2   r2   r3   r?     s    
z!PostCompileParamsTest.insert_datac                 C   s<   | j j}t|jj|jjtdddk}| |di  d S )NrV   Tliteral_executezKSELECT some_table.id FROM some_table WHERE some_table.x = __[POSTCOMPILE_q]	r;   r(   r   rL   r)   r   rT   r   assert_compilerF   r   rp   r2   r2   r3   test_compile  s    z"PostCompileParamsTest.test_compilec                 C   sB   | j j}t|jj|jjtddddk}| j|di dd d S )NrV   r   Tr  z<SELECT some_table.id FROM some_table WHERE some_table.x = 10)r   r  r  r2   r2   r3   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 )NrV   Tr  r   rV   z>SELECT some_table.id 
FROM some_table 
WHERE some_table.x = 10r2   )r;   r(   r   rL   r)   r   rT   r   sql_execution_asserterr   rB   rC   r:   dictassert_r
   r   
positionalrF   r   rp   ZasserterrH   r2   r2   r3   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 )
NrV   T	expandingr  rd   r|   rf   r  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r2   )r;   r(   r   rL   r)   r   rT   r	   r   r  r   rB   rC   r:   r  r  r
   r   r  r  r2   r2   r3   +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 )NrV   Tr  )rd   r   )      r  zbSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.y) IN (%s(5, 10), (12, 18))VALUES  r2   )r;   r(   r   rL   r)   r   r!   rT   rU   r	   r   r  r   rB   rC   r:   r  r  r
   r   tuple_in_valuesr  r  r2   r2   r3   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 )NrV   Tr  )rd   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  r2   )r;   r(   r   rL   r)   r   r!   rT   r  r	   r   r  r   rB   rC   r:   r  r  r
   r   r   r  r  r2   r2   r3   ?test_execute_tuple_expanding_plus_literal_heterogeneous_execute1  s"    
*zUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rN   rO   rP   rQ   rw   rR   r4   r?   r  r  r  r  r   rJ   tuple_inr!  r"  r2   r2   r2   r3   r    s   



r  c                   @   sr  e Zd ZdZedd Zedd ZdDddZd	d
 Zdd Z	e
jjdd Ze
jjdd Ze
jjdd Ze
jjdd Zdd Zdd Zdd Zdd Zdd Zdd  Ze
jjd!d" Ze
jjd#d$ Ze
jjd%d& Ze
jjd'd( Ze
jjd)d* Ze
jjd+d, Ze
jjd-d. Zd/d0 Zd1d2 Z d3d4 Z!d5d6 Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&d?d@ Z'dAdB Z(dCS )EExpandingBoundInTestTc              
   C   s6   t d|tdtddtdttdttdtd d S r  r.   r/   r2   r2   r3   r4   M  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  r9   r=   r2   r2   r3   r?   X  s    
z ExpandingBoundInTest.insert_datar2   c              	   C   s0   t j }t||| | W 5 Q R X d S r@   rA   r   r2   r2   r3   rI   d  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 )NrV   rX   )rV   rX   r   )r;   r(   r   rL   r)   r   rT   r	   r   rU   rK   rI   r  r2   r2   r3   "test_multiple_empty_sets_bindparamh  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 r@   )r;   r(   r   rL   r)   r   rT   r	   rU   rK   rI   r  r2   r2   r3   test_multiple_empty_sets_directt  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 NrV   r   r;   r(   r   rL   r)   r   r!   rT   r  r	   r   rK   rI   r  r2   r2   r3   )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 r@   )
r   rL   r)   r   r!   rT   r  r	   rK   rI   valr   rp   rF   r   r2   r3   go  s    zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.gor   r  r   r	  rZ   r
  r^   r_   r   r;   r(   rF   r-  r2   r,  r3   &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   rL   r)   r   r!   rT   rU   r	   r   rK   rI   r  r2   r2   r3   'test_empty_homogeneous_tuples_bindparam  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 r@   )
r   rL   r)   r   r!   rT   rU   r	   rK   rI   r*  r,  r2   r3   r-    s    zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go)r5   r   r   r   r   rZ   r]   r^   r_   r1  r2  r2   r,  r3   $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 )	NrV   r^   r_   r   r   r   rZ   r   r;   r(   r   rL   r)   r   rT   r	   r   rK   rI   r  r2   r2   r3   test_bound_in_scalar_bindparam  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   rZ   r^   r_   r   
r;   r(   r   rL   r)   r   rT   r	   rK   rI   r  r2   r2   r3   test_bound_in_scalar_direct  s    z0ExpandingBoundInTest.test_bound_in_scalar_directc                 C   sV   | j j}t|jj|jjddg|jjg 	|jj}| 
|ddg d S )Nr   r   r^   r_   r;   r(   r   rL   r)   r   rT   r	   not_inrK   rI   r  r2   r2   r3   !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  r2   r2   r3   !test_empty_in_plus_notempty_notin  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 idrV   Ttype_r  r^   r_   r   r  r	  r
  r   N)r   
bindparamsr   r   rI   rF   rp   r2   r2   r3   test_typed_str_in  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....

        rA  rV   Tr  r^   r_   r   r  r	  r
  r   Nr   rD  r   rI   rE  r2   r2   r3   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 )	NrV   r^   r_   r   r6  r7  rZ   rd   r   r4  r  r2   r2   r3   !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 )Nr6  r7  rJ  r^   r_   r   )r;   r(   r   rL   r)   r   r!   rT   rU   r	   rK   rI   r  r2   r2   r3   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 )	NrV   r^   r_   r   r.  r/  r0  r   r(  r  r2   r2   r3   /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/  r0  r^   r_   r   )r;   r(   r   rL   r)   r   r!   rT   r  r	   rK   rI   r  r2   r2   r3   ,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 idrV   TrG  r^   r_   r   r.  r/  r0  r   rH  rE  r2   r2   r3   4test_bound_in_heterogeneous_two_tuple_text_bindparam2  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 r@   _datarF   r,   r2   r2   r3   __init__B  s    zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS r@   iterrR  rF   r2   r2   r3   __iter__E  s    zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S r@   rQ  rF   idxr2   r2   r3   __getitem__H  s    ztExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS r@   r}   rR  rW  r2   r2   r3   __len__K  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrN   rO   rP   rT  rX  r[  r]  r2   r2   r2   r3   
LikeATupleA  s   r_  rO  rV   TrB  r^   r_   r   r   r  r   r	  rZ   r
  r   )	collections_abcSequencer   rD  r   r"   r   r   rI   rF   r_  rp   r2   r2   r3   ?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 r@   rQ  rS  r2   r2   r3   rT  g  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS r@   rU  rW  r2   r2   r3   rX  j  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S r@   rQ  rY  r2   r2   r3   r[  m  s    zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS r@   r\  rW  r2   r2   r3   r]  p  s    zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__Nr^  r2   r2   r2   r3   r_  f  s   r_  rO  rV   TrG  r^   r_   r   r   r  r   r	  rZ   r
  r   )r`  ra  r   rD  r   rI   rb  r2   r2   r3   >test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuplea  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'  r9  r  r2   r2   r3   (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 r@   r;  r  r2   r2   r3   %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 NrV   r]   r^   r_   r   r   )r;   r(   r   rL   r)   r   rT   r>  r   rK   rI   r  r2   r2   r3   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^   r_   r   )
r;   r(   r   rL   r)   r   rT   r>  rK   rI   r  r2   r2   r3   .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   rL   r)   r   r  r	   r   rK   rI   r  r2   r2   r3   '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 r@   )
r;   r(   r   rL   r)   r   r  r	   rK   rI   r  r2   r2   r3   $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 rg  )r;   r(   r   rL   r)   r   r  r>  r   rK   rI   r  r2   r2   r3   0test_empty_set_against_string_negation_bindparam  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 ri  )
r;   r(   r   rL   r)   r   r  r>  rK   rI   r  r2   r2   r3   -test_empty_set_against_string_negation_direct  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foor2   )valueZelse_r   Fr   )	r   r   r   r	   r   r    r   r:   fetchonerF   r>   rp   r2   r2   r3   )test_null_in_empty_set_is_false_bindparam  s    	z>ExpandingBoundInTest.test_null_in_empty_set_is_false_bindparamc                 C   s<   t tt g t ft d}t|| d d d S )Nrq  r   rr  )r   r   r   r	   r    r   r:   rs  rt  r2   r2   r3   &test_null_in_empty_set_is_false_direct  s    
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directN)r2   ))rN   rO   rP   rQ   rR   r4   r?   rI   r%  r&  r   rJ   Ztuple_in_w_emptyr)  r3  r5  r8  r:  r<  r?  r@  rF  rI  r#  rK  rL  rM  rN  rP  rc  rd  re  rf  rh  rj  rk  rl  rm  rn  ru  rv  r2   r2   r2   r3   r$  J  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,   rW   r.   r/   r2   r2   r3   r4     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 )Nr5   Zabcdefgr7   r   zab/cdefgr   zab%cdefgrZ   Zab_cdefgrd   zabcde/fgr|   zabcde%fgrf   zab#cdefg   Zab9cdefg	   zabcde#fgr   Zabcd9fg   r9   r=   r2   r2   r3   r?     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 r2   r2   )r   rp  r2   r2   r3   	<setcomp>  s   z*LikeFunctionsTest._test.<locals>.<setcomp>)r;   r(   r   rB   rC   r:   r   rL   r)   r   r   )rF   ro   r   r(   rH   rowsr2   r2   r3   _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%cr5   r   r   rZ   rd   r|   rf   ry  rz  r   r;   r(   rL   r,   r~  
startswithrF   colr2   r2   r3   test_startswith_unescaped  s    z+LikeFunctionsTest.test_startswith_unescapedc                 C   s(   | j jjj}| |jddddh d S )Nr  T
autoescaper   r  r  r2   r2   r3   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'r5   r   r   rZ   rd   r|   rf   ry  rz  r   )r;   r(   rL   r,   r~  r  r   r  r2   r2   r3   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#escaperf   r  r  r2   r2   r3   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 )Nr  Tr  r  r  r   zab#crf   r  r  r2   r2   r3   !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%fgr5   r   r   rZ   rd   r|   rf   ry  rz  r;   r(   rL   r,   r~  endswithr  r2   r2   r3   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'r5   r   r   rZ   rd   r|   rf   ry  rz  )r;   r(   rL   r,   r~  r  r   r  r2   r2   r3   test_endswith_sqlexpr   s
     z'LikeFunctionsTest.test_endswith_sqlexprc                 C   s(   | j jjj}| |jddddh d S )Nr  Tr  r|   r  r  r2   r2   r3   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  rz  r  r  r2   r2   r3   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#fgrz  r  r  r2   r2   r3   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%cder5   r   r   rZ   rd   r|   rf   ry  rz  r;   r(   rL   r,   r~  containsr  r2   r2   r3   test_contains_unescaped3  s    z)LikeFunctionsTest.test_contains_unescapedc                 C   s(   | j jjj}| |jddddh d S )Nr  Tr  r   r  r  r2   r2   r3   test_contains_autoescape7  s    z*LikeFunctionsTest.test_contains_autoescapec                 C   s(   | j jjj}| |jddddh d S )Nzb##cder  r  rf   r  r  r2   r2   r3   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#cdrf   r  r  r2   r2   r3   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   rZ   rf   ry  r   r;   r(   rL   r,   r~  regexp_matchr  r2   r2   r3   test_not_regexp_matchD  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FOOr5   rd   r|   rz  )r;   r(   rL   r,   r~  regexp_replacer  r  r2   r2   r3   test_regexp_replaceI  s
     
z%LikeFunctionsTest.test_regexp_replacer  r5   rd   r|   rz  abcr   z^abcZ9cdery  z^ar{  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S r@   r  )rF   r   r   r  r2   r2   r3   test_regexp_matchP  s    z#LikeFunctionsTest.test_regexp_match)"rN   rO   rP   rQ   run_insertsrun_deletesrR   r4   r?   r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rJ   r  r  r  r  r   r~   ranger  r2   r2   r2   r3   rw    sJ   



	rw  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   r/   r2   r2   r3   r4   c  s    z ComputedColumnTest.define_tablesc                 C   s(   | | jj ddddddg d S )Nr5   r   )r)   r  *   )r:   r;   r  r<   r=   r2   r2   r3   r?   n  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*)r5   r   r-   r   )r   r       )r   rB   rC   r:   r   r   r   r;   r  rK   rL   r)   rD   r   rF   rH   resr2   r2   r3   test_select_allu  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   rB   rC   r:   r   r;   r  rL   r  r  r   rK   r)   rD   r   r  r2   r2   r3   test_select_columns~  s    
 

z&ComputedColumnTest.test_select_columnsN)
rN   rO   rP   rQ   rw   rR   r4   r?   r  r  r2   r2   r2   r3   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_columnsrx  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*   rj   r-   tbl_br   i)	incrementr  ZminvalueZmaxvaluer   r   r   r   r   r/   r2   r2   r3   r4     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 )Nrj   r   r   r  rL   r)   rj   )r:   r;   r  r<   r  r=   r2   r2   r3   r?     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  rL   )r:   r   r   r   r;   r  rK   rL   r)   rD   r   r  rF   r>   r  r2   r2   r3   r    s     

z"IdentityColumnTest.test_select_allc                 C   s:   | t| jjjj| jjjj }t|ddg d S )N)r  )r  )	r:   r   r;   r  rL   r)   rK   rD   r   r  r2   r2   r3   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<   r2   r>   rF   r2   r3   fn  s    

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r%   r&   )rF   r>   r  r2   r  r3   test_insert_always_error  s    z+IdentityColumnTest.test_insert_always_errorN)rN   rO   rP   rQ   rw   r  r  rR   r4   r?   r  r  r   rJ   Zidentity_columns_standardr  r2   r2   r2   r3   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autoincrementrj   r-   r  r/   r2   r2   r3   r4     s    z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi}| | jj  }t|d d S )Nrj   row)r5   r  )r:   r;   r  r<   r   r   r   r  r2   r2   r3    test_autoincrement_with_identity  s    z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rN   rO   rP   rQ   rw   rR   r4   r  r2   r2   r2   r3   r    s
   
r  c                   @   s8   e Zd ZdZedd Zedd Zdd Zdd	 Zd
S )
ExistsTestTc                 C   s&   t d|tdtddtdtd d S )Nstuffr)   Tr*   r,   rW   r.   r/   r2   r2   r3   r4     s    zExistsTest.define_tablesc              	   C   s8   | | jj ddddddddddddg d S )Nr5   	some datar7   r   r   rZ   zsome other data)r:   r;   r  r<   r=   r2   r2   r3   r?     s    
zExistsTest.insert_datac              	   C   s@   | j j}t|ttdt |jj	dk
 dg d S )Nr5   r  r]   r;   r  r   r:   r   r   r   r   rL   r,   rD   rF   r>   r  r2   r2   r3   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 )Nr5   zno datar  r  r2   r2   r3   test_select_exists_false  s    z#ExistsTest.test_select_exists_falseN)	rN   rO   rP   rQ   rR   r4   r?   r  r  r2   r2   r2   r3   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  rV   ro  z:DISTINCT ON is currently supported only by the PostgreSQL zSELECT DISTINCT * FROM foo)r   r   r   r   r   r   Zexpect_deprecatedr  )rF   Zstmr2   r2   r3   test_distinct_on%  s
    zDistinctOnTest.test_distinct_onN)	rN   rO   rP   rQ   r   Zfails_ifrJ   Zsupports_distinct_onr  r2   r2   r2   r3   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_brz   r/   r2   r2   r3   r4   2  s    z'IsOrIsNotDistinctFromTest.define_tables)Zboth_int_differentr   r5   r5   )Zboth_int_samer5   r5   r   )Zone_null_firstNr5   r5   )Zone_null_secondr   Nr5   )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 )Nr5   )r)   r  r  r   )r;   r  r:   r<   r   r   rL   r  Zis_distinct_fromr  rD   r   r}   Zis_not_distinct_from)rF   Zcol_a_valueZcol_b_valueZexpected_row_count_for_isr>   r  rG   Zexpected_row_count_for_is_notr2   r2   r3   test_is_or_is_not_distinct_from<  s*    z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rN   rO   rP   rQ   rw   rR   r4   r   r   r  r2   r2   r2   r3   r  .  s   
		r  c                   @   s<   e Zd ZdZdZedd Zedd Zdd Zd	d
 Z	dS )WindowFunctionTest)Zwindow_functionsTc                 C   s*   t d|tdtddtdttdt d S )Nr(   r)   Tr*   col1col2rz   r/   r2   r2   r3   r4   h  s    z WindowFunctionTest.define_tablesc                 C   s(   | | jj dd tddD  d S )Nc                 S   s   g | ]}|||d  dqS )rd   )r)   r  r  r2   r   ir2   r2   r3   r   v  s     z2WindowFunctionTest.insert_data.<locals>.<listcomp>r5   rW   )r:   r;   r(   r<   r  r=   r2   r2   r3   r?   r  s    
zWindowFunctionTest.insert_datac                 C   s`   | j j}|tt|jjj|jj	
 gd|jj	dk  }t|dd tdD  d S )N)rK   r   c                 S   s   g | ]}d qS ))_   r2   r  r2   r2   r3   r     s     z2WindowFunctionTest.test_window.<locals>.<listcomp>   )r;   r(   r:   r   r   maxrL   r  overr  rj   r   ru   r   r  rF   r>   r(   r}  r2   r2   r3   test_windowy  s    
zWindowFunctionTest.test_windowc                 C   sT   | j j}|tt|jjj|jj	gdd
 }t|dd tdddD  d S )N)r  r   )rK   r}  c                 S   s   g | ]
}|fqS r2   r2   r  r2   r2   r3   r     s     z?WindowFunctionTest.test_window_rows_between.<locals>.<listcomp>rd      )r;   r(   r:   r   r   r  rL   r  r  r  ru   r   r  r  r2   r2   r3   test_window_rows_between  s    	z+WindowFunctionTest.test_window_rows_betweenN)
rN   rO   rP   rw   rQ   rR   r4   r?   r  r  r2   r2   r2   r3   r  c  s   
	
r  c                   @   s   e Zd ZdZd ZZdd edD Zedd Z	edd	 Z
ejd
d dd edD ejjfdd eedejjfdd eeddejjfdd dgejjfdd eeddejjfdd eeddejjfdddd ZdS )BitwiseTestTrx  c                 C   s   g | ]}||d  dqS )r5   )r   r   r2   r  r2   r2   r3   r     s     zBitwiseTest.<listcomp>r   c                 C   s   t d|tdttdt d S )Nbitwiser   r   rz   r/   r2   r2   r3   r4     s    zBitwiseTest.define_tablesc                 C   s   | | jj | j d S r@   )r:   r;   r  r<   inserted_datar=   r2   r2   r3   r?     s    zBitwiseTest.insert_datac                 C   s
   |  dS )Nrd   )Zbitwise_xorr   r2   r2   r3   <lambda>      zBitwiseTest.<lambda>c                 C   s   g | ]}|d kr|qS rc   r2   r  r2   r2   r3   r     s      c                 C   s
   |  dS Nr5   )Z
bitwise_orr  r2   r2   r3   r    r  c                 C   s
   |  dS )NrZ   )Zbitwise_andr  r2   r2   r3   r    r  rZ   ry  c                 C   s   | d   S Nr   )Zbitwise_notr  r2   r2   r3   r    r  r   c                 C   s
   |  dS r  )Zbitwise_lshiftr  r2   r2   r3   r    r  r5   c                 C   s
   |  dS r  )Zbitwise_rshiftr  r2   r2   r3   r    r  zcase, expectedr   c           	         sd    j j}|jj}tj||d}t||dk|}|	|
  }t| fdd|D  d S )Nr  r   c                    s   g | ]} j | qS r2   )r  r  rW  r2   r3   r     s     z,BitwiseTest.test_bitwise.<locals>.<listcomp>)r;   r  rL   r   r   Zresolve_lambdar   r   rK   r:   Zmappingsru   r   )	rF   r   r   r>   r  r   oprp   r  r2   rW  r3   test_bitwise  s    "zBitwiseTest.test_bitwiseN)rN   rO   rP   rQ   r  r  r  r  rR   r4   r?   r   r   rJ   Zsupports_bitwise_xorlistZsupports_bitwise_orZsupports_bitwise_andZsupports_bitwise_notZsupports_bitwise_shiftr  r2   r2   r2   r3   r    sF   


!r  )@collections.abcr  r`  r   r  r   r   r   r   Z
assertionsr   r   r	   Z	assertsqlr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   excr%   r&   Z
TablesTestr'   rS   ZTestBasers   rx   r   r   r   r  r$  rw  r  r  r  r  r  r  r  r  r2   r2   r2   r3   <module>	   s   &M   Jcdw
       	+P/53