o
    i	Z                     @   s  d dl mZ d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ ddl m	Z	 dd	l m
Z
 dd
l mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ ddl mZ G dd dejZG dd dejZG dd dejZG dd dejZG d d! d!ejZG d"d# d#ejZG d$d% d%ejZ G d&d' d'ejZ!d(S ))   )config)fixtures)eq_)in_)Column)Table   )	bindparam)case)Computed)false)func)Integer)literal_column)null)select)String)testing)text)true)tuple_)union)utilc                   @   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 r%   _/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_select.pydefine_tables      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r#   
connectionr%   r%   r&   insert_data%   s   
zCollateTest.insert_datac                 C      t tj| | d S Nr   r   dbr.   fetchallselfr   resultr%   r%   r&   _assert_result/      zCollateTest._assert_resultc                 C   sD   t jt j}| t| jjg| jjj	j
| ddg d S )N)r)   r*   )r   r,   )r   requiresget_order_by_collationr   r<   r   r/   r   order_bycr   collateasc)r:   	collationr%   r%   r&   test_collate_order_by2   s   z!CollateTest.test_collate_order_byN)__name__
__module____qualname____backend__classmethodr'   r3   r<   r   r>   order_by_collationrE   r%   r%   r%   r&   r      s    

	r   c                   @   sl   e Zd ZdZdZedd Zedd Zdd Zd	d
 Z	dd Z
dd Z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"   r%   r%   r&   r'   I   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 )Nr)   r   q1p3)r   rM   rN   rO   rQ   r   q2p2   q3p1r-   r1   r%   r%   r&   r3   U   s   
zOrderByLabelTest.insert_datac                 C   r4   r5   r6   r9   r%   r%   r&   r<   `   r=   zOrderByLabelTest._assert_resultc                 C   s6   | j j}|jjd}| t|g|g d d S )Nlx)r)   r   r   )r/   r   rA   rM   labelr<   r   r@   r:   tablerY   r%   r%   r&   
test_plainc   s    zOrderByLabelTest.test_plainc                 C   s>   | j j}|jj|jj d}| t|g|g d d S )NrY   )r\         )	r/   r   rA   rM   rN   r]   r<   r   r@   r^   r%   r%   r&   test_composed_inth   s    z"OrderByLabelTest.test_composed_intc              	   C   s   | j j}|jj|jj d}t|jj|jj	 d}| 
t||g|| dtdfdtdfdtdfg d S )	NrY   lyr   q1p3rb   q2p2rd   q3p1)r/   r   rA   rM   rN   r]   r   lowerrO   rQ   r<   r   r@   descr   u)r:   r_   rY   rf   r%   r%   r&   test_composed_multiplem   s   &z'OrderByLabelTest.test_composed_multiplec                 C   s:   | j j}|jjd}| t|g| g d d S )NrY   )r\   r[   rZ   )	r/   r   rA   rM   r]   r<   r   r@   rk   r^   r%   r%   r&   test_plain_descv   s
   z OrderByLabelTest.test_plain_descc                 C   sB   | j j}|jj|jj d}| t|g|	 g d d S )NrY   )rc   ra   r\   )
r/   r   rA   rM   rN   r]   r<   r   r@   rk   r^   r%   r%   r&   test_composed_int_desc}   s
   z'OrderByLabelTest.test_composed_int_descc                 C   sT   | j j}|jj|jj d}tt|jj	|g
||}| |g d d S )NrY   ))r)   r   )r)   rb   )r)   rd   )r/   r   rA   rM   rN   r]   r   r   countr   group_byr@   r<   )r:   r_   exprstmtr%   r%   r&   test_group_by_composed   s   z'OrderByLabelTest.test_group_by_composedN)rF   rG   rH   __doc__rI   rJ   r'   r3   r<   r`   re   rm   rn   ro   r   r>   group_by_complex_expressionrt   r%   r%   r%   r&   rL   >   s    


	rL   c                   @   s   e Zd ZdZedd Zedd Zd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dS )LimitOffsetTestTc                 C   *   t d|tdtddtdttdt d S Nr   r   Tr   rM   rN   r   r   r   r"   r%   r%   r&   r'         zLimitOffsetTest.define_tablesc              
   C   @   | | jj ddddddddddddddddg d S Nr)   r   )r   rM   rN   r   rV   rb   r-   r1   r%   r%   r&   r3         




zLimitOffsetTest.insert_datar%   c                 C      t tj|| | d S r5   r6   r:   r   r;   paramsr%   r%   r&   r<         zLimitOffsetTest._assert_resultc                 C   2   | j j}| t|g|jjdddg d S )Nr   r)   r)   r   r   r   r   )r/   r   r<   r   r@   rA   r   limitr:   r_   r%   r%   r&   test_simple_limit   s
   z!LimitOffsetTest.test_simple_limitc                 C   r   )Nr   r   r   rV   rV   rV   rb   )r/   r   r<   r   r@   rA   r   offsetr   r%   r%   r&   test_simple_offset   s
   z"LimitOffsetTest.test_simple_offsetc                 C   s8   | j j}| t|g|jjddddg d S )Nr   r)   r   r   )	r/   r   r<   r   r@   rA   r   r   r   r   r%   r%   r&   test_simple_limit_offset   s
   z(LimitOffsetTest.test_simple_limit_offsetc                 C   sZ   | j j}t|g|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   r)   literal_bindsT)dialectcompile_kwargsr   r   N)r/   r   r   r@   rA   r   r   r   compiler   r7   r   strr<   )r:   r_   rs   sqlr%   r%   r&   test_limit_offset_nobinds   s    z)LimitOffsetTest.test_limit_offset_nobindsc                 C   >   | j j}| jt|g|jjtdddgddid d S )Nlr   r   r   r   )	r/   r   r<   r   r@   rA   r   r   r	   r   r%   r%   r&   test_bound_limit      
z LimitOffsetTest.test_bound_limitc                 C   r   )Nor   r   r   r   )	r/   r   r<   r   r@   rA   r   r   r	   r   r%   r%   r&   test_bound_offset   r   z!LimitOffsetTest.test_bound_offsetc                 C   sJ   | j j}| jt|g|jjtd	tdddgdddd d S )	Nr   r   r   r   r   r)   )r   r   r   )
r/   r   r<   r   r@   rA   r   r   r	   r   r   r%   r%   r&   test_bound_limit_offset   s   



z'LimitOffsetTest.test_bound_limit_offsetNr%   )rF   rG   rH   rI   rJ   r'   r3   r<   r   r   r>   r   r   r   r   bound_limit_offsetr   r   r   r%   r%   r%   r&   rw      s(    
	






rw   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   rx   ry   rz   r"   r%   r%   r&   r'      r{   z CompoundSelectTest.define_tablesc              
   C   r|   r}   r-   r1   r%   r%   r&   r3      r~   zCompoundSelectTest.insert_datar%   c                 C   r   r5   r6   r   r%   r%   r&   r<     r   z!CompoundSelectTest._assert_resultc                 C   s`   | j j}t|g|jjdk}t|g|jjdk}t||}| ||jjddg d S Nr   r   r   r   )	r/   r   r   whererA   r   r   r<   r@   r:   r_   s1s2u1r%   r%   r&   test_plain_union  s
   
z#CompoundSelectTest.test_plain_unionc                 C   sh   | j j}t|g|jjdk}t|g|jjdk}t||  }| |	|jjddg d S r   )
r/   r   r   r   rA   r   r   aliasr<   r@   r   r%   r%   r&   test_select_from_plain_union  s
   z/CompoundSelectTest.test_select_from_plain_unionc                 C   s   | j j}t|g|jjdkd|jj}t|g|jjdkd|jj}t||d}| 	||jjddg d S Nr   r)   r   r   r   )
r/   r   r   r   rA   r   r   r@   r   r<   r   r%   r%   r&   &test_limit_offset_selectable_in_unions  s   

z9CompoundSelectTest.test_limit_offset_selectable_in_unionsc                 C   sz   | j j}t|g|jjdk|jj}t|g|jjdk|jj}t||d}| 	||jjddg d S r   )
r/   r   r   r   rA   r   r@   r   r   r<   r   r%   r%   r&   "test_order_by_selectable_in_unions/  s
   ""z5CompoundSelectTest.test_order_by_selectable_in_unionsc                 C   sn   | j j}t|g|jjdk }t|g|jjdk }t||d}| 	|
|jjddg d S r   )r/   r   r   r   rA   r   distinctr   r   r<   r@   r   r%   r%   r&   "test_distinct_selectable_in_unions8  s
   z5CompoundSelectTest.test_distinct_selectable_in_unionsc                 C   s   | j j}t|g|jjdkd|jj}t|g|jjdkd|jj}t||	 }| 
| d|jjddg d S r   )r/   r   r   r   rA   r   r   r@   r   r   r<   r   r%   r%   r&   &test_limit_offset_in_unions_from_alias@  s   

z9CompoundSelectTest.test_limit_offset_in_unions_from_aliasc                 C   s   | j j}t|g|jjdkd|jj  }t|g|jjdkd|jj  }t	||d}| 
||jjddg d S r   )r/   r   r   r   rA   r   r   r@   r   r   r<   r   r%   r%   r&   .test_limit_offset_aliased_selectable_in_unionsV  s"   
	
	zACompoundSelectTest.test_limit_offset_aliased_selectable_in_unionsNr   )rF   rG   rH   rI   rJ   r'   r3   r<   r   r   r   r>   order_by_col_from_union/parens_in_union_contained_select_w_limit_offsetr   0parens_in_union_contained_select_wo_limit_offsetr   r   r   r   r%   r%   r%   r&   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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dd Zdd Zdd Zdd Zdd ZdS )!ExpandingBoundInTestTc              
   C   s6   t d|tdtddtdttdttdtd d S )	Nr   r   Tr   rM   rN   zrP   r!   r"   r%   r%   r&   r'   p  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 )Nr)   r   z1)r   rM   rN   r   r   z2rV   z3rb   z4r-   r1   r%   r%   r&   r3   {  s   
z ExpandingBoundInTest.insert_datar%   c                 C   r   r5   r6   r   r%   r%   r&   r<     r   z#ExpandingBoundInTest._assert_resultc                 C   sj   | j j}t|jjg|jjtddd|jj	tddd
|jj}| j|g g g dd d S )NrO   T	expandingrQ   )rO   rQ   r   )r/   r   r   rA   r   r   rM   r   r	   rN   r@   r<   r:   r_   rs   r%   r%   r&   test_multiple_empty_sets  s   
z-ExpandingBoundInTest.test_multiple_empty_setsc                 C   Z   | j j}t|jjgt|jj|jj	t
ddd|jj}| j|g dg id d S NrO   Tr   r   r/   r   r   rA   r   r   r   rM   r   r   r	   r@   r<   r   r%   r%   r&   test_empty_heterogeneous_tuples     


z4ExpandingBoundInTest.test_empty_heterogeneous_tuplesc                 C   r   r   r/   r   r   rA   r   r   r   rM   rN   r   r	   r@   r<   r   r%   r%   r&   test_empty_homogeneous_tuples  r   z2ExpandingBoundInTest.test_empty_homogeneous_tuplesc                 C   sX   | j j}t|jjg|jjtddd	|jj}| j
|g ddg did d S )NrO   Tr   r[   r\   rV   )r   r   rV   r   r/   r   r   rA   r   r   rM   r   r	   r@   r<   r   r%   r%   r&   test_bound_in_scalar  s   
 z)ExpandingBoundInTest.test_bound_in_scalarc                 C   b   | j j}t|jjgt|jj|jj	t
ddd|jj}| j|g ddg did d S )NrO   Tr   r   ))r   r   )r   rV   )rV   rb   r   r   r   r%   r%   r&   test_bound_in_two_tuple  s   



z,ExpandingBoundInTest.test_bound_in_two_tuplec                 C   r   )NrO   Tr   r   ))r   r   )r   r   )rV   r   r   r   r   r%   r%   r&   %test_bound_in_heterogeneous_two_tuple  s   




z:ExpandingBoundInTest.test_bound_in_heterogeneous_two_tuplec                 C   P   | j j}t|jjg|jjtddd	|jj}| j
|g dg id d S r   r   r   r%   r%   r&   test_empty_set_against_integer     
z3ExpandingBoundInTest.test_empty_set_against_integerc                 C   T   | j j}t|jjg|jjtddd	|jj}| j
|g ddg id d S NrO   Tr   )rZ   r[   r\   r   r   )r/   r   r   rA   r   r   rM   notin_r	   r@   r<   r   r%   r%   r&   'test_empty_set_against_integer_negation     
z<ExpandingBoundInTest.test_empty_set_against_integer_negationc                 C   r   r   )r/   r   r   rA   r   r   r   r   r	   r@   r<   r   r%   r%   r&   test_empty_set_against_string  r   z2ExpandingBoundInTest.test_empty_set_against_stringc                 C   r   r   )r/   r   r   rA   r   r   r   r   r	   r@   r<   r   r%   r%   r&   &test_empty_set_against_string_negation
  r   z;ExpandingBoundInTest.test_empty_set_against_string_negationc              	   C   sL   t tt tddddt fgt dg}ttj	|
 d d d S )Nfoor%   T)valuer   )else_    )Fr   )r   r
   r   r   r	   r   r   r   r7   r.   fetchone)r:   rs   r%   r%   r&   test_null_in_empty_set_is_false  s   z4ExpandingBoundInTest.test_null_in_empty_set_is_falseNr   )rF   rG   rH   rI   rJ   r'   r3   r<   r   r   r>   tuple_inr   r   r   r   r   r   r   r   r   r   r%   r%   r%   r&   r   m  s,    







r   c                   @   s   e Zd ZdZdZdZedd Zedd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% ZdS )&LikeFunctionsTestTonceNc                 C   r   )Nr   r   Tr   r   rP   r!   r"   r%   r%   r&   r'   .  r(   zLikeFunctionsTest.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ddddddddddg
 d S )Nr)   abcdefgr+   r   zab/cdefgr   zab%cdefgrV   ab_cdefgrb   zabcde/fg   zabcde%fgrd   zab#cdefg   ab9cdefg	   zabcde#fg
   abcd9fgr-   r1   r%   r%   r&   r3   7  s   
zLikeFunctionsTest.insert_datac                 C   sd   | j j}tj }dd |t|jjg	|D }W d    n1 s&w   Y  t
|| d S )Nc                 S   s   h | ]\}|qS r%   r%   ).0r   r%   r%   r&   	<setcomp>M  s    z*LikeFunctionsTest._test.<locals>.<setcomp>)r/   r   r   r7   connectr.   r   rA   r   r   r   )r:   rr   expectedr   connrowsr%   r%   r&   _testI  s   zLikeFunctionsTest._testc                 C   &   | j jjj}| |dh d d S )Nab%c
   r)   r   r   rV   rb   r   rd   r   r   r   r/   r   rA   r   r   
startswithr:   colr%   r%   r&   test_startswith_unescapedV     z+LikeFunctionsTest.test_startswith_unescapedc                 C   (   | j jjj}| |jddddh d S )Nr   T
autoescaper   r   r   r%   r%   r&   test_startswith_autoescapeZ     z,LikeFunctionsTest.test_startswith_autoescapec                 C   *   | j jjj}| |tdh d d S )Nz'ab%c'r   )r/   r   rA   r   r   r   r   r   r%   r%   r&   test_startswith_sqlexpr^  s
   z)LikeFunctionsTest.test_startswith_sqlexprc                 C   r   )Nzab##c#escaperd   r   r   r%   r%   r&   test_startswith_escapee  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#crd   r   r   r%   r%   r&   !test_startswith_autoescape_escapei     z3LikeFunctionsTest.test_startswith_autoescape_escapec                 C   r   )Ne%fg	   r)   r   r   rV   rb   r   rd   r   r   r/   r   rA   r   r   endswithr   r%   r%   r&   test_endswith_unescapedn  r   z)LikeFunctionsTest.test_endswith_unescapedc                 C   r   )Nz'e%fg'r  )r/   r   rA   r   r   r  r   r   r%   r%   r&   test_endswith_sqlexprr  s   z'LikeFunctionsTest.test_endswith_sqlexprc                 C   r   )Nr  Tr   r   r  r   r%   r%   r&   test_endswith_autoescapex  r   z*LikeFunctionsTest.test_endswith_autoescapec                 C   r   )Nze##fgr   r   r   r  r   r%   r%   r&   test_endswith_escape|  r   z&LikeFunctionsTest.test_endswith_escapec                 C   r  )Nr  Tr   r  r   ze#fgr   r  r   r%   r%   r&   test_endswith_autoescape_escape  r  z1LikeFunctionsTest.test_endswith_autoescape_escapec                 C   r   )Nb%cder  r/   r   rA   r   r   containsr   r%   r%   r&   test_contains_unescaped  r   z)LikeFunctionsTest.test_contains_unescapedc                 C   r   )Nr  Tr   r   r  r   r%   r%   r&   test_contains_autoescape  r   z*LikeFunctionsTest.test_contains_autoescapec                 C   r   )Nzb##cder   r   rd   r  r   r%   r%   r&   test_contains_escape  r   z&LikeFunctionsTest.test_contains_escapec                 C   r  )Nzb%cdTr   r  r   zb#cdrd   r  r   r%   r%   r&   test_contains_autoescape_escape  r  z1LikeFunctionsTest.test_contains_autoescape_escape)rF   rG   rH   rI   run_insertsrun_deletesrJ   r'   r3   r   r   r   r   r   r  r	  r
  r  r  r  r  r  r  r  r%   r%   r%   r&   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)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"   r%   r%   r&   r'     s   z ComputedColumnTest.define_tablesc                 C   s(   | | jj ddddddg d S )Nr)   r   )r   r  *   )r.   r/   r  r0   r1   r%   r%   r&   r3     s   
zComputedColumnTest.insert_datac                 C   sn   t j (}|ttdg| jj	| jjj
j }t|ddg W d    d S 1 s0w   Y  d S )N*)r)   r   r    (   )r   r       )r   r7   r   r.   r   r   select_fromr/   r  r@   rA   r   r8   r   r:   r   resr%   r%   r&   test_select_all  s   
"z"ComputedColumnTest.test_select_allc                 C   s|   t j /}|t| jjjj| jjjj	g
| jj| jjjj }t|ddg W d    d S 1 s7w   Y  d S )N)r    r  )r   r!  )r   r7   r   r.   r   r/   r  rA   r  r  r"  r@   r   r8   r   r#  r%   r%   r&   test_select_columns  s   
"z&ComputedColumnTest.test_select_columnsN)
rF   rG   rH   rI   __requires__rJ   r'   r3   r%  r&  r%   r%   r%   r&   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)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_a)nullablecol_brz   r"   r%   r%   r&   r'     s   z'IsOrIsNotDistinctFromTest.define_tables)both_int_differentr   r)   r)   )both_int_samer)   r)   r   )one_null_firstNr)   r)   )one_null_secondr   Nr)   )	both_nullNNr   iaaaz3col_a_value, col_b_value, expected_row_count_for_is)id_argnamesc                 C   s   | j j}|| d||dg |||jj|jj	 }t
t|| |dkr/dnd}|||jj|jj	 }t
t|| d S )Nr)   )r   r+  r-  r   )r/   r*  r.   r0   r   rA   r+  is_distinct_fromr-  r8   r   lenisnot_distinct_from)r:   col_a_valuecol_b_valueexpected_row_count_for_isr2   tblr;   expected_row_count_for_isnotr%   r%   r&   test_is_or_isnot_distinct_from  s.   z8IsOrIsNotDistinctFromTest.test_is_or_isnot_distinct_fromN)
rF   rG   rH   rI   r'  rJ   r'   r   combinationsr>  r%   r%   r%   r&   r(    s    
		r(  N)" r   r   
assertionsr   r   schemar   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
TablesTestr   rL   rw   r   r   r   r  r(  r%   r%   r%   r&   <module>   s>    %R_~ <o+