summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-07-01 16:57:25 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-07-01 18:01:16 +0100
commit2e8e61b8d41144cbb65dfce786335ff7c625b4f7 (patch)
treec6e68a33331f2352a0daee3389cc0facdf90a0af
parentbada1f1f8e390c7d0ef8eea88cdb16e6f78c1eec (diff)
downloadpsycopg2-2e8e61b8d41144cbb65dfce786335ff7c625b4f7.tar.gz
Test moved to the right module, cleanup, but same problem
-rw-r--r--psycopg/adapter_qstring.c3
-rwxr-xr-xtests/test_quote.py47
-rwxr-xr-xtests/test_types_basic.py37
-rw-r--r--tests/testconfig.py2
4 files changed, 43 insertions, 46 deletions
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 1e256cf..110093e 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -87,8 +87,7 @@ qstring_quote(qstringObject *self)
/* if the wrapped object is not a string, this is an error */
else {
- PyErr_SetString(PyExc_TypeError,
- "can't quote non-string object (or missing encoding)");
+ PyErr_SetString(PyExc_TypeError, "can't quote non-string object");
goto exit;
}
diff --git a/tests/test_quote.py b/tests/test_quote.py
index 6e94562..9d00c53 100755
--- a/tests/test_quote.py
+++ b/tests/test_quote.py
@@ -29,6 +29,7 @@ import psycopg2
import psycopg2.extensions
from psycopg2.extensions import b
+
class QuotingTestCase(ConnectingTestCase):
r"""Checks the correct quoting of strings and binary objects.
@@ -51,7 +52,7 @@ class QuotingTestCase(ConnectingTestCase):
data = """some data with \t chars
to escape into, 'quotes' and \\ a backslash too.
"""
- data += "".join(map(chr, range(1,127)))
+ data += "".join(map(chr, range(1, 127)))
curs = self.conn.cursor()
curs.execute("SELECT %s;", (data,))
@@ -90,13 +91,13 @@ class QuotingTestCase(ConnectingTestCase):
if server_encoding != "UTF8":
return self.skipTest(
"Unicode test skipped since server encoding is %s"
- % server_encoding)
+ % server_encoding)
data = u"""some data with \t chars
to escape into, 'quotes', \u20ac euro sign and \\ a backslash too.
"""
- data += u"".join(map(unichr, [ u for u in range(1,65536)
- if not 0xD800 <= u <= 0xDFFF ])) # surrogate area
+ data += u"".join(map(unichr, [u for u in range(1, 65536)
+ if not 0xD800 <= u <= 0xDFFF])) # surrogate area
self.conn.set_client_encoding('UNICODE')
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE, self.conn)
@@ -183,9 +184,45 @@ class TestQuotedIdentifier(ConnectingTestCase):
self.assertEqual(quote_ident(snowman, self.conn), quoted)
+class TestStringAdapter(ConnectingTestCase):
+ def test_encoding_default(self):
+ from psycopg2.extensions import adapt
+ a = adapt("hello")
+ self.assertEqual(a.encoding, 'latin1')
+ self.assertEqual(a.getquoted(), "'hello'")
+
+ egrave = u'\xe8'
+ self.assertEqual(adapt(egrave).getquoted(), "'\xe8'")
+
+ def test_encoding_error(self):
+ from psycopg2.extensions import adapt
+ snowman = u"\u2603"
+ a = adapt(snowman)
+ self.assertRaises(UnicodeEncodeError, a.getquoted)
+
+ def test_set_encoding(self):
+ from psycopg2.extensions import adapt
+ snowman = u"\u2603"
+ a = adapt(snowman)
+ a.encoding = 'utf8'
+ self.assertEqual(a.encoding, 'utf8')
+ self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
+
+ def test_connection_wins_anyway(self):
+ from psycopg2.extensions import adapt
+ snowman = u"\u2603"
+ a = adapt(snowman)
+ a.encoding = 'latin9'
+
+ self.conn.set_client_encoding('utf8')
+ a.prepare(self.conn)
+
+ self.assertEqual(a.encoding, 'utf_8')
+ self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
+
+
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == "__main__":
unittest.main()
-
diff --git a/tests/test_types_basic.py b/tests/test_types_basic.py
index baa80c0..248712b 100755
--- a/tests/test_types_basic.py
+++ b/tests/test_types_basic.py
@@ -344,43 +344,6 @@ class TypesBasicTests(ConnectingTestCase):
self.assertEqual(a, [2,4,'nada'])
-class TestStringAdapter(ConnectingTestCase):
- def test_encoding_default(self):
- from psycopg2.extensions import adapt
- a = adapt("hello")
- self.assertEqual(a.encoding, 'latin1')
- self.assertEqual(a.getquoted(), "'hello'")
-
- egrave = u'\xe8'
- self.assertEqual(adapt(egrave).getquoted(), "'\xe8'")
-
- def test_encoding_error(self):
- from psycopg2.extensions import adapt
- snowman = u"\u2603"
- a = adapt(snowman)
- self.assertRaises(UnicodeEncodeError, a.getquoted)
-
- def test_set_encoding(self):
- from psycopg2.extensions import adapt
- snowman = u"\u2603"
- a = adapt(snowman)
- a.encoding = 'utf8'
- self.assertEqual(a.encoding, 'utf8')
- self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
-
- def test_connection_wins_anyway(self):
- from psycopg2.extensions import adapt
- snowman = u"\u2603"
- a = adapt(snowman)
- a.encoding = 'latin9'
-
- self.conn.set_client_encoding('utf8')
- a.prepare(self.conn)
-
- self.assertEqual(a.encoding, 'utf_8')
- self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
-
-
class AdaptSubclassTest(unittest.TestCase):
def test_adapt_subtype(self):
from psycopg2.extensions import adapt
diff --git a/tests/testconfig.py b/tests/testconfig.py
index 0f995fb..72c533e 100644
--- a/tests/testconfig.py
+++ b/tests/testconfig.py
@@ -34,5 +34,3 @@ if dbuser is not None:
dsn += ' user=%s' % dbuser
if dbpass is not None:
dsn += ' password=%s' % dbpass
-
-