From 05627ac0f9e519c52014185b48a782f8669e6843 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 11 Oct 2016 00:22:23 +0100 Subject: [PATCH] Fix unicode mogrify test on python 2 --- tests/test_cursor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 4fab2c4c..4aae6b2f 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -70,21 +70,27 @@ class CursorTests(ConnectingTestCase): conn.set_client_encoding('UTF8') snowman = u"\u2603" + def b(s): + if isinstance(s, unicode): + return s.encode('utf8') + else: + return s + # unicode query with non-ascii data cur.execute(u"SELECT '%s';" % snowman) - self.assertEqual(snowman.encode('utf8'), cur.fetchone()[0].encode('utf8')) + self.assertEqual(snowman.encode('utf8'), b(cur.fetchone()[0])) self.assertEqual(("SELECT '%s';" % snowman).encode('utf8'), cur.mogrify(u"SELECT '%s';" % snowman).replace(b"E'", b"'")) # unicode args cur.execute("SELECT %s;", (snowman,)) - self.assertEqual(snowman.encode("utf-8"), cur.fetchone()[0].encode('utf8')) + self.assertEqual(snowman.encode("utf-8"), b(cur.fetchone()[0])) self.assertEqual(("SELECT '%s';" % snowman).encode('utf8'), cur.mogrify("SELECT %s;", (snowman,)).replace(b"E'", b"'")) # unicode query and args cur.execute(u"SELECT %s;", (snowman,)) - self.assertEqual(snowman.encode("utf-8"), cur.fetchone()[0].encode('utf8')) + self.assertEqual(snowman.encode("utf-8"), b(cur.fetchone()[0])) self.assertEqual(("SELECT '%s';" % snowman).encode('utf8'), cur.mogrify(u"SELECT %s;", (snowman,)).replace(b"E'", b"'"))