3
(h O                 @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
Z
yd dlZejZW n ek
rz   Y nX dddgZG dd de	jZG d	d de	jZG d
d de	jZdS )    N)cursors)	text_type)baseTestOldIssuesTestNewIssuesTestGitHubIssuesc               @   sf   e 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ejddd ZdS )r   c             C   s   | j d }|j }tj  tjd |jd W dQ R X |jd z|jdd |jd | jd|j d  |jd | jd|j d  |jd	 | jd|j d  |jd
 | jt	|j d t
j
 W d|jd X dS )z2 undefined methods datetime_or_None, date_or_None r   ignorezdrop table if exists issue3Nz?create table issue3 (d date, t time, dt datetime, ts timestamp)z6insert into issue3 (d, t, dt, ts) values (%s,%s,%s,%s)zselect d from issue3zselect t from issue3zselect dt from issue3zselect ts from issue3zdrop table issue3)NNNN)connectionscursorwarningscatch_warningsfilterwarningsexecuteassertEqualfetchone
assertTrue
isinstancedatetime)selfconnc r   >/tmp/pip-install-q3hcpn_q/PyMySQL/pymysql/tests/test_issues.pytest_issue_3   s"    







zTestOldIssues.test_issue_3c             C   s   | j d }|j }tj  tjd |jd W dQ R X |jd z2|jd |jd | jt|j d t	j	 W d|jd X dS )	z! can't retrieve TIMESTAMP fields r   r   zdrop table if exists issue4Nz"create table issue4 (ts timestamp)z&insert into issue4 (ts) values (now())zselect ts from issue4zdrop table issue4)
r	   r
   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   test_issue_4+   s    





zTestOldIssues.test_issue_4c             C   s    | j d }|j }|jd dS )z* query on information_schema.tables fails r   z'select * from information_schema.tablesN)r	   r
   r   )r   concurr   r   r   test_issue_5:   s    
zTestOldIssues.test_issue_5c             C   s@   | j d j }d|d< tjf |}|j }|jd |j  dS )zP exception: TypeError: ord() expected a character, but string of length 0 found r   Zmysqldbzselect * from userN)	databasescopypymysqlconnectr
   r   close)r   kwargsr   r   r   r   r   test_issue_6@   s    
zTestOldIssues.test_issue_6c             C   s   | j d }|j }tj  tjd |jd W dQ R X |jd z2| jd|jd |jd | jd|jd W d|jd X dS )	z1 Primary Key and Index error when selecting data r   r   zdrop table if exists testNa  CREATE TABLE `test` (`station` int(10) NOT NULL DEFAULT '0', `dh`
datetime NOT NULL DEFAULT '2015-01-01 00:00:00', `echeance` int(1) NOT NULL
DEFAULT '0', `me` double DEFAULT NULL, `mo` double DEFAULT NULL, PRIMARY
KEY (`station`,`dh`,`echeance`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;zSELECT * FROM testz6ALTER TABLE `test` ADD INDEX `idx_station` (`station`)zdrop table test)r	   r
   r   r   r   r   r   )r   r   r   r   r   r   test_issue_8J   s    



zTestOldIssues.test_issue_8c             C   s.   yt t W n tk
r(   | j  Y nX dS )z' sets DeprecationWarning in Python 2.6 N)reloadr!   DeprecationWarningfail)r   r   r   r   test_issue_9\   s    zTestOldIssues.test_issue_9c             C   s   | j d }|j }tj  tjd |jd W dQ R X zL|jd d}|jdd	| f |jd
 |j d }| jd	| |k W d|jd X dS )z" can't handle large result fields r   r   zdrop table if exists issue13Nzcreate table issue13 (t text)   i   z#insert into issue13 (t) values (%s)xzselect t from issue13zdrop table issue13i H  )r	   r
   r   r   r   r   r   r   )r   r   r   sizerr   r   r   test_issue_13c   s    




zTestOldIssues.test_issue_13c             C   s   | j d }|j }tj  tjd |jd W dQ R X |jd z.|jdd
 |jd | jd|j d  W d|jd	 X dS )z< query should be expanded before perform character encoding r   r   zdrop table if exists issue15Nz$create table issue15 (t varchar(32))z#insert into issue15 (t) values (%s)   äöüzselect t from issue15zdrop table issue15)r0   )r	   r
   r   r   r   r   r   r   )r   r   r   r   r   r   test_issue_15v   s    




zTestOldIssues.test_issue_15c             C   s   | j d }|j }tj  tjd |jd W dQ R X |jd z.|jd |jdd | jd	|j d  W d|jd
 X dS )z% Patch for string and tuple escaping r   r   zdrop table if exists issue16NzFcreate table issue16 (name varchar(32) primary key, email varchar(32))z@insert into issue16 (name, email) values ('pete', 'floydophone')z'select email from issue16 where name=%speteZfloydophonezdrop table issue16)r2   )r	   r
   r   r   r   r   r   r   )r   r   r   r   r   r   test_issue_16   s    




zTestOldIssues.test_issue_16zRtest_issue_17() requires a custom, legacy MySQL configuration and will not be run.c             C   s   | j d }| jd d }| jd d }|j }ztj  tjd |jd W dQ R X |jd |jd |jd	|  |j  tj	|d
d|d}|j }|jd | j
d|j d  W d|jd X dS )z#could not connect mysql use passwodr   hostr   r   zdrop table if exists issue17Nz0create table issue17 (x varchar(32) primary key)z0insert into issue17 (x) values ('hello, world!')zMgrant all privileges on %s.issue17 to 'issue17user'@'%%' identified by '1234'Zissue17userZ1234)r4   userpasswdr   zselect x from issue17zhello, world!zdrop table issue17)r	   r   r
   r   r   r   r   commitr!   r"   r   r   )r   r   r4   r   r   Zconn2c2r   r   r   test_issue_17   s"    





zTestOldIssues.test_issue_17N)__name__
__module____qualname__r   r   r   r%   r&   r*   r/   r1   r3   	unittest2skipr9   r   r   r   r   r      s   
c               @   sN   e Zd Zdd Zdd Zejddd Zdd	 Zd
d Z	dd Z
dd ZdS )r   c             C   sr   yt jdddd | j  W nP t jk
rR } z| jd|jd  W Y d d }~X n tk
rl   | j  Y nX d S )N	localhosti  root)r4   portr5   i  r   )r!   r"   r)   OperationalErrorr   args	Exception)r   er   r   r   test_issue_34   s    "zTestNewIssues.test_issue_34c             C   s\   t jf ddi| jd }| j|dd |j }|jd |jd | jd|j d  d S )	Ncharsetutf8r   u   heißeu&   create table heiße (name varchar(32))u,   insert into heiße (name) values ('Pißata')u   select name from heißeu   Pißata)r!   r"   r   safe_create_tabler
   r   r   r   )r   r   r   r   r   r   test_issue_33   s    

zTestNewIssues.test_issue_33z&This test requires manual interventionc             C   sl   | j d }|j }td y|jd | j  W n6 tjk
rf } z| jd|jd  W Y d d }~X nX d S )Nr   z1sudo killall -9 mysqld within the next 10 secondszselect sleep(10)i  )	r	   r
   printr   r)   r!   rB   r   rC   )r   r   r   rE   r   r   r   test_issue_35   s    

zTestNewIssues.test_issue_35c             C   s  | j d }|j }|jd d }x.|j D ]"}|d }|d }|dkr*|}P q*W | j||j  | j d j| y|jd | j  W n tk
r   Y nX |j	  |j	  zFt
jd | j d j }|jd dd |j D }| j||k W d | j d= X d S )	N   zshow processlistr      zshow tablesg?c             S   s   g | ]}|d  qS )r   r   ).0rowr   r   r   
<listcomp>   s    z/TestNewIssues.test_issue_36.<locals>.<listcomp>)r	   r
   r   fetchallr   Z	thread_idkillr)   rD   r#   timesleepassertFalse)r   r   r   Zkill_idrP   idinfoidsr   r   r   test_issue_36   s4    




zTestNewIssues.test_issue_36c             C   sT   | j d }|j }| jd|jd | jd|j  | jd|jd |jd d S )Nr   rM   zSELECT @foozSET @foo = 'bar'zset @foo = 'bar')N)r	   r
   r   r   r   )r   r   r   r   r   r   test_issue_37   s    
zTestNewIssues.test_issue_37c             C   st   | j d }|j }dd d }zDtj  tjd |jd W d Q R X |jd |jd|f W d |jd	 X d S )
Nr   ai   i  r   zdrop table if exists issue38z2create table issue38 (id integer, data mediumblob)z"insert into issue38 values (1, %s)zdrop table issue38)r	   r
   r   r   r   r   )r   r   r   Zdatumr   r   r   test_issue_38   s    



zTestNewIssues.test_issue_38c             C   s   | j d }|j }tj  tjd |jd W d Q R X d}|djdd tddD 7 }z6|jd	 |jd
 |j| | jd|j	 d  W d |jd X d S )Nr   r   zdrop table if exists issue54zselect * from issue54 where z and c             s   s   | ]}d ||f V  qdS )z%d=%dNr   )rO   ir   r   r   	<genexpr>  s    z7TestNewIssues.disabled_test_issue_54.<locals>.<genexpr>i z-create table issue54 (id integer primary key)z#insert into issue54 (id) values (7)rN   zdrop table issue54)
r	   r
   r   r   r   r   joinranger   r   )r   r   r   Zbig_sqlr   r   r   disabled_test_issue_54  s    





z$TestNewIssues.disabled_test_issue_54N)r:   r;   r<   rF   rJ   r=   r>   rL   rZ   r[   r]   rb   r   r   r   r   r      s   		$c               @   sT   e 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S )r   c             C   s   | j d }|j }| jd|j  zZtj  tjd |jd W dQ R X |jd |jd |jd | jd|j  W d|jd X dS )	z2 'Connection' object has no attribute 'insert_id' r   r   zdrop table if exists issue66NzGcreate table issue66 (id integer primary key auto_increment, x integer)z"insert into issue66 (x) values (1)   zdrop table issue66)r	   r
   r   Z	insert_idr   r   r   r   )r   r   r   r   r   r   test_issue_66  s    





zTestGitHubIssues.test_issue_66c             C   s   | j d }|jtjj}tj $ tjd |jd |jd W dQ R X |jd |jd d}d}zb|jd| |jd| |jd |j	 d }| j
|d d | j
|d d	 | j
|d d
 W d|jd |jd X dS )zI Duplicate field overwrites the previous one in the result of DictCursor r   r   zdrop table if exists azdrop table if exists bNz"CREATE TABLE a (id int, value int)z"CREATE TABLE b (id int, value int)rM         zinsert into a values (%s, %s)zinsert into b values (%s, %s)z+SELECT * FROM a inner join b on a.id = b.idrW   valuezb.valuezdrop table azdrop table b)rM   re   )rM   rf   )r	   r
   r!   r   Z
DictCursorr   r   r   r   rR   r   )r   r   r   r\   br.   r   r   r   test_issue_79'  s(    







zTestGitHubIssues.test_issue_79c             C   s   | j d }|j }tj  tjd |jd W dQ R X |jd z,|jd |jd | j|j d d W dtj  tjd |jd W dQ R X X dS )	z6 Leftover trailing OK packet for "CALL my_sp" queries r   r   zDROP PROCEDURE IF EXISTS `foo`NzICREATE PROCEDURE `foo` ()
        BEGIN
            SELECT 1;
        ENDz
CALL foo()zSELECT 1rM   )r	   r
   r   r   r   r   r   r   )r   r   r   r   r   r   test_issue_95B  s    






zTestGitHubIssues.test_issue_95c             C   s   t jf ddi| jd }|jd |j }|jd | j|j d  |j  |j	  |jd | j|j d  |j  t jf ddi| jd }|j }|jd | j|j d  |j  |j	  |jd |jd | j
|j d  |j  dS )z6 autocommit is not set after reconnecting with ping() rG   rH   r   Fzselect @@autocommit;TN)r!   r"   r   Z
autocommitr
   r   rV   r   r#   Zpingr   )r   r   r   r   r   r   test_issue_114V  s(    





zTestGitHubIssues.test_issue_114c             C   s   | j d }|j }xdD ]|}djdd t|D }dj|}z*|j| |jd t|j|ksftW d	t	j
  t	jd
 |jd W d	Q R X X qW d	S )z> The number of fields returned by server is read in wrong way r      ,  z, c             s   s   | ]}d j |V  qdS )zc{0} integerN)format)rO   r^   r   r   r   r_   t  s    z2TestGitHubIssues.test_issue_175.<locals>.<genexpr>z#create table test_field_count ({0})zselect * from test_field_countNr   z%drop table if exists test_field_count)rl   rm   )r	   r
   r`   ra   rn   r   lendescriptionAssertionErrorr   r   r   )r   r   r   lengthcolumnssqlr   r   r   test_issue_175o  s    






zTestGitHubIssues.test_issue_175c             C   s   t jf ddi| jd }| j|dd d}d}d}dd
gdgd
gdggd
dg}|j }| j|j||d d | j|j||d d | j|j||d d | j|j|dd
gd | j|j d | j|j d | j|j d dS )z" Test iterable as query argument. rG   rH   r   Zissue321z>create table issue321 (value_1 varchar(1), value_2 varchar(1))z7insert into issue321 (value_1, value_2) values (%s, %s)zIinsert into issue321 (value_1, value_2) values (%(value_1)s, %(value_2)s)z9select * from issue321 where value_1 in %s and value_2=%sr\      аrh   r   )Zvalue_1Zvalue_2rM   rc      N)r\   )r\   rh   r   )r\   rv   )rh   rv   )r   rv   )r!   r"   r   rI   r
   r   r   r   )r   r   Z
sql_insertZsql_dict_insertZ
sql_selectdatar   r   r   r   test_issue_321  s&    zTestGitHubIssues.test_issue_321c             C   s   t jf ddi| jd }| j|dd d}d}t jddg}|j }|j||d	 |jd
 | j|j t	| |j||d	 |j
||||fd	 |jd
 x |j D ]}| j|t	| qW |j
||||fd	 dS )z5 Test mixed unicode/binary arguments in executemany. rG   rH   r   Zissue364z`create table issue364 (value_1 binary(3), value_2 varchar(3)) engine=InnoDB default charset=utf8z7insert into issue364 (value_1, value_2) values (%s, %s)s     u   äöü)rC   zselect * from issue364N)r!   r"   r   rI   Binaryr
   r   r   r   tupleZexecutemanyrR   )r   r   rt   Zusqlvaluesr   rP   r   r   r   test_issue_364  s"    

zTestGitHubIssues.test_issue_364c             C   sD  t jf ddi| jd }| j|dd |j }d}| j|drf| jt jj}|j	| W d	Q R X n
|j	| d
}| j|dr| jt jj}|j	| W d	Q R X n
|j	| |j
 }| j|d d}| j|d r| jt jj}|j	| W d	Q R X n
|j	| |j
 }| j|d |j	d |j
 }| jt|d t d	S )z Test binary / geometry types. rG   rH   r   Zissue363zCREATE TABLE issue363 ( id INTEGER PRIMARY KEY, geom LINESTRING NOT NULL, SPATIAL KEY geom (geom)) ENGINE=MyISAM default charset=utf8zYINSERT INTO issue363 (id, geom) VALUES(1998, GeomFromText('LINESTRING(1.1 1.1,2.2 2.2)'))   rN   Nz!SELECT AsText(geom) FROM issue363LINESTRING(1.1 1.1,2.2 2.2)z#SELECT AsBinary(geom) FROM issue363)         ??@@zSELECT geom FROM issue363)r~   rN   r   )r~   rN   r   )r   )r~   rN   r   )r   )r!   r"   r   rI   r
   Zmysql_server_isZassertWarnserrWarningr   r   r   r   r   bytes)r   r   r   querycmrP   r   r   r   test_issue_363  s8    



zTestGitHubIssues.test_issue_363c             C   s   t jf ddi| jd }tj  tjd tjdt jd xtjtj	fD ]}|j
|}zy|jd |j  W n^ t jk
r } z@| jt|jd | j|jd d	 | jt|jd
 t W Y dd}~X nX | jd W d|j  X qLW W dQ R X dS )z Test warning propagation rG   rH   r   r   error)categoryzSELECT CAST('124b' AS SIGNED)rc   i  rM   NzShould raise Warning)r!   r"   r   r   r   simplefilterr   r   CursorZSSCursorr
   r   rR   r   ro   rC   r   r   r   r)   r#   )r   r   Zcursor_classr   rE   r   r   r   test_issue_491  s    



(zTestGitHubIssues.test_issue_491N)r:   r;   r<   rd   ri   rj   rk   ru   ry   r}   r   r   r   r   r   r   r     s   4)r   rT   r   sysr!   r   Zpymysql._compatr   Zpymysql.testsr   r=   impr'   AttributeError__all__ZPyMySQLTestCaser   r   r   r   r   r   r   <module>   s$   

 i