def test_non_ascii_string(self): con = self._connect() cur = con.cursor() self.executeDDL1(cur) input_ = '中文 zhōngwén' args = {'beer': input_} cur.execute( 'insert into %sbooze values (%%(beer)s)' % self.table_prefix, args) cur.execute('select name from %sbooze' % self.table_prefix) res = cur.fetchall() returned = res[0][0] encoded = unicode_string(input_) self.assertEqual(returned, encoded) self.assertEqual(type(returned), text_type)
def test_utf8(self): con = self._connect() try: cur = con.cursor() self.executeDDL1(cur) args = {'beer': '\xc4\xa5'} cur.execute('insert into %sbooze values (%%(beer)s)' % self.table_prefix, args) cur.execute('select name from %sbooze' % self.table_prefix) res = cur.fetchall() beer = res[0][0] encoded = unicode_string(args['beer']) self.assertEqual(beer, encoded, 'incorrect data retrieved') finally: con.close()
def test_unicode(self): con = self._connect() try: cur = con.cursor() self.executeDDL1(cur) s = unicode_string('\N{latin small letter a with acute}', 'unicode-escape') args = {'beer': s} encoded = args['beer'] cur.execute('insert into %sbooze values (%%(beer)s)' % self.table_prefix, args) cur.execute('select name from %sbooze' % self.table_prefix) res = cur.fetchall() beer = res[0][0] self.assertEqual(beer, encoded, 'incorrect data retrieved') finally: con.close()