a
    dhY                     @   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   `/var/www/html/requester/venv/lib/python3.9/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   
connectionr2   r2   r3   insert_data=   s    
zCollateTest.insert_datac                 C   sB   t j $}t|| | W d    n1 s40    Y  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   sB   t j $}t|| | W d    n1 s40    Y  d S r@   rA   rE   r2   r2   r3   rI   y   s    zOrderByLabelTest._assert_resultc                 C   s4   | j j}|jjd}| t||g d 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||g d d S )Nr\   )r`         )	r;   r(   rL   rT   rU   ra   rI   r   rK   rb   r2   r2   r3   test_composed_int   s    z"OrderByLabelTest.test_composed_intc                 C   s`   | j j}|jj|jj d}t|jj|jj	 d}| 
t|||| g d d S )Nr\   ly))r   Zq1p3)re   Zq2p2)rg   Zq3p1)r;   r(   rL   rT   rU   ra   r   lowerrV   rX   rI   r   rK   desc)rF   r   r\   ri   r2   r2   r3   test_composed_multiple   s    z'OrderByLabelTest.test_composed_multiplec                 C   s8   | j j}|jjd}| t|| g d d S )Nr\   )r`   r_   r^   )	r;   r(   rL   rT   ra   rI   r   rK   rk   rb   r2   r2   r3   test_plain_desc   s    z OrderByLabelTest.test_plain_descc                 C   s@   | j j}|jj|jj d}| t||	 g d d S )Nr\   )rf   rd   r`   )
r;   r(   rL   rT   rU   ra   rI   r   rK   rk   rb   r2   r2   r3   test_composed_int_desc   s    z'OrderByLabelTest.test_composed_int_descc                 C   sR   | j j}|jj|jj d}tt|jj	|
||}| |g d d S )Nr\   ))r5   r   )r5   re   )r5   rg   )r;   r(   rL   rT   rU   ra   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   rc   rh   rl   rm   rn   r   rJ   Zgroup_by_complex_expressionrr   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   sD   t tdttdtddg d}t|t| g d d S )Nr)   nameZ	my_values)ru   ))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   rw   r2   r2   r2   r3   rt      s   rt   c                   @   s2  e Zd ZdZedd Zedd ZdHdd	ZdId
dZdd Z	dd Z
ejjdd Zejjdd Zejg dg dg dddejjdd Zejjdd Zejjdd Zejjdd  Zejjd!d" Zejjd#d$ Zejjd%d& Zejjd'd( Zejjd)d* Zejjd+d, Zejjd-d. Zejjd/d0 Z ejjd1d2 Z!ejjejj"d3d4 Z#ejjd5d6 Z$ejjd7d8 Z%ejj&d9d: Z'ejj&ejj(d;d< Z)ejj&ejj(d=d> Z*ejj+d?d@ Z,ejj+ejj(dAdB Z-ejj&ejj+dCdD Z.ejj&ejj+ejj(dEdF Z/dGS )JFetchLimitOffsetTestTc                 C   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   re      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   sD   t j &}t||| | W d    n1 s60    Y  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   sN   | j j}t||jj}| ||dddg | ||dg d d S Nr   r5   r5   r   r   r   r   r   r   r   r   r   rZ   )r;   r(   r   rK   rL   r)   rI   limit)rF   r>   r   rq   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   rq   ur2   r2   r3    test_limit_render_multiple_times   s    z5FetchLimitOffsetTest.test_limit_render_multiple_timesc                 C   sX   | j j}| |t||jjdddg | |t||jjdg d d S r   r;   r(   rI   r   rK   rL   r)   fetchrF   r>   r   r2   r2   r3   test_simple_fetch   s    z&FetchLimitOffsetTest.test_simple_fetchc                 C   sX   | j j}| |t||jjdg d | |t||jjdddg d S )Nr   r   rZ   rZ   re   re   rZ   r}   r   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   r   r   )r   r5   r   r   casesargnamesc                 C   sf   | j j}|ji d}g d}|D ]@\}}||||  }| |t||jj|	|| q d S )N)Zcompiled_cacher   r   r   r   r   )
r;   r(   Zexecution_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   sd   | j j}| |t||jjddddg | |t||jjddg d d S )Nr   r5   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   s,   | j j}| j|t|dg ddd d S )N
   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   sX   | j j}| |t||jjdg d | |t||jjdg d d S )Nr   r   r5   r   r   r   r   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   rq   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   sp   | j j}| j|t||jjtdddgddid | j|t||jjtdg dddid d S )Nlr   r   r   r   r   r   )	r;   r(   rI   r   rK   rL   r)   r   r   r   r2   r2   r3   test_bound_limitl  s    z%FetchLimitOffsetTest.test_bound_limitc                 C   sp   | j j}| j|t||jjtdg dddid | j|t||jjtdg dddid d S )Nor   r   r   r   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g d	d
ddd d S )Nr   r   r   r   r   r5   )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g d	d
ddd d S )Nfr   r   r   r   r5   )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 g d d S )Nr   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 g d 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   sp   | j j}| j|t||jj jdddddgdd | j|t||jj jdddg ddd d S )	Nr5   T	with_tiesr   r   r   r   r   	r;   r(   rI   r   rK   rL   rT   rk   r   r   r2   r2   r3   test_simple_fetch_ties  s    z+FetchLimitOffsetTest.test_simple_fetch_tiesc                 C   sX   | j j}|t||jjjdddd	 }t
|d d t
t|h d d S )Nr   Tr   r   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  s.    	z8FetchLimitOffsetTest.test_fetch_offset_ties_exact_numberc                 C   s4   | j j}| |t||jjjddddg d S )N   Tpercentr   r   r   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   sZ   | j j}|t||jjjddddd	 }t
|d d t
t|h d d S )Nr   Tr   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   ry      s   
	
 





	















ry   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  s.    


	z&SameNamedSchemaTableTest.test_subqueryN)rN   rO   rP   rs   rQ   rx   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   sD   t j &}t||| | W d    n1 s60    Y  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   re   )r)   r   )r:   r;   r   r<   r   r=   r2   r2   r3   r?     s    
 
zJoinTest.insert_datac                 C   sJ   |  dd\}}t|||||jj|jj}| |g d d S Nr   r   )r   )r5   r   r5   )r   rZ   r   )r   re   r   r;   r   select_fromjoinrK   rL   r)   rI   rF   r   r   rq   r2   r2   r3   test_inner_join_fk   s    &zJoinTest.test_inner_join_fkc              	   C   sd   |  dd\}}t||||t |jj|jj}| |dd t	
g dg dD  d S )Nr   r   c                 S   s    g | ]\\}\}}|||fqS r2   r2   ).0r   r   rL   r2   r2   r3   
<listcomp>  s   z1JoinTest.test_inner_join_true.<locals>.<listcomp>)r^   r_   r`   rZ   rd   )r   r   )rZ   r   )re   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   sN   |  dd\}}t||||t |jj|jj}| |g d d S )Nr   r   ))r5   NN)r   NN)r   NN)rZ   NN)re   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   sJ   |  dd\}}t|||||jj|jj}| |g d 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 rz   r{   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   re   r9   r=   r2   r2   r3   r?   O  s    




zCompoundSelectTest.insert_datar2   c                 C   sD   t j &}t||| | W d    n1 s60    Y  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   z3re   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   rq   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}|  L}t	j
 "}||tdd W d    n1 sf0    Y  W d    n1 s0    Y  |tdt	j
jjrd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   rq   ZasserterrH   r2   r2   r3   test_execute  s    
Nz"PostCompileParamsTest.test_executec              	   C   s   | j j}t|jj|jjtdddd}| 	 P}t
j &}||tg dd W d    n1 sn0    Y  W d    n1 s0    Y  |tdt
jjjrdni  d S )NrV   T	expandingr  )re   r}   rg   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    
RzAPostCompileParamsTest.test_execute_expanding_plus_literal_executec              	   C   s   | j j}t|jjt|jj|jj	t
dddd}|  P}tj &}||tddgd W d    n1 sx0    Y  W d    n1 s0    Y  |tdtjjjrdnd	 tjjjrd
ni  d S )NrV   Tr"  )re   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"    
R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}|  P}tj &}||tddgd W d    n1 sx0    Y  W d    n1 s0    Y  |tdtjjjrdnd	 tjjjrd
ni  d S )NrV   Tr"  )re   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"    
RzUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rN   rO   rP   rQ   rx   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   sD   t j &}t||| | W d    n1 s60    Y  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                    s@    j j fdd}|g g  |g dg d |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   rq   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   r6  r2   r5  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 r0  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                    s@    j j fdd}|g g  |g dg d |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   r3  r5  r2   r3   r6    s    zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go))r5   r   r   r   r   rZ   r]   r9  r:  r2   r5  r3   $test_empty_homogeneous_tuples_direct  s
    
z9ExpandingBoundInTest.test_empty_homogeneous_tuples_directc                 C   sR   | j j}t|jj|jjtd	|jj}| j
|g ddg did d S )NrV   r8  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   sF   | j j}t|jj|jjg d|jj}| 	|g d d S )NrA  r8  
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   rF  r  r2   r2   r3   !test_empty_in_plus_notempty_notin  s    z6ExpandingBoundInTest.test_empty_in_plus_notempty_notinc                 C   s8   t dtdtdd}| j|g ddg did dS )	ztest related to #7292.

        as a type is given to the bound param, there is no ambiguity
        to the type of element.

        3select id FROM some_table WHERE z IN :q ORDER BY idrV   Ttype_r#  r8  r  r  r  r   N)r   
bindparamsr   r   rI   rF   rq   r2   r2   r3   test_typed_str_in  s    
z&ExpandingBoundInTest.test_typed_str_inc                 C   s6   t dtddd}| j|g ddg did dS )	ztest related to #7292.

        for untyped expression, we look at the types of elements.
        Test for Sequence to detect tuple in.  but not strings or bytes!
        as always....

        rJ  rV   Tr#  r8  rM  r   Nr   rN  r   rI   rO  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|g ddg did d S )NrV   r8  r>  r?  )rZ   re   r   r<  r  r2   r2   r3   !test_bound_in_two_tuple_bindparam  s    z6ExpandingBoundInTest.test_bound_in_two_tuple_bindparamc                 C   sP   | j j}t|jjt|jj|jj	g d
|jj}| |g d d S )NrT  r8  )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|g ddg did d S )NrV   r8  r7  r   r1  r  r2   r2   r3   /test_bound_in_heterogeneous_two_tuple_bindparam  s    
zDExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_bindparamc                 C   sP   | j j}t|jjt|jj|jj	g d
|jj}| |g d d S )Nr7  r8  )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   s6   t dtddd}| j|g ddg did d S )N8select id FROM some_table WHERE (x, z) IN :q ORDER BY idrV   TrQ  r8  r7  r   rR  rO  r2   r2   r3   4test_bound_in_heterogeneous_two_tuple_text_bindparam2  s    

zIExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparamc              	   C   sh   G dd dt j}tdtdtt t dd}| j|g dd|dd	|d
d|ddgid d S )Nc                   @   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@   iterr\  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@   r[  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~   r\  ra  r2   r2   r3   __len__K  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrN   rO   rP   r^  rb  re  rg  r2   r2   r2   r3   
LikeATupleA  s   ri  rY  rV   TrK  r8  r   r  r   r  rZ   r  r   )	collections_abcSequencer   rN  r   r"   r   r   rI   rF   ri  rq   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|g d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@   r[  r]  r2   r2   r3   r^  g  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   s
   t | jS r@   r_  ra  r2   r2   r3   rb  j  s    zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   s
   | j | S r@   r[  rc  r2   r2   r3   re  m  s    zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   s
   t | jS r@   rf  ra  r2   r2   r3   rg  p  s    zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__Nrh  r2   r2   r2   r3   ri  f  s   ri  rY  rV   TrQ  r8  r   r  r   r  rZ   r  r   )rj  rk  r   rN  r   rI   rl  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 r0  rB  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@   rD  r  r2   r2   r3   %test_empty_set_against_integer_direct  s    &z:ExpandingBoundInTest.test_empty_set_against_integer_directc                 C   sN   | j j}t|jj|jjtd	|jj}| j
|g ddg id d S NrV   r^   r_   r`   r   r   )r;   r(   r   rL   r)   r   rT   rG  r   rK   rI   r  r2   r2   r3   1test_empty_set_against_integer_negation_bindparam  s    zFExpandingBoundInTest.test_empty_set_against_integer_negation_bindparamc                 C   sB   | j j}t|jj|jjg |jj}| 	|g d d S Nrr  )
r;   r(   r   rL   r)   r   rT   rG  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 r0  )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   sN   | j j}t|jj|jjtd	|jj}| j
|g ddg id d S rq  )r;   r(   r   rL   r)   r   r  rG  r   rK   rI   r  r2   r2   r3   0test_empty_set_against_string_negation_bindparam  s    zEExpandingBoundInTest.test_empty_set_against_string_negation_bindparamc                 C   sB   | j j}t|jj|jjg |jj}| 	|g d d S rt  )
r;   r(   r   rL   r)   r   r  rG  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>   rq   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 )Nr|  r   r}  )r   r   r   r	   r    r   r:   r~  r  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_emptyr2  r;  r=  r@  rC  rE  rH  rI  rP  rS  r,  rU  rV  rW  rX  rZ  rm  rn  ro  rp  rs  ru  rv  rw  rx  ry  r  r  r2   r2   r2   r3   r-  J  s\   




	

	
		



	



!
 				r-  c                   @   sv  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*h d+fd,h d-fd.h d-fd/d0hfd1e e!d2d3fd4e e!d2d3fd5e  fd6d7 Z"dS )8LikeFunctionsTestTonceNc                 C   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_cdefgre   zabcde/fgr}   zabcde%fgrg   zab#cdefg   Zab9cdefg	   zabcde#fgr   Zabcd9fg   r9   r=   r2   r2   r3   r?     s    
zLikeFunctionsTest.insert_datac                 C   sb   | j j}tj 2}dd |t|jj	|D }W d    n1 sJ0    Y  t
|| d S )Nc                 S   s   h | ]
\}|qS r2   r2   )r   r{  r2   r2   r3   	<setcomp>  s   z*LikeFunctionsTest._test.<locals>.<setcomp>)r;   r(   r   rB   rC   r:   r   rL   r)   r   r   )rF   rp   r   r(   rH   rowsr2   r2   r3   _test  s    $zLikeFunctionsTest._testc                 C   s&   | j jjj}| |dh d d S )Nab%c
   r5   r   r   rZ   re   r}   rg   r  r  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h d d S )Nz'ab%c'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#escaperg   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#crg   r  r  r2   r2   r3   !test_startswith_autoescape_escape  s    z3LikeFunctionsTest.test_startswith_autoescape_escapec                 C   s&   | j jjj}| |dh d d S )Ne%fg	   r5   r   r   rZ   re   r}   rg   r  r  r;   r(   rL   r,   r  endswithr  r2   r2   r3   test_endswith_unescaped  s    z)LikeFunctionsTest.test_endswith_unescapedc                 C   s*   | j jjj}| |tdh d d S )Nz'e%fg'r  )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  r  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#fgr  r  r  r2   r2   r3   test_endswith_autoescape_escape3  s    z1LikeFunctionsTest.test_endswith_autoescape_escapec                 C   s&   | j jjj}| |dh d d S )Nb%cder  r;   r(   rL   r,   r  containsr  r2   r2   r3   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  r2   r2   r3   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  rg   r  r  r2   r2   r3   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#cdrg   r  r  r2   r2   r3   test_contains_autoescape_escapeG  s    z1LikeFunctionsTest.test_contains_autoescape_escapec                 C   s(   | j jjj}| |d h d d S )Na.cde>   r   r   rZ   rg   r  r   r;   r(   rL   r,   r  regexp_matchr  r2   r2   r3   test_not_regexp_matchM  s    z'LikeFunctionsTest.test_not_regexp_matchc                 C   s.   | j jjj}| |dddh d d S )Nr  ZFOO   r5   re   r}   r  )r;   r(   rL   r,   r  regexp_replacer  r  r2   r2   r3   test_regexp_replaceR  s    z%LikeFunctionsTest.test_regexp_replacer  r  abc>   r5   re   r}   r  r   z^abcZ9cder  z^ar5   r  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_matchY  s    z#LikeFunctionsTest.test_regexp_match)#rN   rO   rP   rQ   run_insertsrun_deletesrR   r4   r?   r  r  r   rJ   Zlike_escapesr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   ranger  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 )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   l  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?   w  s    
zComputedColumnTest.insert_datac                 C   sj   t j L}|ttd| jj	| jjj
j }t|ddg W d    n1 s\0    Y  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_all~  s    
z"ComputedColumnTest.test_select_allc                 C   sx   t j Z}|t| jjjj| jjjj	
| jj| jjjj }t|ddg W d    n1 sj0    Y  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   rx   rR   r4   r?   r  r  r2   r2   r2   r3   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_columnsr  c                 C   sd   t d|tdttdddddddtdtd t d	|tdttd
ddddddtdtd d S )Ntbl_ar)   Tr  )alwaysstartZ
nominvalueZ
nomaxvaluer*   rk   r-   tbl_br   i)	incrementr  ZminvalueZmaxvaluer   r   r   r   r   r/   r2   r2   r3   r4     s0    z IdentityColumnTest.define_tablesc                 C   s`   | | jj ddiddig | | jj ddiddig | | jj dddg d S )Nrk   r   r   r  rL   r)   rk   )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
|g d 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   rx   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autoincrementrk   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 )Nrk   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   rx   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   sV   t dtdtd}td | |d W d    n1 sH0    Y  d S )Nr  rV   rz  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_br{   r/   r2   r2   r3   r4   ;  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_fromE  s*    z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rN   rO   rP   rQ   rx   rR   r4   r   r   r  r2   r2   r2   r3   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col2r{   r/   r2   r2   r3   r4   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 )re   )r)   r  r  r2   r   ir2   r2   r3   r         z2WindowFunctionTest.insert_data.<locals>.<listcomp>r5   rW   )r:   r;   r(   r<   r  r=   r2   r2   r3   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     r  z2WindowFunctionTest.test_window.<locals>.<listcomp>   )r;   r(   r:   r   r   maxrL   r  overr  rk   r   rv   r   r  rF   r>   r(   r  r2   r2   r3   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   )rK   r  c                 S   s   g | ]
}|fqS r2   r2   r  r2   r2   r3   r     r  z?WindowFunctionTest.test_window_rows_between.<locals>.<listcomp>re      )r;   r(   r:   r   r   r  rL   r  r  r  rv   r   r  r  r2   r2   r3   test_window_rows_between  s    	z+WindowFunctionTest.test_window_rows_betweenN)
rN   rO   rP   rx   rQ   rR   r4   r?   r  r  r2   r2   r2   r3   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 )BitwiseTestTr  c                 C   s   g | ]}||d  dqS )r5   )r   r   r2   r  r2   r2   r3   r     r  zBitwiseTest.<listcomp>r   c                 C   s   t d|tdttdt d S )Nbitwiser   r   r{   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 )Nre   )Zbitwise_xorr   r2   r2   r3   <lambda>  r  zBitwiseTest.<lambda>c                 C   s   g | ]}|d kr|qS rd   r2   r  r2   r2   r3   r     r  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   r  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  ra  r2   r3   r     r  z,BitwiseTest.test_bitwise.<locals>.<listcomp>)r;   r  rL   r   r   Zresolve_lambdar   r   rK   r:   Zmappingsrv   r   )	rF   r   r   r>   r  r   oprq   r  r2   ra  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  rj  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TestBasert   ry   r   r   r   r  r-  r  r  r  r  r  r  r  r  r  r2   r2   r2   r3   <module>	   s   &M   Jcdw
     +P/53