<s> from pymysql . tests import base <EOL> import pymysql . cursors <EOL> import datetime <EOL> import warnings <EOL> class TestDictCursor ( base . PyMySQLTestCase ) : <EOL> bob = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT> ) } <EOL> jim = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> ) } <EOL> fred = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:100> , '<STR_LIT>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:12> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) } <EOL> cursor_type = pymysql . cursors . DictCursor <EOL> def setUp ( self ) : <EOL> super ( TestDictCursor , self ) . setUp ( ) <EOL> self . conn = conn = self . connections [ <NUM_LIT:0> ] <EOL> c = conn . cursor ( self . cursor_type ) <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> c . execute ( """<STR_LIT>""" ) <EOL> data = [ ( "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:100> , "<STR_LIT>" ) ] <EOL> c . executemany ( "<STR_LIT>" , data ) <EOL> def tearDown ( self ) : <EOL> c = self . conn . cursor ( ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> super ( TestDictCursor , self ) . tearDown ( ) <EOL> def _ensure_cursor_expired ( self , cursor ) : <EOL> pass <EOL> def test_DictCursor ( self ) : <EOL> bob , jim , fred = self . bob . copy ( ) , self . jim . copy ( ) , self . fred . copy ( ) <EOL> conn = self . conn <EOL> c = conn . cursor ( self . cursor_type ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> bob [ '<STR_LIT>' ] = <NUM_LIT:20> <EOL> c . execute ( "<STR_LIT>" ) <EOL> r = c . fetchone ( ) <EOL> self . assertEqual ( bob , r , "<STR_LIT>" ) <EOL> self . _ensure_cursor_expired ( c ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> r = c . fetchall ( ) <EOL> self . assertEqual ( [ bob ] , r , "<STR_LIT>" ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> for r in c : <EOL> self . assertEqual ( bob , r , "<STR_LIT>" ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> r = c . fetchall ( ) <EOL> self . assertEqual ( [ bob , jim , fred ] , r , "<STR_LIT>" ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> r = list ( c ) <EOL> self . assertEqual ( [ bob , jim , fred ] , r , "<STR_LIT>" ) <EOL> c . execute ( "<STR_LIT>" ) <EOL> r = c . fetchmany ( <NUM_LIT:2> ) <EOL> self . assertEqual ( [ bob , jim ] , r , "<STR_LIT>" ) <EOL> self . _ensure_cursor_expired ( c ) <EOL> def test_custom_dict ( self ) : <EOL> class MyDict ( dict ) : pass <EOL> class MyDictCursor ( self . cursor_type ) : <EOL> dict_type = MyDict <EOL> keys = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> bob = MyDict ( [ ( k , self . bob [ k ] ) for k in keys ] ) <EOL> jim = MyDict ( [ ( k , self . jim [ k ] ) for k in keys ] ) <EOL> fred = MyDict ( [ ( k , self . fred [ k ] ) for k in keys ] ) <EOL> cur = self . conn . cursor ( MyDictCursor ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> r = cur . fetchone ( ) <EOL> self . assertEqual ( bob , r , "<STR_LIT>" ) <EOL> self . _ensure_cursor_expired ( cur ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> r = cur . fetchall ( ) <EOL> self . assertEqual ( [ bob , jim , fred ] , r , <EOL> "<STR_LIT>" ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> r = list ( cur ) <EOL> self . assertEqual ( [ bob , jim , fred ] , r , <EOL> "<STR_LIT>" ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> r = cur . fetchmany ( <NUM_LIT:2> ) <EOL> self . assertEqual ( [ bob , jim ] , r , <EOL> "<STR_LIT>" ) <EOL> self . _ensure_cursor_expired ( cur ) <EOL> class TestSSDictCursor ( TestDictCursor ) : <EOL> cursor_type = pymysql . cursors . SSDictCursor <EOL> def _ensure_cursor_expired ( self , cursor ) : <EOL> list ( cursor . fetchall_unbuffered ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import unittest <EOL> unittest . main ( ) </s>
