U
    [hY                     @   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   clsZmetadata r1   J./venv/lib/python3.8/site-packages/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   
connectionr1   r1   r2   insert_data=   s    
zCollateTest.insert_datac              	   C   s.   t j }t|| | W 5 Q R X d S Nr   dbconnectr   r9   fetchallselfr   resultconnr1   r1   r2   _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)r4   r5   )r   r7   )r   requiresZget_order_by_collationr   rH   r   r:   r(   order_bycr,   ZcollateZasc)rE   Z	collationr1   r1   r2   test_collate_order_byK   s    z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr3   r>   rH   r   rI   Zorder_by_collationrL   r1   r1   r1   r2   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/   r1   r1   r2   r3   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 )Nr4   r   Zq1Zp3)r)   rS   rT   rU   rW   r   Zq2Zp2   Zq3Zp1r8   r<   r1   r1   r2   r>   n   s    
zOrderByLabelTest.insert_datac              	   C   s.   t j }t|| | W 5 Q R X d S r?   r@   rD   r1   r1   r2   rH   y   s    zOrderByLabelTest._assert_resultc                 C   s6   | j j}|jjd}| t||dddg d S )Nlxr4   r   r   )r:   r(   rK   rS   labelrH   r   rJ   rE   r   rY   r1   r1   r2   
test_plain}   s    zOrderByLabelTest.test_plainc                 C   s>   | j j}|jj|jj d}| t||dddg d S )NrY   r\         )	r:   r(   rK   rS   rT   r]   rH   r   rJ   r^   r1   r1   r2   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 )NrY   ly)r   Zq1p3)ra   Zq2p2)rc   Zq3p1)r:   r(   rK   rS   rT   r]   r   lowerrU   rW   rH   r   rJ   desc)rE   r   rY   re   r1   r1   r2   test_composed_multiple   s    z'OrderByLabelTest.test_composed_multiplec                 C   s:   | j j}|jjd}| t|| dddg d S )NrY   r\   r[   rZ   )	r:   r(   rK   rS   r]   rH   r   rJ   rg   r^   r1   r1   r2   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 )NrY   rb   r`   r\   )
r:   r(   rK   rS   rT   r]   rH   r   rJ   rg   r^   r1   r1   r2   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 )NrY   )r4   r   )r4   ra   )r4   rc   )r:   r(   rK   rS   rT   r]   r   r   countr)   Zgroup_byrJ   rH   )rE   r   exprstmtr1   r1   r2   test_group_by_composed   s
    z'OrderByLabelTest.test_group_by_composedN)rM   rN   rO   __doc__rP   rQ   r3   r>   rH   r_   rd   rh   ri   rj   r   rI   Zgroup_by_complex_expressionrn   r1   r1   r1   r2   rR   W   s   


	rR   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)rq   )r4   Zname1)r   Zname2)r   Zname3)	r$   r   r   r   r,   r   r9   r   all)rE   r=   Z
value_exprr1   r1   r2   test_tuples   s      z ValuesExpressionTest.test_tuplesN)rM   rN   rO   __requires__rP   rs   r1   r1   r1   r2   rp      s   rp   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*   rS   rT   r   r   r   r/   r1   r1   r2   r3      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 )Nr4   r   r)   rS   rT   r   rX   ra      r8   r<   r1   r1   r2   r>      s    





z FetchLimitOffsetTest.insert_datar1   Fc                 C   sT   |r:| || }tt|t| tt|t| nt| || | d S r?   )r9   rC   r   lenset)rE   r=   r   rF   paramsset_Z	query_resr1   r1   r2   rH      s
    z#FetchLimitOffsetTest._assert_resultc              	   C   s0   t j }t||| | W 5 Q R X d S r?   )r   rA   rB   r   Zexec_driver_sqlrC   rE   r   rF   r|   rG   r1   r1   r2   _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   r4   r4   r   r   r   r   r   r   r   rX   )r:   r(   r   rJ   rK   r)   rH   limit)rE   r=   r   rm   r1   r1   r2   test_simple_limit   s    z&FetchLimitOffsetTest.test_simple_limitc                 C   sL   | j j}t|jjd }tt|t|  }| 	||dg d S )Nr4   rZ   )
r:   r(   r   rK   r)   r   Zscalar_subqueryr#   subqueryrH   )rE   r=   r   rm   ur1   r1   r2    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(   rH   r   rJ   rK   r)   fetchrE   r=   r   r1   r1   r2   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   rX   rX   ra   ra   rX   ry   r   r:   r(   rH   r   rJ   rK   r)   offsetr   r1   r1   r2   test_simple_offset  s    z'FetchLimitOffsetTest.test_simple_offset)r   r   r   r4   )r   r   )r   r4   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_optionsrH   r   rJ   rK   r)   r   r   )rE   r=   r   r   Zassert_datar   r   expectedr1   r1   r2   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   r4   r   r   r   r   r   	r:   r(   rH   r   rJ   rK   r)   r   r   r   r1   r1   r2   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(   rH   r   r   r   r1   r1   r2   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   r4   r   r   r1   r1   r2   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   r4   literal_bindsT)dialectZcompile_kwargsr   r   N)r:   r(   r   rJ   rK   r)   r   r   compiler   rA   r   strr   rE   r   rm   Zsqlr1   r1   r2   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   rJ   rK   r)   r   r   r   r   rA   r   r   r   r   r1   r1   r2   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(   rH   r   rJ   rK   r)   r   r   r   r1   r1   r2   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   r4   )	r:   r(   rH   r   rJ   rK   r)   r   r   r   r1   r1   r2   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   r4   )r   r   r   r   r   r   )
r:   r(   rH   r   rJ   rK   r)   r   r   r   r   r1   r1   r2   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   r4   )r   r   r   r   r   r   )
r:   r(   rH   r   rJ   rK   r)   r   r   r   r   r1   r1   r2   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(   rH   r   rJ   rK   r)   r   r   r   r1   r1   r2   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(   rH   r   rJ   rK   r)   r   r   r   r1   r1   r2   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(   rH   r   rJ   rK   r)   r   r   r   r   r1   r1   r2   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(   rH   r   rJ   rK   r)   r   r   r   r   r1   r1   r2   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(   rH   r   rJ   rK   r)   r   r   r   r   r1   r1   r2   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   r4   r   r   r   r1   r1   r2   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 )	Nr4   T	with_tiesr   r   r   r   r   	r:   r(   rH   r   rJ   rK   rS   rg   r   r   r1   r1   r2   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(   r9   r   rJ   rK   rS   r   r   rC   r   r{   rE   r=   r   far1   r1   r2   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   r4   r   r   r   r   r   )	r:   r(   rH   r   rJ   rK   rS   r   r   r   r1   r1   r2   #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   r1   r1   r2   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   r4   r   r   r   r   r1   r1   r2   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   r1   r1   r2   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   r1   r1   r2   test_fetch_offset_percent_tiesl  s      z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r1   F)r1   )0rM   rN   rO   rP   rQ   r3   r>   rH   r   r   r   r   rI   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   r1   r1   r1   r2   ru      s   
	
   





	















ru   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/   r1   r1   r2   r3     s     z&SameNamedSchemaTableTest.define_tablesc                 C   sD   |  ddtj \}}|| ddi || ddd d S )Nr(   %s.some_tabler)   r4   )r)   r   )r:   r   r   r9   r;   )r0   r=   r(   some_table_schemar1   r1   r2   r>     s     z$SameNamedSchemaTableTest.insert_datac              	   C   sJ   |  ddtj \}}t|t|||||jj|jj	k
 d d S )Nr(   r   r4   r4   r4   )r:   r   r   r   r9   r   	join_fromrK   r   r)   firstrE   r=   r(   r   r1   r1   r2   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   r4   r4   r4   )r:   r   r   r   r9   r   r   rK   r   r)   wherer   r   r1   r1   r2   !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   r4   r   )r:   r   r   r   r   rK   r   r)   r   r   r   r9   r   )rE   r=   r(   r   Zsubqr1   r1   r2   test_subquery  s0     

	z&SameNamedSchemaTableTest.test_subqueryN)rM   rN   rO   ro   rP   rt   rQ   r3   r>   r   r   r   r1   r1   r1   r2   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 )JoinTestTr1   c              	   C   s0   t j }t||| | W 5 Q R X d S r?   r@   r~   r1   r1   r2   rH     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/   r1   r1   r2   r3     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)   r4   r   r   rX   ra   )r)   r   )r9   r:   r   r;   r   r<   r1   r1   r2   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   )r4   r   r4   )r   rX   r   )r   ra   r   r:   r   select_fromjoinrJ   rK   r)   rH   rE   r   r   rm   r1   r1   r2   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 r1   r1   ).0r   r   rK   r1   r1   r2   
<listcomp>  s   z1JoinTest.test_inner_join_true.<locals>.<listcomp>rZ   r[   r\   rX   r`   r   r   )rX   r   )ra   r   )r:   r   r   r   r    rJ   rK   r)   rH   	itertoolsproductr   r1   r1   r2   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   rJ   rK   r)   rH   r   r1   r1   r2   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   )r4   NN)r   NN)r   NN)rX   NN)ra   NN)	r:   r   r   Z	outerjoinr   rJ   rK   r)   rH   r   r1   r1   r2   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   r1   r1   r2   test_outer_join_fk:  s    &zJoinTest.test_outer_join_fkN)r1   )rM   rN   rO   rP   rH   rQ   r3   r>   r   r   r   r   r   r1   r1   r1   r2   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 rv   rw   r/   r1   r1   r2   r3   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 )Nr4   r   rx   r   rX   ra   r8   r<   r1   r1   r2   r>   O  s    




zCompoundSelectTest.insert_datar1   c              	   C   s0   t j }t||| | W 5 Q R X d S r?   r@   r~   r1   r1   r2   rH   [  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   rK   r)   r#   rH   rJ   selected_columnsrE   r   s1s2Zu1r1   r1   r2   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   rK   r)   r#   aliasrH   rJ   r   r   r1   r1   r2   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   r4   r   r   r   )r:   r(   r   r   rK   r)   r   rJ   r#   rH   r   r   r1   r1   r2   &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   rK   r)   rJ   r#   r   rH   r   r   r1   r1   r2   "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   rK   r)   distinctr#   r   rH   rJ   r   r   r1   r1   r2   "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   rK   r)   r   rJ   r#   r   rH   r   r1   r1   r2   &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   rK   r)   r   rJ   r   r#   rH   r   r   r1   r1   r2   .test_limit_offset_aliased_selectable_in_unions  s,    

	

	 zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsN)r1   )rM   rN   rO   rP   rQ   r3   r>   rH   r   r   r   rI   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   r1   r1   r1   r2   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*   rS   rT   zrV   r.   r/   r1   r1   r2   r3     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 Nr4   r   z1)r)   rS   rT   r   r   z2rX   z3ra   z4r8   r<   r1   r1   r2   r>     s    
z!PostCompileParamsTest.insert_datac                 C   s<   | j j}t|jj|jjtdddk}| |di  d S )NrU   Tliteral_executezKSELECT some_table.id FROM some_table WHERE some_table.x = __[POSTCOMPILE_q]	r:   r(   r   rK   r)   r   rS   r   assert_compilerE   r   rm   r1   r1   r2   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 )NrU   r   Tr  z<SELECT some_table.id FROM some_table WHERE some_table.x = 10)r   r  r
  r1   r1   r2   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 )NrU   Tr  r   rU   z>SELECT some_table.id 
FROM some_table 
WHERE some_table.x = 10r1   )r:   r(   r   rK   r)   r   rS   r   sql_execution_asserterr   rA   rB   r9   dictassert_r
   r   
positionalrE   r   rm   ZasserterrG   r1   r1   r2   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 )
NrU   T	expandingr  ra   ry   rc   r  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r1   )r:   r(   r   rK   r)   r   rS   r	   r   r  r   rA   rB   r9   r  r  r
   r   r  r  r1   r1   r2   +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 )NrU   Tr  )ra   r   )      r  zbSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.y) IN (%s(5, 10), (12, 18))VALUES  r1   )r:   r(   r   rK   r)   r   r!   rS   rT   r	   r   r  r   rA   rB   r9   r  r  r
   r   tuple_in_valuesr  r  r1   r1   r2   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 )NrU   Tr  )ra   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  r1   )r:   r(   r   rK   r)   r   r!   rS   r   r	   r   r  r   rA   rB   r9   r  r  r
   r   r  r  r  r1   r1   r2   ?test_execute_tuple_expanding_plus_literal_heterogeneous_execute1  s"    
*zUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rM   rN   rO   rP   rt   rQ   r3   r>   r  r  r  r  r   rI   tuple_inr  r  r1   r1   r1   r2   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/   r1   r1   r2   r3   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  r8   r<   r1   r1   r2   r>   X  s    
z ExpandingBoundInTest.insert_datar1   c              	   C   s0   t j }t||| | W 5 Q R X d S r?   r@   r~   r1   r1   r2   rH   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 )NrU   rW   )rU   rW   r   )r:   r(   r   rK   r)   r   rS   r	   r   rT   rJ   rH   r
  r1   r1   r2   "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   rK   r)   r   rS   r	   rT   rJ   rH   r
  r1   r1   r2   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 NrU   r   r:   r(   r   rK   r)   r   r!   rS   r   r	   r   rJ   rH   r
  r1   r1   r2   )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   rK   r)   r   r!   rS   r   r	   rJ   rH   valr   rm   rE   r   r1   r2   go  s    zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.gor   r  r   r  rX   r  r[   r\   r   r:   r(   rE   r(  r1   r'  r2   &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   rK   r)   r   r!   rS   rT   r	   r   rJ   rH   r
  r1   r1   r2   '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   rK   r)   r   r!   rS   rT   r	   rJ   rH   r%  r'  r1   r2   r(    s    zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go)r4   r   r   r   r   rX   rZ   r[   r\   r,  r-  r1   r'  r2   $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 )	NrU   r[   r\   r   r   r   rX   r   r:   r(   r   rK   r)   r   rS   r	   r   rJ   rH   r
  r1   r1   r2   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   rX   r[   r\   r   
r:   r(   r   rK   r)   r   rS   r	   rJ   rH   r
  r1   r1   r2   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   rK   r)   r   rS   r	   not_inrJ   rH   r
  r1   r1   r2   !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   r8  r
  r1   r1   r2   !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 idrU   TZtype_r  r[   r\   r   r  r  r  r   N)r   
bindparamsr   r   rH   rE   rm   r1   r1   r2   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....

        r<  rU   Tr  r[   r\   r   r  r  r  r   Nr   r>  r   rH   r?  r1   r1   r2   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 )	NrU   r[   r\   r   r1  r2  rX   ra   r   r/  r
  r1   r1   r2   !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 )Nr1  r2  rD  r[   r\   r   )r:   r(   r   rK   r)   r   r!   rS   rT   r	   rJ   rH   r
  r1   r1   r2   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 )	NrU   r[   r\   r   r)  r*  r+  r   r#  r
  r1   r1   r2   /test_bound_in_heterogeneous_two_tuple_bindparam  s    zDExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_bindparamc                 C   sT   | j j}t|jjt|jj|jj	dddg
|jj}| |dddg d S )Nr)  r*  r+  r[   r\   r   )r:   r(   r   rK   r)   r   r!   rS   r   r	   rJ   rH   r
  r1   r1   r2   ,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 idrU   TrA  r[   r\   r   r)  r*  r+  r   rB  r?  r1   r1   r2   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rE   r,   r1   r1   r2   __init__B  s    zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS r?   iterrL  rE   r1   r1   r2   __iter__E  s    zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S r?   rK  rE   idxr1   r1   r2   __getitem__H  s    ztExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS r?   rz   rL  rQ  r1   r1   r2   __len__K  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrM   rN   rO   rN  rR  rU  rW  r1   r1   r1   r2   
LikeATupleA  s   rY  rI  rU   Tr=  r[   r\   r   r   r  r   r  rX   r  r   )	collections_abcSequencer   r>  r   r"   r   r   rH   rE   rY  rm   r1   r1   r2   ?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?   rK  rM  r1   r1   r2   rN  g  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS r?   rO  rQ  r1   r1   r2   rR  j  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S r?   rK  rS  r1   r1   r2   rU  m  s    zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS r?   rV  rQ  r1   r1   r2   rW  p  s    zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__NrX  r1   r1   r1   r2   rY  f  s   rY  rI  rU   TrA  r[   r\   r   r   r  r   r  rX   r  r   )rZ  r[  r   r>  r   rH   r\  r1   r1   r2   >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"  r4  r
  r1   r1   r2   (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?   r6  r
  r1   r1   r2   %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 NrU   rZ   r[   r\   r   r   )r:   r(   r   rK   r)   r   rS   r9  r   rJ   rH   r
  r1   r1   r2   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 NrZ   r[   r\   r   )
r:   r(   r   rK   r)   r   rS   r9  rJ   rH   r
  r1   r1   r2   .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   rK   r)   r   r   r	   r   rJ   rH   r
  r1   r1   r2   '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   rK   r)   r   r   r	   rJ   rH   r
  r1   r1   r2   $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 ra  )r:   r(   r   rK   r)   r   r   r9  r   rJ   rH   r
  r1   r1   r2   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 rc  )
r:   r(   r   rK   r)   r   r   r9  rJ   rH   r
  r1   r1   r2   -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foor1   )valueZelse_r   Fr   )	r   r   r   r	   r   r    r   r9   fetchonerE   r=   rm   r1   r1   r2   )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 )Nrk  r   rl  )r   r   r   r	   r    r   r9   rm  rn  r1   r1   r2   &test_null_in_empty_set_is_false_direct  s    
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directN)r1   ))rM   rN   rO   rP   rQ   r3   r>   rH   r   r!  r   rI   Ztuple_in_w_emptyr$  r.  r0  r3  r5  r7  r:  r;  r@  rC  r  rE  rF  rG  rH  rJ  r]  r^  r_  r`  rb  rd  re  rf  rg  rh  ro  rp  r1   r1   r1   r2   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
ejjdd Zdd Zejjdd Zejj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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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,   rV   r.   r/   r1   r1   r2   r3     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 )Nr4   Zabcdefgr6   r   zab/cdefgr   zab%cdefgrX   Zab_cdefgra   zabcde/fgry   zabcde%fgrc   zab#cdefg   Zab9cdefg	   zabcde#fgr   Zabcd9fg   r8   r<   r1   r1   r2   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 r1   r1   )r   rj  r1   r1   r2   	<setcomp>  s   z*LikeFunctionsTest._test.<locals>.<setcomp>)r:   r(   r   rA   rB   r9   r   rK   r)   r   r   )rE   rl   r   r(   rG   rowsr1   r1   r2   _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%cr4   r   r   rX   ra   ry   rc   rs  rt  r   r:   r(   rK   r,   rx  
startswithrE   colr1   r1   r2   test_startswith_unescaped  s    z+LikeFunctionsTest.test_startswith_unescapedc                 C   s(   | j jjj}| |jddddh d S )Nry  T
autoescaper   rz  r|  r1   r1   r2   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'r4   r   r   rX   ra   ry   rc   rs  rt  r   )r:   r(   rK   r,   rx  r{  r   r|  r1   r1   r2   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#escaperc   rz  r|  r1   r1   r2   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 )Nry  Tr  r  r  r   zab#crc   rz  r|  r1   r1   r2   !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%fgr4   r   r   rX   ra   ry   rc   rs  rt  r:   r(   rK   r,   rx  endswithr|  r1   r1   r2   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'r4   r   r   rX   ra   ry   rc   rs  rt  )r:   r(   rK   r,   rx  r  r   r|  r1   r1   r2   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  ry   r  r|  r1   r1   r2   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  rt  r  r|  r1   r1   r2   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  ry   ze#fgrt  r  r|  r1   r1   r2   test_endswith_autoescape_escape3  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%cder4   r   r   rX   ra   ry   rc   rs  rt  r:   r(   rK   r,   rx  containsr|  r1   r1   r2   test_contains_unescaped9  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|  r1   r1   r2   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  rc   r  r|  r1   r1   r2   test_contains_escapeB  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#cdrc   r  r|  r1   r1   r2   test_contains_autoescape_escapeG  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   rX   rc   rs  r   r:   r(   rK   r,   rx  regexp_matchr|  r1   r1   r2   test_not_regexp_matchM  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FOOr4   ra   ry   rt  )r:   r(   rK   r,   rx  regexp_replacer  r|  r1   r1   r2   test_regexp_replaceR  s
     
z%LikeFunctionsTest.test_regexp_replacer  r4   ra   ry   rt  abcr   z^abcZ9cders  z^aru  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S r?   r  )rE   r   r   r}  r1   r1   r2   test_regexp_matchY  s    z#LikeFunctionsTest.test_regexp_match)#rM   rN   rO   rP   run_insertsrun_deletesrQ   r3   r>   rx  r~  r   rI   Zlike_escapesr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r{   ranger  r1   r1   r1   r2   rq    s\   












	rq  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/   r1   r1   r2   r3   l  s    z ComputedColumnTest.define_tablesc                 C   s(   | | jj ddddddg d S )Nr4   r   )r)   r  *   )r9   r:   r  r;   r<   r1   r1   r2   r>   w  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*)r4   r   r-   r   )r   r       )r   rA   rB   r9   r   r   r   r:   r  rJ   rK   r)   rC   r   rE   rG   resr1   r1   r2   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   rA   rB   r9   r   r:   r  rK   r  r  r   rJ   r)   rC   r   r  r1   r1   r2   test_select_columns  s    
 

z&ComputedColumnTest.test_select_columnsN)
rM   rN   rO   rP   rt   rQ   r3   r>   r  r  r1   r1   r1   r2   r  h  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_columnsrr  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*   rg   r-   tbl_br   i)Z	incrementr  ZminvalueZmaxvaluer   r   r   r   r   r/   r1   r1   r2   r3     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 )Nrg   r   r   r  rK   r)   rg   )r9   r:   r  r;   r  r<   r1   r1   r2   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  rK   )r9   r   r   r   r:   r  rJ   rK   r)   rC   r   r  rE   r=   r  r1   r1   r2   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  )	r9   r   r:   r  rK   r)   rJ   rC   r   r  r1   r1   r2   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  )r9   r:   r  r;   r1   r=   rE   r1   r2   fn  s    

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r%   r&   )rE   r=   r  r1   r  r2   test_insert_always_error  s    z+IdentityColumnTest.test_insert_always_errorN)rM   rN   rO   rP   rt   r  r  rQ   r3   r>   r  r  r   rI   Zidentity_columns_standardr  r1   r1   r1   r2   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autoincrementrg   r-   r  r/   r1   r1   r2   r3     s    z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi | | jj  }t|d d S )Nrg   row)r4   r  )r9   r:   r  r;   r   r   r   r  r1   r1   r2    test_autoincrement_with_identity  s    z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rM   rN   rO   rP   rt   rQ   r3   r  r1   r1   r1   r2   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,   rV   r.   r/   r1   r1   r2   r3     s    zExistsTest.define_tablesc              	   C   s8   | | jj ddddddddddddg d S )Nr4   	some datar6   r   r   rX   zsome other data)r9   r:   r  r;   r<   r1   r1   r2   r>     s    
zExistsTest.insert_datac              	   C   s@   | j j}t|ttdt |jj	dk
 dg d S )Nr4   r  rZ   r:   r  r   r9   r   r   r   r   rK   r,   rC   rE   r=   r  r1   r1   r2   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 )Nr4   zno datar  r  r1   r1   r2   test_select_exists_false  s    z#ExistsTest.test_select_exists_falseN)	rM   rN   rO   rP   rQ   r3   r>   r  r  r1   r1   r1   r2   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  rU   ri  z:DISTINCT ON is currently supported only by the PostgreSQL zSELECT DISTINCT * FROM foo)r   r   r   r   r   r   Zexpect_deprecatedr	  )rE   Zstmr1   r1   r2   test_distinct_on.  s
    zDistinctOnTest.test_distinct_onN)	rM   rN   rO   rP   r   Zfails_ifrI   Zsupports_distinct_onr  r1   r1   r1   r2   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_brw   r/   r1   r1   r2   r3   ;  s    z'IsOrIsNotDistinctFromTest.define_tables)Zboth_int_differentr   r4   r4   )Zboth_int_samer4   r4   r   )Zone_null_firstNr4   r4   )Zone_null_secondr   Nr4   )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 )Nr4   )r)   r  r  r   )r:   r  r9   r;   r   r   rK   r  Zis_distinct_fromr  rC   r   rz   Zis_not_distinct_from)rE   Zcol_a_valueZcol_b_valueZexpected_row_count_for_isr=   r  rF   Zexpected_row_count_for_is_notr1   r1   r2   test_is_or_is_not_distinct_fromE  s*    z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rM   rN   rO   rP   rt   rQ   r3   r   r   r  r1   r1   r1   r2   r  7  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col2rw   r/   r1   r1   r2   r3   q  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 )ra   )r)   r  r  r1   r   ir1   r1   r2   r     s     z2WindowFunctionTest.insert_data.<locals>.<listcomp>r4   rV   )r9   r:   r(   r;   r  r<   r1   r1   r2   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)rJ   r   c                 S   s   g | ]}d qS ))_   r1   r  r1   r1   r2   r     s     z2WindowFunctionTest.test_window.<locals>.<listcomp>   )r:   r(   r9   r   r   maxrK   r  overr  rg   r   rr   r   r  rE   r=   r(   rw  r1   r1   r2   test_window  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   )rJ   rw  c                 S   s   g | ]
}|fqS r1   r1   r  r1   r1   r2   r     s     z?WindowFunctionTest.test_window_rows_between.<locals>.<listcomp>ra      )r:   r(   r9   r   r   r  rK   r  r  r  rr   r   r  r  r1   r1   r2   test_window_rows_between  s    	z+WindowFunctionTest.test_window_rows_betweenN)
rM   rN   rO   rt   rP   rQ   r3   r>   r  r  r1   r1   r1   r2   r  l  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 )BitwiseTestTrr  c                 C   s   g | ]}||d  dqS )r4   )r   r   r1   r  r1   r1   r2   r     s     zBitwiseTest.<listcomp>r   c                 C   s   t d|tdttdt d S )Nbitwiser   r   rw   r/   r1   r1   r2   r3     s    zBitwiseTest.define_tablesc                 C   s   | | jj | j d S r?   )r9   r:   r  r;   inserted_datar<   r1   r1   r2   r>     s    zBitwiseTest.insert_datac                 C   s
   |  dS )Nra   )Zbitwise_xorr   r1   r1   r2   <lambda>      zBitwiseTest.<lambda>c                 C   s   g | ]}|d kr|qS r`   r1   r  r1   r1   r2   r     s      c                 C   s
   |  dS Nr4   )Z
bitwise_orr  r1   r1   r2   r    r  c                 C   s
   |  dS )NrX   )Zbitwise_andr  r1   r1   r2   r    r  rX   rs  c                 C   s   | d   S Nr   )Zbitwise_notr  r1   r1   r2   r    r  r   c                 C   s
   |  dS r  )Zbitwise_lshiftr  r1   r1   r2   r    r  r4   c                 C   s
   |  dS r  )Zbitwise_rshiftr  r1   r1   r2   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 r1   )r  r  rQ  r1   r2   r     s     z,BitwiseTest.test_bitwise.<locals>.<listcomp>)r:   r  rK   r   r   Zresolve_lambdar   r   rJ   r9   Zmappingsrr   r   )	rE   r   r   r=   r  r   oprm   r  r1   rQ  r2   test_bitwise  s    "zBitwiseTest.test_bitwiseN)rM   rN   rO   rP   r  r  r  r  rQ   r3   r>   r   r   rI   Zsupports_bitwise_xorlistZsupports_bitwise_orZsupports_bitwise_andZsupports_bitwise_notZsupports_bitwise_shiftr  r1   r1   r1   r2   r    sF   


!r  )@Zcollections.abcr  rZ  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'   rR   ZTestBaserp   ru   r   r   r   r   r  rq  r  r  r  r  r  r  r  r  r1   r1   r1   r2   <module>	   s   &M   Jcdw
       +P/53