mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-19 18:30:33 +03:00
In tests, use compat.py where there is overlap
This commit is contained in:
parent
8ad2098b74
commit
be3b1ba1eb
|
@ -29,9 +29,10 @@ import psycopg2.extensions
|
||||||
import unittest
|
import unittest
|
||||||
from .testutils import (ConnectingTestCase, skip_before_postgres,
|
from .testutils import (ConnectingTestCase, skip_before_postgres,
|
||||||
skip_if_no_getrefcount, slow, skip_if_no_superuser,
|
skip_if_no_getrefcount, slow, skip_if_no_superuser,
|
||||||
skip_if_windows, unicode)
|
skip_if_windows)
|
||||||
|
|
||||||
import psycopg2.extras
|
import psycopg2.extras
|
||||||
|
from psycopg2.compat import text_type
|
||||||
|
|
||||||
|
|
||||||
class CursorTests(ConnectingTestCase):
|
class CursorTests(ConnectingTestCase):
|
||||||
|
@ -75,7 +76,7 @@ class CursorTests(ConnectingTestCase):
|
||||||
snowman = u"\u2603"
|
snowman = u"\u2603"
|
||||||
|
|
||||||
def b(s):
|
def b(s):
|
||||||
if isinstance(s, unicode):
|
if isinstance(s, text_type):
|
||||||
return s.encode('utf8')
|
return s.encode('utf8')
|
||||||
else:
|
else:
|
||||||
return s
|
return s
|
||||||
|
|
|
@ -26,10 +26,11 @@ import datetime as dt
|
||||||
import unittest
|
import unittest
|
||||||
from .testutils import (ConnectingTestCase,
|
from .testutils import (ConnectingTestCase,
|
||||||
skip_before_postgres, skip_before_python, skip_copy_if_green,
|
skip_before_postgres, skip_before_python, skip_copy_if_green,
|
||||||
unicode, StringIO)
|
StringIO)
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import sql
|
from psycopg2 import sql
|
||||||
|
from psycopg2.compat import text_type
|
||||||
|
|
||||||
|
|
||||||
class SqlFormatTests(ConnectingTestCase):
|
class SqlFormatTests(ConnectingTestCase):
|
||||||
|
@ -64,7 +65,7 @@ class SqlFormatTests(ConnectingTestCase):
|
||||||
s = sql.SQL(u"select {0} from {1}").format(
|
s = sql.SQL(u"select {0} from {1}").format(
|
||||||
sql.Identifier(u'field'), sql.Identifier('table'))
|
sql.Identifier(u'field'), sql.Identifier('table'))
|
||||||
s1 = s.as_string(self.conn)
|
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"')
|
self.assertEqual(s1, u'select "field" from "table"')
|
||||||
|
|
||||||
def test_compose_literal(self):
|
def test_compose_literal(self):
|
||||||
|
|
|
@ -30,6 +30,7 @@ import platform
|
||||||
import unittest
|
import unittest
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from .testconfig import dsn, repl_dsn
|
from .testconfig import dsn, repl_dsn
|
||||||
|
from psycopg2.compat import text_type
|
||||||
|
|
||||||
# Python 2/3 compatibility
|
# Python 2/3 compatibility
|
||||||
|
|
||||||
|
@ -39,14 +40,12 @@ if sys.version_info[0] == 2:
|
||||||
long = long
|
long = long
|
||||||
reload = reload
|
reload = reload
|
||||||
unichr = unichr
|
unichr = unichr
|
||||||
unicode = unicode
|
|
||||||
else:
|
else:
|
||||||
# Python 3
|
# Python 3
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
long = int
|
long = int
|
||||||
unichr = chr
|
unichr = chr
|
||||||
unicode = str
|
|
||||||
|
|
||||||
|
|
||||||
# Silence warnings caused by the stubbornness of the Python unittest
|
# 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):
|
def assertQuotedEqual(self, first, second, msg=None):
|
||||||
"""Compare two quoted strings disregarding eventual E'' quotes"""
|
"""Compare two quoted strings disregarding eventual E'' quotes"""
|
||||||
def f(s):
|
def f(s):
|
||||||
if isinstance(s, unicode):
|
if isinstance(s, text_type):
|
||||||
return re.sub(r"\bE'", "'", s)
|
return re.sub(r"\bE'", "'", s)
|
||||||
elif isinstance(first, bytes):
|
elif isinstance(first, bytes):
|
||||||
return re.sub(br"\bE'", b"'", s)
|
return re.sub(br"\bE'", b"'", s)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user