Skip to content

Commit f15dd42

Browse files
committed
Investigate travis error
1 parent 8293c53 commit f15dd42

File tree

2 files changed

+76
-78
lines changed

2 files changed

+76
-78
lines changed

pymysql/tests/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class PyMySQLTestCase(unittest2.TestCase):
2020
else:
2121
databases = [
2222
{"host":"localhost","user":"root",
23-
"passwd":"","db":"test_pymysql", "use_unicode": True, 'local_infile': True},
24-
{"host":"localhost","user":"root","passwd":"","db":"test_pymysql2"}]
23+
"passwd":"","db":"test1", "use_unicode": True, 'local_infile': True},
24+
{"host":"localhost","user":"root","passwd":"","db":"test2"}]
2525

2626
def mysql_server_is(self, conn, version_tuple):
2727
"""Return True if the given connection is on the version given or

pymysql/tests/test_SSCursor.py

Lines changed: 74 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,82 +28,80 @@ def test_SSCursor(self):
2828
('America', '', 'America/Denver'),
2929
('America', '', 'America/Detroit'),]
3030

31-
try:
32-
cursor = conn.cursor(pymysql.cursors.SSCursor)
33-
34-
# Create table
35-
cursor.execute('CREATE TABLE tz_data ('
36-
'region VARCHAR(64),'
37-
'zone VARCHAR(64),'
38-
'name VARCHAR(64))')
39-
40-
conn.begin()
41-
# Test INSERT
42-
for i in data:
43-
cursor.execute('INSERT INTO tz_data VALUES (%s, %s, %s)', i)
44-
self.assertEqual(conn.affected_rows(), 1, 'affected_rows does not match')
45-
conn.commit()
46-
47-
# Test fetchone()
48-
iter = 0
49-
cursor.execute('SELECT * FROM tz_data')
50-
while True:
51-
row = cursor.fetchone()
52-
if row is None:
53-
break
54-
iter += 1
55-
56-
# Test cursor.rowcount
57-
self.assertEqual(cursor.rowcount, affected_rows,
58-
'cursor.rowcount != %s' % (str(affected_rows)))
59-
60-
# Test cursor.rownumber
61-
self.assertEqual(cursor.rownumber, iter,
62-
'cursor.rowcount != %s' % (str(iter)))
63-
64-
# Test row came out the same as it went in
65-
self.assertEqual((row in data), True,
66-
'Row not found in source data')
67-
68-
# Test fetchall
69-
cursor.execute('SELECT * FROM tz_data')
70-
self.assertEqual(len(cursor.fetchall()), len(data),
71-
'fetchall failed. Number of rows does not match')
72-
73-
# Test fetchmany
74-
cursor.execute('SELECT * FROM tz_data')
75-
self.assertEqual(len(cursor.fetchmany(2)), 2,
76-
'fetchmany failed. Number of rows does not match')
77-
78-
# So MySQLdb won't throw "Commands out of sync"
79-
while True:
80-
res = cursor.fetchone()
81-
if res is None:
82-
break
83-
84-
# Test update, affected_rows()
85-
cursor.execute('UPDATE tz_data SET zone = %s', ['Foo'])
86-
conn.commit()
87-
self.assertEqual(cursor.rowcount, len(data),
88-
'Update failed. affected_rows != %s' % (str(len(data))))
89-
90-
# Test executemany
91-
cursor.executemany('INSERT INTO tz_data VALUES (%s, %s, %s)', data)
92-
self.assertEqual(cursor.rowcount, len(data),
93-
'executemany failed. cursor.rowcount != %s' % (str(len(data))))
94-
95-
# Test multiple datasets
96-
cursor.execute('SELECT 1; SELECT 2; SELECT 3')
97-
self.assertListEqual(list(cursor), [(1, )])
98-
self.assertTrue(cursor.nextset())
99-
self.assertListEqual(list(cursor), [(2, )])
100-
self.assertTrue(cursor.nextset())
101-
self.assertListEqual(list(cursor), [(3, )])
102-
self.assertFalse(cursor.nextset())
103-
104-
finally:
105-
cursor.execute('DROP TABLE IF EXISTS tz_data')
106-
cursor.close()
31+
cursor = conn.cursor(pymysql.cursors.SSCursor)
32+
33+
# Create table
34+
cursor.execute('CREATE TABLE tz_data ('
35+
'region VARCHAR(64),'
36+
'zone VARCHAR(64),'
37+
'name VARCHAR(64))')
38+
39+
conn.begin()
40+
# Test INSERT
41+
for i in data:
42+
cursor.execute('INSERT INTO tz_data VALUES (%s, %s, %s)', i)
43+
self.assertEqual(conn.affected_rows(), 1, 'affected_rows does not match')
44+
conn.commit()
45+
46+
# Test fetchone()
47+
iter = 0
48+
cursor.execute('SELECT * FROM tz_data')
49+
while True:
50+
row = cursor.fetchone()
51+
if row is None:
52+
break
53+
iter += 1
54+
55+
# Test cursor.rowcount
56+
self.assertEqual(cursor.rowcount, affected_rows,
57+
'cursor.rowcount != %s' % (str(affected_rows)))
58+
59+
# Test cursor.rownumber
60+
self.assertEqual(cursor.rownumber, iter,
61+
'cursor.rowcount != %s' % (str(iter)))
62+
63+
# Test row came out the same as it went in
64+
self.assertEqual((row in data), True,
65+
'Row not found in source data')
66+
67+
# Test fetchall
68+
cursor.execute('SELECT * FROM tz_data')
69+
self.assertEqual(len(cursor.fetchall()), len(data),
70+
'fetchall failed. Number of rows does not match')
71+
72+
# Test fetchmany
73+
cursor.execute('SELECT * FROM tz_data')
74+
self.assertEqual(len(cursor.fetchmany(2)), 2,
75+
'fetchmany failed. Number of rows does not match')
76+
77+
# So MySQLdb won't throw "Commands out of sync"
78+
while True:
79+
res = cursor.fetchone()
80+
if res is None:
81+
break
82+
83+
# Test update, affected_rows()
84+
cursor.execute('UPDATE tz_data SET zone = %s', ['Foo'])
85+
conn.commit()
86+
self.assertEqual(cursor.rowcount, len(data),
87+
'Update failed. affected_rows != %s' % (str(len(data))))
88+
89+
# Test executemany
90+
cursor.executemany('INSERT INTO tz_data VALUES (%s, %s, %s)', data)
91+
self.assertEqual(cursor.rowcount, len(data),
92+
'executemany failed. cursor.rowcount != %s' % (str(len(data))))
93+
94+
# Test multiple datasets
95+
cursor.execute('SELECT 1; SELECT 2; SELECT 3')
96+
self.assertListEqual(list(cursor), [(1, )])
97+
self.assertTrue(cursor.nextset())
98+
self.assertListEqual(list(cursor), [(2, )])
99+
self.assertTrue(cursor.nextset())
100+
self.assertListEqual(list(cursor), [(3, )])
101+
self.assertFalse(cursor.nextset())
102+
103+
cursor.execute('DROP TABLE IF EXISTS tz_data')
104+
cursor.close()
107105

108106
__all__ = ["TestSSCursor"]
109107

0 commit comments

Comments
 (0)