Permalink
Browse files

add test case

  • Loading branch information...
1 parent 00f28cf commit 74691f76c8e27dd92afd00355969324be4e8b4fe @hongqn hongqn committed Feb 29, 2012
Showing with 31 additions and 1 deletion.
  1. +31 −1 tests/tests.py
View
@@ -659,7 +659,37 @@ def testCharsets(self):
self.assertEquals(result, expected)
cnn.close()
-
+
+ def testTextCharsets(self):
+ aumlaut_unicode = u"\u00e4"
+ aumlaut_utf8 = "\xc3\xa4"
+ aumlaut_latin1 = "\xe4"
+
+ cnn = umysql.Connection()
+ cnn.connect (DB_HOST, 3306, DB_USER, DB_PASSWD, DB_DB)
+
+ cnn.query("drop table if exists tblutf")
+ cnn.query("create table tblutf (test_mode TEXT DEFAULT NULL, test_utf TEXT DEFAULT NULL, test_latin1 TEXT) ENGINE=MyISAM DEFAULT CHARSET=utf8")
+
+ # We insert the same character using two different encodings
+ cnn.query("set names utf8")
+ cnn.query("insert into tblutf (test_mode, test_utf, test_latin1) values ('utf8', _utf8'" + aumlaut_utf8 + "', _latin1'" + aumlaut_latin1 + "')")
+
+ cnn.query("set names latin1")
+ cnn.query("insert into tblutf (test_mode, test_utf, test_latin1) values ('latin1', _utf8'" + aumlaut_utf8 + "', _latin1'" + aumlaut_latin1 + "')")
+
+ # We expect the driver to always give us unicode strings back
+ expected = [(u"utf8", aumlaut_unicode, aumlaut_unicode), (u"latin1", aumlaut_unicode, aumlaut_unicode)]
+
+ # Fetch and test with different charsets
+ for charset in ("latin1", "utf8", "cp1250"):
+ cnn.query("set names " + charset)
+ rs = cnn.query("select test_mode, test_utf, test_latin1 from tblutf")
+ result = rs.rows
+ self.assertEquals(result, expected)
+
+ cnn.close()
+
if __name__ == '__main__':
from guppy import hpy
hp = hpy()

0 comments on commit 74691f7

Please sign in to comment.