mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-28 20:03:43 +03:00
Test moved to the right module, cleanup, but same problem
This commit is contained in:
parent
bada1f1f8e
commit
2e8e61b8d4
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,5 +34,3 @@ if dbuser is not None:
|
|||
dsn += ' user=%s' % dbuser
|
||||
if dbpass is not None:
|
||||
dsn += ' password=%s' % dbpass
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user