summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rwxr-xr-xtests/test_quote.py12
2 files changed, 10 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 9056b0f..4571f67 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ What's new in psycopg 2.6.2
- Report the server response status on errors (such as :ticket:`#281`).
- Raise `!NotSupportedError` on unhandled server response status
(:ticket:`#352`).
+- Allow overriding string adapter encoding with no connection (:ticket:`#331`).
- The `~psycopg2.extras.wait_select` callback allows interrupting a
long-running query in an interactive shell using :kbd:`Ctrl-C`
(:ticket:`#333`).
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)