Skip to content

Commit

Permalink
add more connection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grooverdan committed Aug 29, 2015
1 parent 7547b03 commit 7e4a872
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def test_init_command(self):
c.execute('select "foobar";')
self.assertEqual(('foobar',), c.fetchone())
conn.close()
with self.assertRaises(pymysql.err.Error):
conn.ping(reconnect=False)

def test_read_default_group(self):
conn = pymysql.connect(
Expand All @@ -81,6 +83,30 @@ def test_read_default_group(self):
)
self.assertTrue(conn.open)

def test_context(self):
with self.assertRaises(ValueError):
c = pymysql.connect(**self.databases[0])
with c as cur:
cur.execute('create table test ( a int )')
c.begin()
cur.execute('insert into test values ((1))')
raise ValueError('pseudo abort')
c.commit()
c = pymysql.connect(**self.databases[0])
with c as cur:
cur.execute('select count(*) from test')
self.assertEqual(0, cur.fetchone()[0])
cur.execute('insert into test values ((1))')
with c as cur:
cur.execute('select count(*) from test')
self.assertEqual(1,cur.fetchone()[0])
cur.execute('drop table test')

def test_set_charset(self):
c = pymysql.connect(**self.databases[0])
c.set_charset('utf8')
# TODO validate setting here


# A custom type and function to escape it
class Foo(object):
Expand Down

0 comments on commit 7e4a872

Please sign in to comment.