Skip to content

Commit 0503973

Browse files
committed
fix some tests
1 parent 481e97a commit 0503973

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

tornado_mysql/tests/base.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import gc
2-
import os
32
import json
4-
import tornado_mysql
3+
import os
4+
import re
55
import unittest
6+
import warnings
67

78
from .._compat import CPYTHON
89

9-
import warnings
10-
10+
import tornado_mysql
1111
from tornado import gen
1212
from tornado.testing import AsyncTestCase, gen_test
1313

@@ -55,11 +55,12 @@ def setUp(self):
5555
self.addCleanup(self._teardown_connections)
5656

5757
def _teardown_connections(self):
58-
@self.io_loop.run_sync
59-
@gen.coroutine
60-
def inner():
61-
for connection in self.connections:
62-
yield connection.close()
58+
for connection in self.connections:
59+
try:
60+
connection.close()
61+
except:
62+
# IOLoop closed already
63+
pass
6364

6465
def safe_create_table(self, connection, tablename, ddl, cleanup=False):
6566
"""create a table.

tornado_mysql/tests/test_basic.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def test_datatypes(self):
3030
try:
3131
# insert values
3232
v = (True, -3, 123456789012, 5.7, "hello'\" world", u"Espa\xc3\xb1ol", "binary\x00data".encode(conn.charset), datetime.date(1988,2,2), datetime.datetime(2014, 5, 15, 7, 45, 57), datetime.timedelta(5,6), datetime.time(16,32), time.localtime())
33-
c.execute("insert into test_datatypes (b,i,l,f,s,u,bb,d,dt,td,t,st) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", v)
34-
c.execute("select b,i,l,f,s,u,bb,d,dt,td,t,st from test_datatypes")
33+
yield c.execute("insert into test_datatypes (b,i,l,f,s,u,bb,d,dt,td,t,st) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", v)
34+
yield c.execute("select b,i,l,f,s,u,bb,d,dt,td,t,st from test_datatypes")
3535
r = c.fetchone()
3636
self.assertEqual(util.int2byte(1), r[0])
3737
self.assertEqual(v[1:10], r[1:10])
@@ -337,12 +337,13 @@ def test_bulk_insert_single_record(self):
337337
yield cursor.execute('commit')
338338
yield self._verify_records(data)
339339

340+
@gen_test
340341
def test_issue_288(self):
341342
"""executemany should work with "insert ... on update" """
342343
conn = self.connections[0]
343344
cursor = conn.cursor()
344345
data = [(0, "bob", 21, 123), (1, "jim", 56, 45), (2, "fred", 100, 180)]
345-
cursor.executemany("""insert
346+
yield cursor.executemany("""insert
346347
into bulkinsert (id, name,
347348
age, height)
348349
values (%s,
@@ -361,17 +362,20 @@ def test_issue_288(self):
361362
'fred' , 100,
362363
180 ) on duplicate key update
363364
age = values(age)"""))
364-
cursor.execute('commit')
365-
self._verify_records(data)
365+
yield cursor.execute('commit')
366+
yield self._verify_records(data)
366367

368+
@gen_test
367369
def test_warnings(self):
368370
con = self.connections[0]
369371
cur = con.cursor()
370372
with warnings.catch_warnings(record=True) as ws:
371373
warnings.simplefilter("always")
372-
cur.execute("drop table if exists no_exists_table")
374+
yield cur.execute("drop table if exists no_exists_table")
375+
for w in ws:
376+
print(w)
373377
self.assertEqual(len(ws), 1)
374-
self.assertEqual(ws[0].category, pymysql.Warning)
378+
self.assertEqual(ws[0].category, tornado_mysql.Warning)
375379
self.assertTrue(u"no_exists_table" in str(ws[0].message))
376380

377381

0 commit comments

Comments
 (0)