U
    x^,                     @   s   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 G dd dejZG dd dejZG dd dejejZdS )    N   )config)engines)fixtures)eq_)requirements)Column)Table   )DateTime)func)Integer)select)sql)String)testing)textc                   @   sV   e Zd ZdZedd Zedd Zdd Zdd	 Zd
d Z	e
jdd Zdd ZdS )RowFetchTestTc                 C   sD   t d|tdtddtdtd t d|tdtddtdt d S )	Nplain_pkidTZprimary_keydata2   	has_datestoday)r	   r   r   r   r   clsmetadata r   M/tmp/pip-install-dq5v43_d/SQLAlchemy/sqlalchemy/testing/suite/test_results.pydefine_tables   s    zRowFetchTest.define_tablesc                 C   s`   t j| jj dddddddddg t j| jj dtdd	d
d
dddg d S )N   d1)r   r   r   Zd2r
   Zd3        r   )r   r   )r   dbexecutetablesr   insertr   datetime)r   r   r   r   insert_data&   s    
	
zRowFetchTest.insert_datac                 C   sF   t j| jj | jjjj	 }t
|d d t
|d d d S )Nr   r!   r   r"   r   r&   r'   r(   r   r   order_bycr   firstr   selfrowr   r   r   test_via_string6   s
    zRowFetchTest.test_via_stringc                 C   sF   t j| jj | jjjj	 }t
|d d t
|d d d S )Nr   r!   r"   r,   r0   r   r   r   test_via_int>   s
    zRowFetchTest.test_via_intc                 C   sV   t j| jj | jjjj	 }t
|| jjjj d t
|| jjjj d d S )Nr!   r"   )r   r&   r'   r(   r   r   r-   r.   r   r/   r   r   r0   r   r   r   test_via_col_objectF   s
    z RowFetchTest.test_via_col_objectc                 C   s`   t jt| jjjj| jjjjdg	| jjjj
}| }t| ddg t|d d S )Nr   )r"   r"   )r   r&   r'   r   r(   r   r.   r   labelr-   r   r/   r   keys)r1   resultr2   r   r   r   test_row_with_dupe_namesN   s    

z%RowFetchTest.test_row_with_dupe_namesc              
   C   sh   | j j}t|djjg }t|jj|dg}t	j
| }t|d tdddddd dS )ztest that a scalar select as a column is returned as such
        and that type conversion works OK.

        (this is half a SQLAlchemy Core test and half to catch database
        backends that may have unusual behavior with scalar selects.)

        xZ	somelabelr#   r$   r%   r   N)r(   r   r   aliasr.   r   Z	as_scalarr   r6   r   r&   r'   r/   r   r*   )r1   Z	datetabless2r2   r   r   r   test_row_w_scalar_select\   s
    z%RowFetchTest.test_row_w_scalar_selectN)__name__
__module____qualname____backend__classmethodr    r+   r3   r4   r5   r   Z%duplicate_names_in_cursor_descriptionr9   r>   r   r   r   r   r      s   


r   c                   @   s<   e Zd ZdZdZdZedd Zdd Zdd	 Z	d
d Z
dS )PercentSchemaNamesTestztests using percent signs, spaces in table and column names.

    This is a very fringe use case, doesn't work for MySQL
    or PostgreSQL.  the requirement, "percent_schema_names",
    is marked "skip" by default.

    )Zpercent_schema_namesTc                 C   s@   t d|tdttdt| j_tdtdtd| j_d S )Nzpercent%tablepercent%spaces % more spaces)	r	   r   r   r(   percent_tabler   tablecolumnlightweight_percent_tabler   r   r   r   r    y   s    z$PercentSchemaNamesTest.define_tablesc                 C   sP   | j j}ddddddddddddfD ]}tj| | q,|   d S Nr$   r%   )rE   rF         	   
   r(   rG   r   r&   r'   r)   _assert_table)r1   rG   paramsr   r   r   test_single_roundtrip   s    z,PercentSchemaNamesTest.test_single_roundtripc                 C   sV   | j j}tj| ddd tj| dddddddddg |   d S rK   rP   )r1   rG   r   r   r   test_executemany_roundtrip   s     z1PercentSchemaNamesTest.test_executemany_roundtripc                 C   sN  | j j}| j j}|| || fD ]}tttj|	 
|jd ddddg tttj|	 |jd ddg
|jd ddg tj|	 
|jd  }t|d d	 t|d d
 t||jd  d	 t||jd  d
 q$tj| |jd di tttj|	 
|jd ddddg d S )NrE   )r$   r%   )rL   rM   )rN   rO   )rM   rN   rF   rN   rO   r$   r%      )r$   rU   )rL   rU   )rN   rU   )rM   rU   )r(   rG   rJ   r;   r   listr   r&   r'   r   r-   r.   whereZin_r/   updatevalues)r1   rG   rJ   rH   r2   r   r   r   rQ      sb    
	
z$PercentSchemaNamesTest._assert_tableN)r?   r@   rA   __doc____requires__rB   rC   r    rS   rT   rQ   r   r   r   r   rD   l   s   
rD   c                   @   s   e Zd ZdZ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!d" Zejd#d$ Zd%S )&ServerSideCursorsTest)server_side_cursorsTc                 C   sd   | j jjdkr|jS | j jjdkr8tdjj}t||S | j jjdkr\tdjj}t||S dS d S )NZpsycopg2Zpymysqlzpymysql.cursorsZmysqldbzMySQLdb.cursorsF)enginedialectZdrivername
__import__ZcursorsZSSCursor
isinstance)r1   cursorZsscursorr   r   r   _is_server_side   s    

z%ServerSideCursorsTest._is_server_sidec                 C   s   t jd|id| _| jS )Nr]   )options)r   Ztesting_enginer^   )r1   r]   r   r   r   _fixture   s    zServerSideCursorsTest._fixturec                 C   s   t j  | j  d S )N)r   Ztesting_reaperZ	close_allr^   Zdispose)r1   r   r   r   tearDown   s    
zServerSideCursorsTest.tearDownc                 C   s(   |  d}|d}| |js$td S NTselect 1rf   r'   rd   rc   AssertionErrorr1   r^   r8   r   r   r   test_global_string   s    

z(ServerSideCursorsTest.test_global_stringc                 C   s,   |  d}|td}| |js(td S rh   rf   r'   r   rd   rc   rk   rl   r   r   r   test_global_text   s    
z&ServerSideCursorsTest.test_global_textc                 C   s.   |  d}|tdg}| |js*td S NTr!   )rf   r'   r   rd   rc   rk   rl   r   r   r   test_global_expr  s    
z&ServerSideCursorsTest.test_global_exprc                 C   s,   |  d}|td}| |jr(td S )NFri   rn   rl   r   r   r   test_global_off_explicit  s    
z.ServerSideCursorsTest.test_global_off_explicitc                 C   s:   |  d}tdgjdd}||}| |js6td S NFr!   TZstream_resultsrf   r   execution_optionsr'   rd   rc   rk   r1   r^   r<   r8   r   r   r   test_stmt_option  s    

z&ServerSideCursorsTest.test_stmt_optionc                 C   s4   |  d}| jddd}| |js0td S )NFTrt   ri   )rf   connectrv   r'   rd   rc   rk   rl   r   r   r   test_conn_option  s    
z&ServerSideCursorsTest.test_conn_optionc                 C   sF   |  d}tdgjdd}| jdd|}| |jrBtd S rs   )rf   r   rv   ry   r'   rd   rc   rk   rw   r   r   r   &test_stmt_enabled_conn_option_disabled$  s
    
z<ServerSideCursorsTest.test_stmt_enabled_conn_option_disabledc                 C   s:   |  d}tdgjdd}||}| |jr6td S )NTr!   Frt   ru   rw   r   r   r   test_stmt_option_disabled/  s    

z/ServerSideCursorsTest.test_stmt_option_disabledc                 C   sf   |  d}tdgjdd }||}| |js:ttdg|d}||}| |jrbtd S )NFr!   Trt   )Zfrom_obj)rf   r   rv   r;   r'   rd   rc   rk   )r1   r^   s1r8   r=   r   r   r   test_aliases_and_ss5  s    


z)ServerSideCursorsTest.test_aliases_and_ssc                 C   s6   |  d}tdg }||}| |js2td S rp   )rf   r   Zwith_for_updater'   rd   rc   rk   )r1   r^   r}   r8   r   r   r   test_for_update_exprA  s    

z*ServerSideCursorsTest.test_for_update_exprc                 C   s(   |  d}|d}| |js$td S )NTzSELECT 1 FOR UPDATErj   rl   r   r   r   test_for_update_stringG  s    

z,ServerSideCursorsTest.test_for_update_stringc                 C   s0   |  d}td}||}| |jr,td S )NF	select 42)rf   r   r'   rd   rc   rk   rw   r   r   r   test_text_no_ssL  s    

z%ServerSideCursorsTest.test_text_no_ssc                 C   s8   |  d}tdjdd}||}| |js4td S )NFr   Trt   )rf   r   rv   r'   rd   rc   rk   rw   r   r   r   test_text_ss_optionR  s    

z)ServerSideCursorsTest.test_text_ss_optionc                 C   s   | j }| d td|tdtddtdtd}|jdd | jdd	 | jd
d	 t	|
 |jj  ddg | |jjdkj|jjd d	  t	|
 |jj  ddg |   t	t
tdg| d d S )NT
test_tabler   r   r   r   )Z
checkfirstdata1)r   data2)r!   r   )r   r   r   z updated)r   zdata2 updated*r   )r   rf   r	   r   r   r   creater)   r'   r   r   r-   r.   r   ZfetchallrX   rW   rY   r   deleter   countselect_fromZscalar)r1   Zmdr   r   r   r   test_roundtripX  s0    


z$ServerSideCursorsTest.test_roundtripN)r?   r@   rA   r[   rB   rd   rf   rg   rm   ro   rq   rr   rx   rz   r{   r|   r~   r   r   r   r   r   Zprovide_metadatar   r   r   r   r   r\      s(   
r\   )r*    r   r   r   Z
assertionsr   r   Zschemar   r	   r   r   r   r   r   r   r   r   Z
TablesTestr   rD   ZTestBaseZAssertsExecutionResultsr\   r   r   r   r   <module>   s*   Xn
 