1
+ import warnings
1
2
from tornado_mysql import ProgrammingError
2
3
from tornado import gen
3
4
from tornado .testing import gen_test
@@ -26,19 +27,18 @@ def test_SSCursor(self):
26
27
affected_rows = 18446744073709551615
27
28
28
29
conn = self .connections [0 ]
30
+ cursor = conn .cursor (tornado_mysql .cursors .SSCursor )
29
31
30
- try :
31
- cursor = conn .cursor (tornado_mysql .cursors .SSCursor )
32
-
33
- # Create table
34
- with warnings .catch_warnings ():
35
- warnings .simplefilter ("ignore" )
36
- yield cursor .execute ('DROP TABLE IF EXISTS tz_data;' )
37
- yield cursor .execute (('CREATE TABLE tz_data ('
38
- 'region VARCHAR(64),'
39
- 'zone VARCHAR(64),'
40
- 'name VARCHAR(64))' ))
32
+ # Create table
33
+ with warnings .catch_warnings ():
34
+ warnings .simplefilter ("ignore" )
35
+ yield cursor .execute ('DROP TABLE IF EXISTS tz_data;' )
36
+ yield cursor .execute ('CREATE TABLE tz_data ('
37
+ 'region VARCHAR(64),'
38
+ 'zone VARCHAR(64),'
39
+ 'name VARCHAR(64))' )
41
40
41
+ try :
42
42
# Test INSERT
43
43
for i in self .data :
44
44
yield cursor .execute ('INSERT INTO tz_data VALUES (%s, %s, %s)' , i )
@@ -97,13 +97,16 @@ def test_SSCursor(self):
97
97
98
98
# Test multiple datasets
99
99
yield cursor .execute ('SELECT 1; SELECT 2; SELECT 3' )
100
- self .assertListEqual (list (cursor ), [(1 , )])
100
+ res = yield cursor .fetchall ()
101
+ self .assertListEqual (res , [(1 , )])
101
102
res = yield cursor .nextset ()
102
103
self .assertTrue (res )
103
- self .assertListEqual (list (cursor ), [(2 , )])
104
+ res = yield cursor .fetchall ()
105
+ self .assertListEqual (res , [(2 , )])
104
106
res = yield cursor .nextset ()
105
107
self .assertTrue (res )
106
- self .assertListEqual (list (cursor ), [(3 , )])
108
+ res = yield cursor .fetchall ()
109
+ self .assertListEqual (res , [(3 , )])
107
110
res = yield cursor .nextset ()
108
111
self .assertFalse (res )
109
112
finally :
@@ -142,7 +145,7 @@ def test_sscursor_executemany(self):
142
145
# Test executemany
143
146
yield cursor .executemany (
144
147
'INSERT INTO tz_data VALUES (%s, %s, %s)' , self .data )
145
- yield cursor ._close ()
148
+ yield cursor .close ()
146
149
msg = 'executemany failed. cursor.rowcount != %s'
147
150
self .assertEqual (cursor .rowcount , len (self .data ),
148
151
msg % (str (len (self .data ))))
@@ -157,6 +160,7 @@ def test_sscursor_scroll_relative(self):
157
160
yield cursor .scroll (1 )
158
161
ret = yield cursor .fetchone ()
159
162
self .assertEqual (('America' , '' , 'America/Los_Angeles' ), ret )
163
+ yield cursor .close ()
160
164
yield self ._cleanup ()
161
165
162
166
@gen_test
@@ -168,6 +172,7 @@ def test_sscursor_scroll_absolute(self):
168
172
yield cursor .scroll (2 , mode = 'absolute' )
169
173
ret = yield cursor .fetchone ()
170
174
self .assertEqual (('America' , '' , 'America/Lima' ), ret )
175
+ yield cursor .close ()
171
176
yield self ._cleanup ()
172
177
173
178
@gen_test
@@ -187,6 +192,7 @@ def test_sscursor_scroll_errors(self):
187
192
yield cursor .scroll (1 , mode = 'absolute' )
188
193
with self .assertRaises (ProgrammingError ):
189
194
yield cursor .scroll (3 , mode = 'not_valid_mode' )
195
+ yield cursor .close ()
190
196
yield self ._cleanup ()
191
197
192
198
0 commit comments