3
(h                 @   sb   d dl mZ d dlZd dlZd dlZG dd dejZG dd deZe	dkr^d dl
Z
e
j  dS )    )baseNc            	       s   e Zd Zddejddddddd	Zd
dejddddddd	Zddejddddddd	Zejj	Z
 fddZ fddZdd Zdd Zdd Z  ZS )TestDictCursorbob   i              8   )nameageDOBjimi     	         -   fredd   iw     c                sv   t t| j  | jd  | _}|j| j}tj $ tj	d |j
d |j
d W d Q R X dddg}|jd| d S )Nr   ignorezdrop table if exists dictcursorz?CREATE TABLE dictcursor (name char(20), age int , DOB datetime)r   r   1990-02-06 23:04:56r   r
   1955-05-09 13:12:45r   r   1911-09-12 01:01:01z(insert into dictcursor values (%s,%s,%s))r   r   r   )r   r
   r   )r   r   r   )superr   setUpconnectionsconncursorcursor_typewarningscatch_warningsfilterwarningsexecuteZexecutemany)selfr   cdata)	__class__ B/tmp/pip-install-q3hcpn_q/PyMySQL/pymysql/tests/test_DictCursor.pyr      s    


zTestDictCursor.setUpc                s&   | j j }|jd tt| j  d S )Nzdrop table dictcursor)r   r   r$   r   r   tearDown)r%   r&   )r(   r)   r*   r+       s    

zTestDictCursor.tearDownc             C   s   d S )Nr)   )r%   r   r)   r)   r*   _ensure_cursor_expired%   s    z%TestDictCursor._ensure_cursor_expiredc             C   s8  | j j | jj | jj   }}}| j}|j| j}|jd d|d< |jd |j }| j	||d | j
| |jd |j }| j	|g|d |jd x|D ]}| j	||d qW |jd |j }| j	|||g|d	 |jd t|}| j	|||g|d
 |jd |jd}| j	||g|d | j
| d S )Nz-update dictcursor set age=20 where name='bob'   r   z)SELECT * from dictcursor where name='bob'zfetchone via DictCursor failedz7fetch a 1 row result via fetchall failed via DictCursorz8fetch a 1 row result via iteration failed via DictCursorzSELECT * from dictcursorzfetchall failed via DictCursorzDictCursor should be iterabler   zfetchmany failed via DictCursor)r   copyr   r   r   r   r    r$   fetchoneassertEqualr,   fetchalllist	fetchmany)r%   r   r   r   r   r&   rr)   r)   r*   test_DictCursor(   s2    "









zTestDictCursor.test_DictCursorc                s(  G dd dt  G  fdddj}dddg} fdd	|D } fd
d	|D } fdd	|D }jj|}|jd |j }j||d j| |jd |j }j|||g|d |jd t	|}j|||g|d |jd |j
d}j||g|d j| d S )Nc               @   s   e Zd ZdS )z/TestDictCursor.test_custom_dict.<locals>.MyDictN)__name__
__module____qualname__r)   r)   r)   r*   MyDictN   s    r9   c                   s   e Zd Z ZdS )z5TestDictCursor.test_custom_dict.<locals>.MyDictCursorN)r6   r7   r8   	dict_typer)   )r9   r)   r*   MyDictCursorP   s   r;   r   r   r   c                s   g | ]}| j | fqS r)   )r   ).0k)r%   r)   r*   
<listcomp>T   s    z3TestDictCursor.test_custom_dict.<locals>.<listcomp>c                s   g | ]}| j | fqS r)   )r   )r<   r=   )r%   r)   r*   r>   U   s    c                s   g | ]}| j | fqS r)   )r   )r<   r=   )r%   r)   r*   r>   V   s    z)SELECT * FROM dictcursor WHERE name='bob'zfetchone() returns MyDictCursorzSELECT * FROM dictcursorz fetchall failed via MyDictCursorzlist failed via MyDictCursorr   )dictr    r   r   r$   r/   r0   r,   r1   r2   r3   )r%   r;   keysr   r   r   curr4   r)   )r9   r%   r*   test_custom_dictM   s0    






zTestDictCursor.test_custom_dict)r6   r7   r8   datetimer   r   r   pymysqlcursorsZ
DictCursorr    r   r+   r,   r5   rB   __classcell__r)   r)   )r(   r*   r      s   %r   c               @   s   e Zd ZejjZdd ZdS )TestSSDictCursorc             C   s   t |j  d S )N)r2   Zfetchall_unbuffered)r%   r   r)   r)   r*   r,   r   s    z'TestSSDictCursor._ensure_cursor_expiredN)r6   r7   r8   rD   rE   ZSSDictCursorr    r,   r)   r)   r)   r*   rG   o   s   rG   __main__)Zpymysql.testsr   Zpymysql.cursorsrD   rC   r!   ZPyMySQLTestCaser   rG   r6   Zunittestmainr)   r)   r)   r*   <module>   s   g