In tests, use compat.py where there is overlap

This commit is contained in:
Jon Dufresne 2017-12-11 20:08:18 -08:00
parent 8ad2098b74
commit be3b1ba1eb
3 changed files with 8 additions and 7 deletions

View File

@ -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

View File

@ -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):

View File

@ -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)