@@ -73,6 +73,8 @@ def test_init_command(self):
73
73
c .execute ('select "foobar";' )
74
74
self .assertEqual (('foobar' ,), c .fetchone ())
75
75
conn .close ()
76
+ with self .assertRaises (pymysql .err .Error ):
77
+ conn .ping (reconnect = False )
76
78
77
79
def test_read_default_group (self ):
78
80
conn = pymysql .connect (
@@ -81,6 +83,30 @@ def test_read_default_group(self):
81
83
)
82
84
self .assertTrue (conn .open )
83
85
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
+
84
110
85
111
# A custom type and function to escape it
86
112
class Foo (object ):
0 commit comments