diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2016-07-01 17:33:12 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2016-07-01 18:02:20 +0100 |
commit | 4a450b63c418bf7e6e62f7b444fd2edd9db246da (patch) | |
tree | 2571ed219d69dc129161510f37858c1b681e71fc /tests/test_quote.py | |
parent | 2e8e61b8d41144cbb65dfce786335ff7c625b4f7 (diff) | |
download | psycopg2-4a450b63c418bf7e6e62f7b444fd2edd9db246da.tar.gz |
Don't hope to encode stuff in an arbitrary encoding
libpq's PQescapeString will use the same encoding it has seen before in
a connection (static_client_encoding).
So I think I'll leave this feature here for people who know what is
doing, but won't really document it as a feature: it can't really work
in a generic way (unless adding some disgusting hack like creating a
fake connection with the encoding we want to call PQescapeStringConn
instead of PQescapeString).
Diffstat (limited to 'tests/test_quote.py')
-rwxr-xr-x | tests/test_quote.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/test_quote.py b/tests/test_quote.py index 9d00c53..0a204c8 100755 --- a/tests/test_quote.py +++ b/tests/test_quote.py @@ -157,7 +157,7 @@ class QuotingTestCase(ConnectingTestCase): class TestQuotedString(ConnectingTestCase): - def test_encoding(self): + def test_encoding_from_conn(self): q = psycopg2.extensions.QuotedString('hi') self.assertEqual(q.encoding, 'latin1') @@ -191,8 +191,11 @@ class TestStringAdapter(ConnectingTestCase): self.assertEqual(a.encoding, 'latin1') self.assertEqual(a.getquoted(), "'hello'") - egrave = u'\xe8' - self.assertEqual(adapt(egrave).getquoted(), "'\xe8'") + # NOTE: we can't really test an encoding different from utf8, because + # when encoding without connection the libpq will use parameters from + # a previous one, so what would happens depends jn the tests run order. + # egrave = u'\xe8' + # self.assertEqual(adapt(egrave).getquoted(), "'\xe8'") def test_encoding_error(self): from psycopg2.extensions import adapt @@ -201,6 +204,9 @@ class TestStringAdapter(ConnectingTestCase): self.assertRaises(UnicodeEncodeError, a.getquoted) def test_set_encoding(self): + # Note: this works-ish mostly in case when the standard db connection + # we test with is utf8, otherwise the encoding chosen by PQescapeString + # may give bad results. from psycopg2.extensions import adapt snowman = u"\u2603" a = adapt(snowman) |