diff --git a/tests/test_cursor.py b/tests/test_cursor.py index ec76918b..d5223860 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -29,9 +29,10 @@ import psycopg2.extensions import unittest from .testutils import (ConnectingTestCase, skip_before_postgres, skip_if_no_getrefcount, slow, skip_if_no_superuser, - skip_if_windows, unicode) + skip_if_windows) import psycopg2.extras +from psycopg2.compat import text_type class CursorTests(ConnectingTestCase): @@ -75,7 +76,7 @@ class CursorTests(ConnectingTestCase): snowman = u"\u2603" def b(s): - if isinstance(s, unicode): + if isinstance(s, text_type): return s.encode('utf8') else: return s diff --git a/tests/test_sql.py b/tests/test_sql.py index 1c20997c..81b22a4e 100755 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -26,10 +26,11 @@ import datetime as dt import unittest from .testutils import (ConnectingTestCase, skip_before_postgres, skip_before_python, skip_copy_if_green, - unicode, StringIO) + StringIO) import psycopg2 from psycopg2 import sql +from psycopg2.compat import text_type class SqlFormatTests(ConnectingTestCase): @@ -64,7 +65,7 @@ class SqlFormatTests(ConnectingTestCase): s = sql.SQL(u"select {0} from {1}").format( sql.Identifier(u'field'), sql.Identifier('table')) s1 = s.as_string(self.conn) - self.assert_(isinstance(s1, unicode)) + self.assert_(isinstance(s1, text_type)) self.assertEqual(s1, u'select "field" from "table"') def test_compose_literal(self): diff --git a/tests/testutils.py b/tests/testutils.py index d70e091e..3bb72e20 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -30,6 +30,7 @@ import platform import unittest from functools import wraps from .testconfig import dsn, repl_dsn +from psycopg2.compat import text_type # Python 2/3 compatibility @@ -39,14 +40,12 @@ if sys.version_info[0] == 2: long = long reload = reload unichr = unichr - unicode = unicode else: # Python 3 from io import StringIO from importlib import reload long = int unichr = chr - unicode = str # Silence warnings caused by the stubbornness of the Python unittest @@ -89,7 +88,7 @@ class ConnectingTestCase(unittest.TestCase): def assertQuotedEqual(self, first, second, msg=None): """Compare two quoted strings disregarding eventual E'' quotes""" def f(s): - if isinstance(s, unicode): + if isinstance(s, text_type): return re.sub(r"\bE'", "'", s) elif isinstance(first, bytes): return re.sub(br"\bE'", b"'", s)