o
    h_                     @   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   &   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 r3   x/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_select.pydefine_tables4      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r1   
connectionr3   r3   r4   insert_data=   s   
zCollateTest.insert_datac                 C   D   t j }t|| | W d    d S 1 sw   Y  d S Nr   dbconnectr   r<   fetchallselfr   resultconnr3   r3   r4   _assert_resultG      "zCollateTest._assert_resultc                 C   sB   t jt j}| t| jj| jjj	j
| ddg d S )N)r7   r8   )r   r:   )r   requiresget_order_by_collationr   rL   r   r=   r)   order_bycr-   collateasc)rI   	collationr3   r3   r4   test_collate_order_byK   s   z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr5   rA   rL   r   rN   order_by_collationrU   r3   r3   r3   r4   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/   r0   r3   r3   r4   r5   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 )Nr7   r   q1p3)r*   r]   r^   r_   ra   r   q2p2   q3p1r;   r?   r3   r3   r4   rA   n   s   
zOrderByLabelTest.insert_datac                 C   rB   rC   rD   rH   r3   r3   r4   rL   y   rM   zOrderByLabelTest._assert_resultc                 C   s4   | j j}|jjd}| t||g d d S )Nlxr7   r   r   )r=   r)   rQ   r]   labelrL   r   rP   rI   r   ri   r3   r3   r4   
test_plain}   s   zOrderByLabelTest.test_plainc                 C   s<   | j j}|jj|jj d}| t||g d d S )Nri   )rm         )	r=   r)   rQ   r]   r^   rn   rL   r   rP   ro   r3   r3   r4   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 )Nri   ly))r   q1p3)rr   q2p2)rt   q3p1)r=   r)   rQ   r]   r^   rn   r   lowerr_   ra   rL   r   rP   desc)rI   r   ri   rv   r3   r3   r4   test_composed_multiple   s   z'OrderByLabelTest.test_composed_multiplec                 C   s8   | j j}|jjd}| t|| g d d S )Nri   )rm   rl   rk   )	r=   r)   rQ   r]   rn   rL   r   rP   r{   ro   r3   r3   r4   test_plain_desc   s   "z OrderByLabelTest.test_plain_descc                 C   s@   | j j}|jj|jj d}| t||	 g d d S )Nri   )rs   rq   rm   )
r=   r)   rQ   r]   r^   rn   rL   r   rP   r{   ro   r3   r3   r4   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 )Nri   ))r7   r   )r7   rr   )r7   rt   )r=   r)   rQ   r]   r^   rn   r   r   countr*   group_byrP   rL   )rI   r   exprstmtr3   r3   r4   test_group_by_composed   s
   z'OrderByLabelTest.test_group_by_composedN)rV   rW   rX   __doc__rY   rZ   r5   rA   rL   rp   ru   r|   r}   r~   r   rN   group_by_complex_expressionr   r3   r3   r3   r4   r\   W   s    


	r\   c                   @   s   e Zd ZdZdZdd ZdS )ValuesExpressionTest)table_value_constructorTc                 C   sD   t tdttdtddg d}t|t| g d d S )Nr*   name	my_values)r   ))r7   name1)r   name2)r   name3)	r$   r   r   r   r-   r   r<   r   all)rI   r@   
value_exprr3   r3   r4   test_tuples   s   
z ValuesExpressionTest.test_tuplesN)rV   rW   rX   __requires__rY   r   r3   r3   r3   r4   r      s    r   c                   @   s4  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   *   t d|tdtddtdttdt d S Nr)   r*   Tr+   r]   r^   r   r   r   r0   r3   r3   r4   r5         z"FetchLimitOffsetTest.define_tablesc                 C   sJ   | | jj ddddddddddddddddddddg d S )Nr7   r   r*   r]   r^   r   rf   rr      r;   r?   r3   r3   r4   rA      s   





z FetchLimitOffsetTest.insert_datar3   Fc                 C   sV   |r| || }tt|t| tt|t| d S t| || | d S rC   )r<   rG   r   lenset)rI   r@   r   rJ   paramsset_	query_resr3   r3   r4   rL      s
   z#FetchLimitOffsetTest._assert_resultc                 C   F   t j }t||| | W d    d S 1 sw   Y  d S rC   )r   rE   rF   r   exec_driver_sqlrG   rI   r   rJ   r   rK   r3   r3   r4   _assert_result_str      "z'FetchLimitOffsetTest._assert_result_strc                 C   sN   | j j}t||jj}| ||dddg | ||dg d d S Nr   r7   r7   r   r   r   r   r   r   r   r   r   rf   )r=   r)   r   rP   rQ   r*   rL   limit)rI   r@   r   r   r3   r3   r4   test_simple_limit   s   z&FetchLimitOffsetTest.test_simple_limitc                 C   sL   | j j}t|jjd }tt|t|  }| 	||dg d S )Nr7   rk   )
r=   r)   r   rQ   r*   r   scalar_subqueryr#   subqueryrL   )rI   r@   r   r   ur3   r3   r4    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)   rL   r   rP   rQ   r*   fetchrI   r@   r   r3   r3   r4   test_simple_fetch      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   rf   rf   rr   rr   rf   r   r   r   r   r=   r)   rL   r   rP   rQ   r*   offsetr   r3   r3   r4   test_simple_offset  r   z'FetchLimitOffsetTest.test_simple_offset)r   r   r   r7   r   r   )r   r   r   )r   r7   r   r   casesargnamesc                 C   sf   | j j}|ji d}g d}|D ] \}}||||  }| |t||jj|	|| qd S )N)compiled_cacher   r   r   r   r   )
r=   r)   execution_optionsrL   r   rP   rQ   r*   r   r   )rI   r@   r   r   assert_datar   r   expectedr3   r3   r4   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   r7   r   r   r   r   	r=   r)   rL   r   rP   rQ   r*   r   r   r   r3   r3   r4   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)   rL   r   r   r   r3   r3   r4   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   r7   r   r   r   r   r   r   r3   r3   r4   test_simple_offset_zeroC  s   z,FetchLimitOffsetTest.test_simple_offset_zeroc                 C   X   | j j}t||jjdd}|jt	j
jddid}t|}| |ddg dS 	z7test that 'literal binds' mode works - no bound params.r   r7   literal_bindsT)dialectcompile_kwargsr   r   N)r=   r)   r   rP   rQ   r*   r   r   compiler   rE   r   strr   rI   r   r   sqlr3   r3   r4   test_limit_offset_nobindsR     z.FetchLimitOffsetTest.test_limit_offset_nobindsc                 C   r   r   )r=   r)   r   rP   rQ   r*   r   r   r   r   rE   r   r   r   r   r3   r3   r4   test_fetch_offset_nobinds_  r   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)   rL   r   rP   rQ   r*   r   r   r   r3   r3   r4   test_bound_limitl     
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   r7   )	r=   r)   rL   r   rP   rQ   r*   r   r   r   r3   r3   r4   test_bound_offset}  r   z&FetchLimitOffsetTest.test_bound_offsetc                 C      | 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   r7   )r   r   r   r   r   )
r=   r)   rL   r   rP   rQ   r*   r   r   r   r   r3   r3   r4   test_bound_limit_offset  &   







z,FetchLimitOffsetTest.test_bound_limit_offsetc                 C   r   )Nfr   r   r   r   r7   )r   r   r   r   r   )
r=   r)   rL   r   rP   rQ   r*   r   r   r   r   r3   r3   r4   test_bound_fetch_offset  r   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)   rL   r   rP   rQ   r*   r   r   r   r3   r3   r4   test_expr_offset     
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)   rL   r   rP   rQ   r*   r   r   r   r3   r3   r4   test_expr_limit  r   z$FetchLimitOffsetTest.test_expr_limitc                 C   P   | j j}| |t||jjtdtd 	tdtd ddg d S Nr   r   r   
r=   r)   rL   r   rP   rQ   r*   r   r   r   r   r3   r3   r4   test_expr_limit_offset  s   
z+FetchLimitOffsetTest.test_expr_limit_offsetc                 C   r   r   )
r=   r)   rL   r   rP   rQ   r*   r   r   r   r   r3   r3   r4   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)   rL   r   rP   rQ   r*   r   r   r   r   r3   r3   r4   test_simple_limit_expr_offset  s"   
	
z2FetchLimitOffsetTest.test_simple_limit_expr_offsetc                 C   s|   | j j}| |t||jjtdtd 	dddg | |t||jjtdtd 	dddg d S )Nr   r   r   r   r7   r   r   r   r3   r3   r4   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 )	Nr7   T	with_tiesr   r   r   r   r   	r=   r)   rL   r   rP   rQ   r]   r{   r   r   r3   r3   r4   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   rP   rQ   r]   r   r   rG   r   r   rI   r@   r   far3   r3   r4   test_fetch_offset_ties&  s   
z+FetchLimitOffsetTest.test_fetch_offset_tiesc                 C   sl   | j j}| |t||jjjddddddg | |t||jjjdddddd	g d S )
Nr   Tr   r7   r   r   r   r   r   )	r=   r)   rL   r   rP   rQ   r]   r   r   r   r3   r3   r4   #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   r3   r3   r4   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   r7   r   r   r   r   r3   r3   r4   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   r3   r3   r4   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   r3   r3   r4   test_fetch_offset_percent_tiesl  s   
z3FetchLimitOffsetTest.test_fetch_offset_percent_tiesN)r3   Fr3   )0rV   rW   rX   rY   rZ   r5   rA   rL   r   r   r   r   rN   fetch_firstr   r   r   combinationsr   r   fetch_no_order_byr   r   r   r   bound_limit_offsetr   r   r   r   sql_expression_limit_offsetr   r   r   fetch_expressionr   r   r   
fetch_tiesr   fetch_offset_with_optionsr   r   fetch_percentr   r   r   r  r3   r3   r3   r4   r      s    
	






	















r   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)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nullable)r   r   r   r   test_schemar0   r3   r3   r4   r5     s    z&SameNamedSchemaTableTest.define_tablesc                 C   sD   |  ddtj \}}|| ddi || ddd d S )Nr)   %s.some_tabler*   r7   )r*   r  )r=   r   r  r<   r>   )r1   r@   r)   some_table_schemar3   r3   r4   rA     s
   
z$SameNamedSchemaTableTest.insert_datac              	   C   sJ   |  ddtj \}}t|t|||||jj|jj	k
 d d S )Nr)   r  r7   r7   r7   )r=   r   r  r   r<   r   	join_fromrQ   r  r*   firstrI   r@   r)   r  r3   r3   r4   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  r7   r7   r7   )r=   r   r  r   r<   r   r  rQ   r  r*   wherer  r  r3   r3   r4   !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  r7   r  )r=   r   r  r   r  rQ   r  r*   r  r   r   r<   r  )rI   r@   r)   r  subqr3   r3   r4   test_subquery  s2   
z&SameNamedSchemaTableTest.test_subqueryN)rV   rW   rX   r   rY   r   rZ   r5   rA   r  r  r  r3   r3   r3   r4   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 )JoinTestTr3   c                 C   r   rC   rD   r   r3   r3   r4   rL     r   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   r0   r3   r3   r4   r5     s   zJoinTest.define_tablesc              	   C   sj   | | jj ddiddiddiddiddig | | jj ddddddddddddg d S )Nr*   r7   r   r   rf   rr   )r*   r"  )r<   r=   r   r>   r!  r?   r3   r3   r4   rA     s   
 
zJoinTest.insert_datac                 C   J   |  dd\}}t|||||jj|jj}| |g d d S Nr   r!  )r  )r7   r   r7   )r   rf   r   )r   rr   r   r=   r   select_fromjoinrP   rQ   r*   rL   rI   r   r!  r   r3   r3   r4   test_inner_join_fk      &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 r3   r3   ).0r   r!  rQ   r3   r3   r4   
<listcomp>  s    z1JoinTest.test_inner_join_true.<locals>.<listcomp>)rk   rl   rm   rf   rq   )r  r   )rf   r   )rr   r   )r=   r   r&  r'  r    rP   rQ   r*   rL   	itertoolsproductr(  r3   r3   r4   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   rP   rQ   r*   rL   r(  r3   r3   r4   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!  ))r7   NN)r   NN)r   NN)rf   NN)rr   NN)	r=   r   r&  	outerjoinr   rP   rQ   r*   rL   r(  r3   r3   r4   test_outer_join_false&  s   zJoinTest.test_outer_join_falsec                 C   r#  r$  r%  r(  r3   r3   r4   test_outer_join_fk:  r*  zJoinTest.test_outer_join_fkNr  )rV   rW   rX   rY   rL   rZ   r5   rA   r)  r0  r1  r3  r4  r3   r3   r3   r4   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   r   r   r   r0   r3   r3   r4   r5   E  r   z CompoundSelectTest.define_tablesc              
   C   s@   | | jj ddddddddddddddddg d S )Nr7   r   r   r   rf   rr   r;   r?   r3   r3   r4   rA   O  s   




zCompoundSelectTest.insert_datar3   c                 C   r   rC   rD   r   r3   r3   r4   rL   [  r   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  rQ   r*   r#   rL   rP   selected_columnsrI   r   s1s2u1r3   r3   r4   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 r6  )r=   r)   r   r  rQ   r*   r#   aliasrL   rP   r7  r8  r3   r3   r4   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   r7   r   r   r   )r=   r)   r   r  rQ   r*   r   rP   r#   rL   r7  r8  r3   r3   r4   &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 r6  )r=   r)   r   r  rQ   r*   rP   r#   r   rL   r7  r8  r3   r3   r4   "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 r6  )r=   r)   r   r  rQ   r*   distinctr#   r   rL   rP   r7  r8  r3   r3   r4   "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  rQ   r*   r   rP   r#   r=  rL   r8  r3   r3   r4   &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  rQ   r*   r   rP   r=  r#   rL   r7  r8  r3   r3   r4   .test_limit_offset_aliased_selectable_in_unions  s&   
	
	zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsNr  )rV   rW   rX   rY   rZ   r5   rA   rL   r<  r>  r   rN   order_by_col_from_union/parens_in_union_contained_select_w_limit_offsetr@  0parens_in_union_contained_select_wo_limit_offsetrA  rC  rD  rE  r3   r3   r3   r4   r5  B  s$    
	








r5  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)standard_cursor_sqlc              
   C   6   t d|tdtddtdttdttdtd d S 	Nr)   r*   Tr+   r]   r^   zr`   r/   r0   r3   r3   r4   r5        z#PostCompileParamsTest.define_tablesc                 C   H   | | jj dddddddddddddddddd	d
dg d S Nr7   r   z1)r*   r]   r^   rM  r   z2rf   z3rr   z4r;   r?   r3   r3   r4   rA        
z!PostCompileParamsTest.insert_datac                 C   s<   | j j}t|jj|jjtdddk}| |di  d S )Nr_   Tliteral_executezKSELECT some_table.id FROM some_table WHERE some_table.x = __[POSTCOMPILE_q]	r=   r)   r   rQ   r*   r  r]   r   assert_compilerI   r   r   r3   r3   r4   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 )Nr_   r   TrV  z<SELECT some_table.id FROM some_table WHERE some_table.x = 10)r   rX  rZ  r3   r3   r4   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 d    n1 s3w   Y  W d    n1 sBw   Y  |tdt	j
jjrRdni  d S )Nr_   TrV  r   r_   z>SELECT some_table.id 
FROM some_table 
WHERE some_table.x = 10r3   )r=   r)   r   rQ   r*   r  r]   r   sql_execution_asserterr   rE   rF   r<   dictassert_r
   r   
positionalrI   r   r   asserterrK   r3   r3   r4   test_execute  s    
z"PostCompileParamsTest.test_executec              	   C   s   | j j}t|jj|jjtdddd}| 	 (}t
j }||tg dd W d    n1 s7w   Y  W d    n1 sFw   Y  |tdt
jjjrVdni  d S )Nr_   T	expandingrW  )rr   r   rt   r]  zFSELECT some_table.id 
FROM some_table 
WHERE some_table.x IN (5, 6, 7)r3   )r=   r)   r   rQ   r*   r  r]   r	   r   r^  r   rE   rF   r<   r_  r`  r
   r   ra  rb  r3   r3   r4   +test_execute_expanding_plus_literal_execute  s    
zAPostCompileParamsTest.test_execute_expanding_plus_literal_executec              	   C      | j j}t|jjt|jj|jj	t
dddd}|  (}tj }||tddgd W d    n1 s<w   Y  W d    n1 sKw   Y  |tdtjjjr[dnd	 tjjjrdd
ni  d S )Nr_   Tre  )rr   r   )      r]  zbSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.y) IN (%s(5, 10), (12, 18))VALUES  r3   )r=   r)   r   rQ   r*   r  r!   r]   r^   r	   r   r^  r   rE   rF   r<   r_  r`  r
   r   tuple_in_valuesra  rb  r3   r3   r4   1test_execute_tuple_expanding_plus_literal_execute  (   
zGPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_executec              	   C   rh  )Nr_   Tre  )rr   rQ  )ri  rS  r]  zfSELECT some_table.id 
FROM some_table 
WHERE (some_table.x, some_table.z) IN (%s(5, 'z1'), (12, 'z3'))rk  rl  r3   )r=   r)   r   rQ   r*   r  r!   r]   rM  r	   r   r^  r   rE   rF   r<   r_  r`  r
   r   rm  ra  rb  r3   r3   r4   ?test_execute_tuple_expanding_plus_literal_heterogeneous_execute1  ro  zUPostCompileParamsTest.test_execute_tuple_expanding_plus_literal_heterogeneous_executeN)rV   rW   rX   rY   r   rZ   r5   rA   r[  r\  rd  rg  r   rN   tuple_inrn  rp  r3   r3   r3   r4   rI    s    



rI  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   rK  rL  r/   r0   r3   r3   r4   r5   M  rN  z"ExpandingBoundInTest.define_tablesc                 C   rO  rP  r;   r?   r3   r3   r4   rA   X  rU  z ExpandingBoundInTest.insert_datar3   c                 C   r   rC   rD   r   r3   r3   r4   rL   d  r   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 )Nr_   ra   )r_   ra   r   )r=   r)   r   rQ   r*   r  r]   r	   r   r^   rP   rL   rZ  r3   r3   r4   "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 rC   )r=   r)   r   rQ   r*   r  r]   r	   r^   rP   rL   rZ  r3   r3   r4   test_multiple_empty_sets_directt  s   

z4ExpandingBoundInTest.test_multiple_empty_sets_directc                 C   T   | j j}t|jjt|jj|jj	t
d|jj}| j|g dg id d S Nr_   r   r=   r)   r   rQ   r*   r  r!   r]   rM  r	   r   rP   rL   rZ  r3   r3   r4   )test_empty_heterogeneous_tuples_bindparam     

z>ExpandingBoundInTest.test_empty_heterogeneous_tuples_bindparamc                    @    j j fdd}|g g  |g dg d |g g  d S )Nc                    @   t jjtjjjj| jj} 	|| d S rC   )
r   rQ   r*   r  r!   r]   rM  r	   rP   rL   valr   r   rI   r   r3   r4   go  
   

zGExpandingBoundInTest.test_empty_heterogeneous_tuples_direct.<locals>.go)r   rR  )r   rS  )rf   rT  rl   rm   r-  r=   r)   rI   r  r3   r~  r4   &test_empty_heterogeneous_tuples_direct  
   
z;ExpandingBoundInTest.test_empty_heterogeneous_tuples_directc                 C   ru  rv  r=   r)   r   rQ   r*   r  r!   r]   r^   r	   r   rP   rL   rZ  r3   r3   r4   'test_empty_homogeneous_tuples_bindparam  ry  z<ExpandingBoundInTest.test_empty_homogeneous_tuples_bindparamc                    rz  )Nc                    r{  rC   )
r   rQ   r*   r  r!   r]   r^   r	   rP   rL   r|  r~  r3   r4   r    r  zEExpandingBoundInTest.test_empty_homogeneous_tuples_direct.<locals>.go))r7   r   r   r   r   rf   rj   r  r  r3   r~  r4   $test_empty_homogeneous_tuples_direct  r  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 )Nr_   r  r   r   rf   r   r=   r)   r   rQ   r*   r  r]   r	   r   rP   rL   rZ  r3   r3   r4   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 )Nr  r  
r=   r)   r   rQ   r*   r  r]   r	   rP   rL   rZ  r3   r3   r4   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   rl   rm   r=   r)   r   rQ   r*   r  r]   r	   not_inrP   rL   rZ  r3   r3   r4   !test_nonempty_in_plus_empty_notin  s   

z6ExpandingBoundInTest.test_nonempty_in_plus_empty_notinc                 C   sR   | j j}t|jj|jjg |jjddg	|jj}| 
|g  d S )Nr   r   r  rZ  r3   r3   r4   !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 idr_   Ttype_rf  r  rR  rS  rT  r   N)r   
bindparamsr   r   rL   rI   r   r3   r3   r4   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....

        r  r_   Trf  r  r  r   Nr   r  r   rL   r  r3   r3   r4   test_untyped_str_in  s   	

z(ExpandingBoundInTest.test_untyped_str_inc                 C   \   | j j}t|jjt|jj|jj	t
d|jj}| j|g ddg did d S )Nr_   r  r  r  )rf   rr   r   r  rZ  r3   r3   r4   !test_bound_in_two_tuple_bindparam  s   


z6ExpandingBoundInTest.test_bound_in_two_tuple_bindparamc                 C   P   | j j}t|jjt|jj|jj	g d
|jj}| |g d d S )Nr  r  )r=   r)   r   rQ   r*   r  r!   r]   r^   r	   rP   rL   rZ  r3   r3   r4   test_bound_in_two_tuple_direct	  s   

z3ExpandingBoundInTest.test_bound_in_two_tuple_directc                 C   r  )Nr_   r  r  r   rw  rZ  r3   r3   r4   /test_bound_in_heterogeneous_two_tuple_bindparam  s   



zDExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_bindparamc                 C   r  )Nr  r  )r=   r)   r   rQ   r*   r  r!   r]   rM  r	   rP   rL   rZ  r3   r3   r4   ,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 idr_   Tr  r  r  r   r  r  r3   r3   r4   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                   @   ,   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   
   || _ d S rC   _datarI   r-   r3   r3   r4   __init__B     
zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   
   t | jS rC   iterr  rI   r3   r3   r4   __iter__E  r  zqExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   
   | j | S rC   r  rI   idxr3   r3   r4   __getitem__H  r  ztExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   r  rC   r   r  r  r3   r3   r4   __len__K  r  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_typed_bindparam_non_tuple.<locals>.LikeATuple.__len__NrV   rW   rX   r  r  r  r  r3   r3   r3   r4   
LikeATupleA  
    r  r  r_   Tr  r  r   rR  r   rS  rf   rT  r   )	collections_abcSequencer   r  r   r"   r   r   rL   rI   r  r   r3   r3   r4   ?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                   @   r  )
zgExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuplec                 W   r  rC   r  r  r3   r3   r4   r  g  r  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__init__c                 S   r  rC   r  r  r3   r3   r4   r  j  r  zpExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__iter__c                 S   r  rC   r  r  r3   r3   r4   r  m  r  zsExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__getitem__c                 S   r  rC   r  r  r3   r3   r4   r  p  r  zoExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuple.<locals>.LikeATuple.__len__Nr  r3   r3   r3   r4   r  f  r  r  r  r_   Tr  r  r   rR  r   rS  rf   rT  r   )r  r  r   r  r   rL   r  r3   r3   r4   >test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuplea  s    
zSExpandingBoundInTest.test_bound_in_heterogeneous_two_tuple_text_bindparam_non_tuplec                 C   J   | j j}t|jj|jjtd	|jj}| j
|g dg id d S rv  r  rZ  r3   r3   r4   (test_empty_set_against_integer_bindparam     

z=ExpandingBoundInTest.test_empty_set_against_integer_bindparamc                 C   >   | j j}t|jj|jjg |jj}| 	|g  d S rC   r  rZ  r3   r3   r4   %test_empty_set_against_integer_direct     &z:ExpandingBoundInTest.test_empty_set_against_integer_directc                 C   N   | j j}t|jj|jjtd	|jj}| j
|g ddg id d S Nr_   rk   rl   rm   r-  r   )r=   r)   r   rQ   r*   r  r]   r  r   rP   rL   rZ  r3   r3   r4   1test_empty_set_against_integer_negation_bindparam     

zFExpandingBoundInTest.test_empty_set_against_integer_negation_bindparamc                 C   B   | j j}t|jj|jjg |jj}| 	|g d d S Nr  )
r=   r)   r   rQ   r*   r  r]   r  rP   rL   rZ  r3   r3   r4   .test_empty_set_against_integer_negation_direct     $zCExpandingBoundInTest.test_empty_set_against_integer_negation_directc                 C   r  rv  )r=   r)   r   rQ   r*   r  rM  r	   r   rP   rL   rZ  r3   r3   r4   'test_empty_set_against_string_bindparam  r  z<ExpandingBoundInTest.test_empty_set_against_string_bindparamc                 C   r  rC   )
r=   r)   r   rQ   r*   r  rM  r	   rP   rL   rZ  r3   r3   r4   $test_empty_set_against_string_direct  r  z9ExpandingBoundInTest.test_empty_set_against_string_directc                 C   r  r  )r=   r)   r   rQ   r*   r  rM  r  r   rP   rL   rZ  r3   r3   r4   0test_empty_set_against_string_negation_bindparam  r  zEExpandingBoundInTest.test_empty_set_against_string_negation_bindparamc                 C   r  r  )
r=   r)   r   rQ   r*   r  rM  r  rP   rL   rZ  r3   r3   r4   -test_empty_set_against_string_negation_direct  r  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foor3   )valueelse_r   Fr   )	r   r   r   r	   r   r    r   r<   fetchonerI   r@   r   r3   r3   r4   )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  r3   r3   r4   &test_null_in_empty_set_is_false_direct  s   
	z;ExpandingBoundInTest.test_null_in_empty_set_is_false_directNr  ))rV   rW   rX   rY   rZ   r5   rA   rL   rs  rt  r   rN   tuple_in_w_emptyrx  r  r  r  r  r  r  r  r  r  rq  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r3   r3   r3   r4   rr  J  s^    




	

	
		



	



!
 				rr  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   r(   )Nr)   r*   Tr+   r-   r`   r/   r0   r3   r3   r4   r5     r6   zLikeFunctionsTest.define_tablesc                 C   sp   | | jj ddddddddddd	dd
ddddddddddddddddddd dg d S )Nr7   abcdefgr9   r   zab/cdefgr   zab%cdefgrf   ab_cdefgrr   zabcde/fgr   zabcde%fgrt   zab#cdefg   ab9cdefg	   zabcde#fgr   abcd9fg   r;   r?   r3   r3   r4   rA     s   
zLikeFunctionsTest.insert_datac                 C   sb   | j j}tj }dd |t|jj	|D }W d    n1 s%w   Y  t
|| d S )Nc                 S   s   h | ]\}|qS r3   r3   )r+  r  r3   r3   r4   	<setcomp>  s    z*LikeFunctionsTest._test.<locals>.<setcomp>)r=   r)   r   rE   rF   r<   r   rQ   r*   r  r   )rI   r   r   r)   rK   rowsr3   r3   r4   _test  s   zLikeFunctionsTest._testc                 C   &   | j jjj}| |dh d d S )Nab%c
   r7   r   r   rf   rr   r   rt   r  r  r   r=   r)   rQ   r-   r  
startswithrI   colr3   r3   r4   test_startswith_unescaped     z+LikeFunctionsTest.test_startswith_unescapedc                 C   (   | j jjj}| |jddddh d S )Nr  T
autoescaper   r  r  r3   r3   r4   test_startswith_autoescape     z,LikeFunctionsTest.test_startswith_autoescapec                 C   *   | j jjj}| |tdh d d S )Nz'ab%c'r  )r=   r)   rQ   r-   r  r  r   r  r3   r3   r4   test_startswith_sqlexpr  s
   z)LikeFunctionsTest.test_startswith_sqlexprc                 C   r  )Nzab##c#escapert   r  r  r3   r3   r4   test_startswith_escape  r  z(LikeFunctionsTest.test_startswith_escapec                 C   D   | 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#crt   r  r  r3   r3   r4   !test_startswith_autoescape_escape     z3LikeFunctionsTest.test_startswith_autoescape_escapec                 C   r  )Ne%fg	   r7   r   r   rf   rr   r   rt   r  r  r=   r)   rQ   r-   r  endswithr  r3   r3   r4   test_endswith_unescaped  r  z)LikeFunctionsTest.test_endswith_unescapedc                 C   r  )Nz'e%fg'r  )r=   r)   rQ   r-   r  r  r   r  r3   r3   r4   test_endswith_sqlexpr#  s   z'LikeFunctionsTest.test_endswith_sqlexprc                 C   r  )Nr  Tr  r   r  r  r3   r3   r4   test_endswith_autoescape)  r  z*LikeFunctionsTest.test_endswith_autoescapec                 C   r  )Nze##fgr  r  r  r  r  r3   r3   r4   test_endswith_escape.  r  z&LikeFunctionsTest.test_endswith_escapec                 C   r  )Nr  Tr  r   r   ze#fgr  r  r  r3   r3   r4   test_endswith_autoescape_escape3  r  z1LikeFunctionsTest.test_endswith_autoescape_escapec                 C   r  )Nb%cder  r=   r)   rQ   r-   r  containsr  r3   r3   r4   test_contains_unescaped9  r  z)LikeFunctionsTest.test_contains_unescapedc                 C   r  )Nr  Tr  r   r  r  r3   r3   r4   test_contains_autoescape=  r  z*LikeFunctionsTest.test_contains_autoescapec                 C   r  )Nzb##cder  r  rt   r  r  r3   r3   r4   test_contains_escapeB  r  z&LikeFunctionsTest.test_contains_escapec                 C   r  )Nzb%cdTr  r   r   zb#cdrt   r  r  r3   r3   r4   test_contains_autoescape_escapeG  r  z1LikeFunctionsTest.test_contains_autoescape_escapec                 C   s(   | j jjj}| |d h d d S )Na.cde>   r   r   rf   rt   r  r   r=   r)   rQ   r-   r  regexp_matchr  r3   r3   r4   test_not_regexp_matchM  r  z'LikeFunctionsTest.test_not_regexp_matchc                 C   s.   | j jjj}| |dddh d d S )Nr  FOO   r7   rr   r   r  )r=   r)   rQ   r-   r  regexp_replacer  r  r3   r3   r4   test_regexp_replaceR  s   z%LikeFunctionsTest.test_regexp_replacer  r  abc>   r7   rr   r   r  r   z^abc9cder  z^ar7   r  z(b|c)z^(b|c)c                 C   s"   | j jjj}| ||| d S rC   r  )rI   r   r   r  r3   r3   r4   test_regexp_matchY  s   z#LikeFunctionsTest.test_regexp_match)#rV   rW   rX   rY   run_insertsrun_deletesrZ   r5   rA   r  r  r   rN   like_escapesr  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  r   ranger  r3   r3   r3   r4   r    s^    















	r  c                   @   <   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)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   r0   r3   r3   r4   r5   l  s   z ComputedColumnTest.define_tablesc                 C   s(   | | jj ddddddg d S )Nr7   r   )r*   r&  *   )r<   r=   r%  r>   r?   r3   r3   r4   rA   w     
zComputedColumnTest.insert_datac                 C   sl   t j '}|ttd| jj	| jjj
j }t|ddg W d    d S 1 s/w   Y  d S )N*)r7   r   r.   r   )r   r)       )r   rE   rF   r<   r   r   r&  r=   r%  rP   rQ   r*   rG   r   rI   rK   resr3   r3   r4   test_select_all~  s   

"z"ComputedColumnTest.test_select_allc                 C   sz   t j .}|t| jjjj| jjjj	
| jj| jjjj }t|ddg W d    d S 1 s6w   Y  d S )N)r.   r   )r,  r-  )r   rE   rF   r<   r   r=   r%  rQ   r'  r(  r&  rP   r*   rG   r   r.  r3   r3   r4   test_select_columns  s   
"z&ComputedColumnTest.test_select_columnsN)
rV   rW   rX   rY   r   rZ   r5   rA   r0  r1  r3   r3   r3   r4   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)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start
nominvalue
nomaxvaluer+   r{   r.   tbl_br   i)	incrementr6  minvaluemaxvaluer   r   r   r   r   r0   r3   r3   r4   r5     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 )Nr{   r   r!  r)  rQ   r*   r{   )r<   r=   r4  r>   r9  r?   r3   r3   r4   rA     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)  rQ   )r<   r   r   r&  r=   r4  rP   rQ   r*   rG   r   r9  rI   r@   r/  r3   r3   r4   r0    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=   r4  rQ   r*   rP   rG   r   rA  r3   r3   r4   r1    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=   r4  r>   r3   r@   rI   r3   r4   fn  s   

z7IdentityColumnTest.test_insert_always_error.<locals>.fn)r   r%   r&   )rI   r@   rD  r3   rC  r4   test_insert_always_error  s   z+IdentityColumnTest.test_insert_always_errorN)rV   rW   rX   rY   r   r  r  rZ   r5   rA   r0  r1  r   rN   identity_columns_standardrE  r3   r3   r3   r4   r2    s    

r2  c                   @   s(   e Zd ZdZdZedd Zdd ZdS )IdentityAutoincrementTestT)autoincrement_without_sequencec              
   C   s,   t d|tdtt dddtdtd d S )Ntblr*   T)r,   autoincrementr{   r.   r>  r0   r3   r3   r4   r5     s   z'IdentityAutoincrementTest.define_tablesc                 C   s<   | | jj ddi}| | jj  }t|d d S )Nr{   row)r7   rK  )r<   r=   rI  r>   r   r  r   rA  r3   r3   r4    test_autoincrement_with_identity  s   z:IdentityAutoincrementTest.test_autoincrement_with_identityN)rV   rW   rX   rY   r   rZ   r5   rL  r3   r3   r3   r4   rG    s    
rG  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   r(   )Nstuffr*   Tr+   r-   r`   r/   r0   r3   r3   r4   r5     r6   zExistsTest.define_tablesc              	   C   s8   | | jj ddddddddddddg d S )Nr7   	some datar9   r   r   rf   zsome other data)r<   r=   rN  r>   r?   r3   r3   r4   rA     s   
zExistsTest.insert_datac              	   C   s@   | j j}t|ttdt |jj	dk
 dg d S )Nr7   rO  rk   r=   rN  r   r<   r   r   r  r   rQ   r-   rG   rI   r@   rN  r3   r3   r4   test_select_exists  s   zExistsTest.test_select_existsc              	   C   s>   | j j}t|ttdt |jj	dk
 g  d S )Nr7   zno datarP  rQ  r3   r3   r4   test_select_exists_false  s   z#ExistsTest.test_select_exists_falseN)	rV   rW   rX   rY   rZ   r5   rA   rR  rS  r3   r3   r3   r4   rM    s    

rM  c                   @   s&   e Zd ZdZeejjdd ZdS )DistinctOnTestTc                 C   sX   t dtdtd}td | |d W d    d S 1 s%w   Y  d S )Nr+  r_   r  z:DISTINCT ON is currently supported only by the PostgreSQL zSELECT DISTINCT * FROM foo)r   rB  r   r&  r   r   expect_deprecatedrY  )rI   stmr3   r3   r4   test_distinct_on.  s   "zDistinctOnTest.test_distinct_onN)	rV   rW   rX   rY   r   fails_ifrN   supports_distinct_onrW  r3   r3   r3   r4   rT  +  s    rT  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)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   r0   r3   r3   r4   r5   ;  s   z'IsOrIsNotDistinctFromTest.define_tables)both_int_differentr   r7   r7   )both_int_samer7   r7   r   )one_null_firstNr7   r7   )one_null_secondr   Nr7   )	both_nullNNr   iaaaz3col_a_value, col_b_value, expected_row_count_for_is)id_r   c                 C   s   | j j}|| d||dg || |jj|jj	
 }tt|| |dkr1dnd}|| |jj|jj	
 }tt|| d S )Nr7   )r*   r]  r^  r   )r=   r\  r<   r>   r   r  rQ   r]  is_distinct_fromr^  rG   r   r   is_not_distinct_from)rI   col_a_valuecol_b_valueexpected_row_count_for_isr@   rI  rJ   expected_row_count_for_is_notr3   r3   r4   test_is_or_is_not_distinct_fromE  s2   z9IsOrIsNotDistinctFromTest.test_is_or_is_not_distinct_fromN)
rV   rW   rX   rY   r   rZ   r5   r   r  rl  r3   r3   r3   r4   rZ  7  s    
		rZ  c                   @   r"  )WindowFunctionTest)window_functionsTc                 C   r   )Nr)   r*   Tr+   col1col2r   r0   r3   r3   r4   r5   q  r   z WindowFunctionTest.define_tablesc                 C   s(   | | jj dd tddD  d S )Nc                 S   s   g | ]
}|||d  dqS )rr   )r*   ro  rp  r3   r+  ir3   r3   r4   r,    s    z2WindowFunctionTest.insert_data.<locals>.<listcomp>r7   r`   )r<   r=   r)   r>   r!  r?   r3   r3   r4   rA   {  r*  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)rP   r   c                 S   s   g | ]}d qS ))_   r3   rq  r3   r3   r4   r,    s    z2WindowFunctionTest.test_window.<locals>.<listcomp>   )r=   r)   r<   r   r   maxrQ   rp  overro  r{   r  r   r   r!  rI   r@   r)   r  r3   r3   r4   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   )rP   r  c                 S   s   g | ]}|fqS r3   r3   rq  r3   r3   r4   r,    s    z?WindowFunctionTest.test_window_rows_between.<locals>.<listcomp>rr      )r=   r)   r<   r   r   ru  rQ   rp  rv  ro  r   r   r!  rw  r3   r3   r4   test_window_rows_between  s    	z+WindowFunctionTest.test_window_rows_betweenN)
rV   rW   rX   r   rY   rZ   r5   rA   rx  rz  r3   r3   r3   r4   rm  l  s    
	
rm  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 )r7   )r   r!  r3   rq  r3   r3   r4   r,    s    zBitwiseTest.<listcomp>r   c                 C   s   t d|tdttdt d S )Nbitwiser   r!  r   r0   r3   r3   r4   r5     s   zBitwiseTest.define_tablesc                 C   s   | | jj | j d S rC   )r<   r=   r|  r>   inserted_datar?   r3   r3   r4   rA     s   zBitwiseTest.insert_datac                 C   
   |  dS )Nrr   )bitwise_xorr   r3   r3   r4   <lambda>     
 zBitwiseTest.<lambda>c                 C   s   g | ]}|d kr|qS rq   r3   rq  r3   r3   r4   r,    s    c                 C   r~  Nr7   )
bitwise_orr  r3   r3   r4   r    r  c                 C   r~  )Nrf   )bitwise_andr  r3   r3   r4   r    r  rf   r  c                 C   s   | d   S Nr   )bitwise_notr  r3   r3   r4   r    s    r   c                 C   r~  r  )bitwise_lshiftr  r3   r3   r4   r    r  r7   c                 C   r~  r  )bitwise_rshiftr  r3   r3   r4   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 r3   )r}  rq  r  r3   r4   r,    s    z,BitwiseTest.test_bitwise.<locals>.<listcomp>)r=   r|  rQ   r   r   resolve_lambdar   r  rP   r<   mappingsr   r   )	rI   r   r   r@   rI  r   opr   r/  r3   r  r4   test_bitwise  s   "zBitwiseTest.test_bitwiseN)rV   rW   rX   rY   r  r  r!  r}  rZ   r5   rA   r   r  rN   supports_bitwise_xorlistsupports_bitwise_orsupports_bitwise_andsupports_bitwise_notsupports_bitwise_shiftr  r3   r3   r3   r4   r{    sH    


!r{  )@collections.abcr  r  r.  rl  r   r   r   r   
assertionsr   r   r	   	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&   
TablesTestr'   r\   TestBaser   r   r  r  r5  rI  rr  r  r#  r2  rG  rM  rT  rZ  rm  r{  r3   r3   r3   r4   <module>   s   &M   Jcd
w     +P/53