3
(h
                 @   sZ   d dl Z d dlZ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 G dd dej	Z
dS )    N   )CPYTHONc            
   @   s   e Zd ZejjejjedZejj	erJe
eZejeZW dQ R X n ddddddddddd	d
gZdd Zdd Zdd ZdddZdd Zdd ZdS )PyMySQLTestCasezdatabases.jsonN	localhostroot Ztest_pymysqlT)hostuserpasswddbZuse_unicodeZlocal_infileZtest_pymysql2)r   r	   r
   r   c             C   s4   |j  }tdd tjd|jdddD }||kS )zReturn True if the given connection is on the version given or
        greater.

        e.g.::

            if self.mysql_server_is(conn, (5, 6, 4)):
                # do something for MySQL 5.6.4 and above
        c             s   s"   | ]}|d k	rt |ndV  qd S )Nr   )int).0dig r   7/tmp/pip-install-q3hcpn_q/PyMySQL/pymysql/tests/base.py	<genexpr>%   s   z2PyMySQLTestCase.mysql_server_is.<locals>.<genexpr>z(\d+)\.(\d+)\.(\d+)   r      )Zget_server_infotuplerematchgroup)selfconnZversion_tupleZserver_versionZserver_version_tupler   r   r   mysql_server_is   s
    	zPyMySQLTestCase.mysql_server_isc             C   s:   g | _ x"| jD ]}| j jtjf | qW | j| j d S )N)connections	databasesappendpymysqlconnect
addCleanup_teardown_connections)r   paramsr   r   r   setUp+   s    zPyMySQLTestCase.setUpc             C   s   x| j D ]}|j  qW d S )N)r   close)r   
connectionr   r   r   r!   1   s    z%PyMySQLTestCase._teardown_connectionsc             C   s`   |j  }tj   tjd |jd|f  W dQ R X |j| |j  |r\| j| j|| dS )zcreate a table.

        Ensures any existing version of that table is first dropped.

        Also adds a cleanup rule to drop the table after the test
        completes.
        ignorezdrop table if exists `%s`N)cursorwarningscatch_warningssimplefilterexecuter$   r    
drop_table)r   r%   	tablenameZddlcleanupr'   r   r   r   safe_create_table5   s    


z!PyMySQLTestCase.safe_create_tablec          
   C   sB   |j  }tj   tjd |jd|f  W d Q R X |j  d S )Nr&   zdrop table if exists `%s`)r'   r(   r)   r*   r+   r$   )r   r%   r-   r'   r   r   r   r,   G   s
    

zPyMySQLTestCase.drop_tablec             C   s   t j  tst j  dS )zfEnsure cycles are collected via gc.

        Runs additional times on non-CPython platforms.

        N)gcZcollectr   )r   r   r   r   safe_gc_collectN   s    zPyMySQLTestCase.safe_gc_collect)T)__name__
__module____qualname__ospathjoindirname__file__fnameexistsopenfjsonloadr   r   r#   r!   r/   r,   r1   r   r   r   r   r      s   

r   )r0   r>   r5   r   r(   Z	unittest2r   _compatr   ZTestCaser   r   r   r   r   <module>   s   