Skip to content

Commit 2e8e61b

Browse files
committed
Test moved to the right module, cleanup, but same problem
1 parent bada1f1 commit 2e8e61b

File tree

4 files changed

+43
-46
lines changed

4 files changed

+43
-46
lines changed

psycopg/adapter_qstring.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ qstring_quote(qstringObject *self)
8787

8888
/* if the wrapped object is not a string, this is an error */
8989
else {
90-
PyErr_SetString(PyExc_TypeError,
91-
"can't quote non-string object (or missing encoding)");
90+
PyErr_SetString(PyExc_TypeError, "can't quote non-string object");
9291
goto exit;
9392
}
9493

tests/test_quote.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import psycopg2.extensions
3030
from psycopg2.extensions import b
3131

32+
3233
class QuotingTestCase(ConnectingTestCase):
3334
r"""Checks the correct quoting of strings and binary objects.
3435
@@ -51,7 +52,7 @@ def test_string(self):
5152
data = """some data with \t chars
5253
to escape into, 'quotes' and \\ a backslash too.
5354
"""
54-
data += "".join(map(chr, range(1,127)))
55+
data += "".join(map(chr, range(1, 127)))
5556

5657
curs = self.conn.cursor()
5758
curs.execute("SELECT %s;", (data,))
@@ -90,13 +91,13 @@ def test_unicode(self):
9091
if server_encoding != "UTF8":
9192
return self.skipTest(
9293
"Unicode test skipped since server encoding is %s"
93-
% server_encoding)
94+
% server_encoding)
9495

9596
data = u"""some data with \t chars
9697
to escape into, 'quotes', \u20ac euro sign and \\ a backslash too.
9798
"""
98-
data += u"".join(map(unichr, [ u for u in range(1,65536)
99-
if not 0xD800 <= u <= 0xDFFF ])) # surrogate area
99+
data += u"".join(map(unichr, [u for u in range(1, 65536)
100+
if not 0xD800 <= u <= 0xDFFF])) # surrogate area
100101
self.conn.set_client_encoding('UNICODE')
101102

102103
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE, self.conn)
@@ -183,9 +184,45 @@ def test_unicode_ident(self):
183184
self.assertEqual(quote_ident(snowman, self.conn), quoted)
184185

185186

187+
class TestStringAdapter(ConnectingTestCase):
188+
def test_encoding_default(self):
189+
from psycopg2.extensions import adapt
190+
a = adapt("hello")
191+
self.assertEqual(a.encoding, 'latin1')
192+
self.assertEqual(a.getquoted(), "'hello'")
193+
194+
egrave = u'\xe8'
195+
self.assertEqual(adapt(egrave).getquoted(), "'\xe8'")
196+
197+
def test_encoding_error(self):
198+
from psycopg2.extensions import adapt
199+
snowman = u"\u2603"
200+
a = adapt(snowman)
201+
self.assertRaises(UnicodeEncodeError, a.getquoted)
202+
203+
def test_set_encoding(self):
204+
from psycopg2.extensions import adapt
205+
snowman = u"\u2603"
206+
a = adapt(snowman)
207+
a.encoding = 'utf8'
208+
self.assertEqual(a.encoding, 'utf8')
209+
self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
210+
211+
def test_connection_wins_anyway(self):
212+
from psycopg2.extensions import adapt
213+
snowman = u"\u2603"
214+
a = adapt(snowman)
215+
a.encoding = 'latin9'
216+
217+
self.conn.set_client_encoding('utf8')
218+
a.prepare(self.conn)
219+
220+
self.assertEqual(a.encoding, 'utf_8')
221+
self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
222+
223+
186224
def test_suite():
187225
return unittest.TestLoader().loadTestsFromName(__name__)
188226

189227
if __name__ == "__main__":
190228
unittest.main()
191-

tests/test_types_basic.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -344,43 +344,6 @@ def caster(s, cur):
344344
self.assertEqual(a, [2,4,'nada'])
345345

346346

347-
class TestStringAdapter(ConnectingTestCase):
348-
def test_encoding_default(self):
349-
from psycopg2.extensions import adapt
350-
a = adapt("hello")
351-
self.assertEqual(a.encoding, 'latin1')
352-
self.assertEqual(a.getquoted(), "'hello'")
353-
354-
egrave = u'\xe8'
355-
self.assertEqual(adapt(egrave).getquoted(), "'\xe8'")
356-
357-
def test_encoding_error(self):
358-
from psycopg2.extensions import adapt
359-
snowman = u"\u2603"
360-
a = adapt(snowman)
361-
self.assertRaises(UnicodeEncodeError, a.getquoted)
362-
363-
def test_set_encoding(self):
364-
from psycopg2.extensions import adapt
365-
snowman = u"\u2603"
366-
a = adapt(snowman)
367-
a.encoding = 'utf8'
368-
self.assertEqual(a.encoding, 'utf8')
369-
self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
370-
371-
def test_connection_wins_anyway(self):
372-
from psycopg2.extensions import adapt
373-
snowman = u"\u2603"
374-
a = adapt(snowman)
375-
a.encoding = 'latin9'
376-
377-
self.conn.set_client_encoding('utf8')
378-
a.prepare(self.conn)
379-
380-
self.assertEqual(a.encoding, 'utf_8')
381-
self.assertEqual(a.getquoted(), "'\xe2\x98\x83'")
382-
383-
384347
class AdaptSubclassTest(unittest.TestCase):
385348
def test_adapt_subtype(self):
386349
from psycopg2.extensions import adapt

tests/testconfig.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@
3434
dsn += ' user=%s' % dbuser
3535
if dbpass is not None:
3636
dsn += ' password=%s' % dbpass
37-
38-

0 commit comments

Comments
 (0)