Skip to content

Commit 7e4a872

Browse files
committed
add more connection tests
1 parent 7547b03 commit 7e4a872

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pymysql/tests/test_connection.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def test_init_command(self):
7373
c.execute('select "foobar";')
7474
self.assertEqual(('foobar',), c.fetchone())
7575
conn.close()
76+
with self.assertRaises(pymysql.err.Error):
77+
conn.ping(reconnect=False)
7678

7779
def test_read_default_group(self):
7880
conn = pymysql.connect(
@@ -81,6 +83,30 @@ def test_read_default_group(self):
8183
)
8284
self.assertTrue(conn.open)
8385

86+
def test_context(self):
87+
with self.assertRaises(ValueError):
88+
c = pymysql.connect(**self.databases[0])
89+
with c as cur:
90+
cur.execute('create table test ( a int )')
91+
c.begin()
92+
cur.execute('insert into test values ((1))')
93+
raise ValueError('pseudo abort')
94+
c.commit()
95+
c = pymysql.connect(**self.databases[0])
96+
with c as cur:
97+
cur.execute('select count(*) from test')
98+
self.assertEqual(0, cur.fetchone()[0])
99+
cur.execute('insert into test values ((1))')
100+
with c as cur:
101+
cur.execute('select count(*) from test')
102+
self.assertEqual(1,cur.fetchone()[0])
103+
cur.execute('drop table test')
104+
105+
def test_set_charset(self):
106+
c = pymysql.connect(**self.databases[0])
107+
c.set_charset('utf8')
108+
# TODO validate setting here
109+
84110

85111
# A custom type and function to escape it
86112
class Foo(object):

0 commit comments

Comments
 (0)