fix testsuite for PG 9.0+

Jan UrbaƄski <[email protected]> Tue, 23 Mar 2010 01:38:17 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Hi,

PostgreSQL 9.0 addes a new GUC called bytea_output which controls the 
output format of bytea values. The default is not what PG <9.0 was 
using, so that breaks the tests that use bytea. It seems strange to me 
that PQescapeByteaConn returns data in the old format, while the default 
for the server is to use the new format. I'll ask on the PG mailing 
list, but for now the attached patch fixes the test suite for me.

PS: is the workflow for psycopg2 attaching patches to mails? Or is there 
a issue tracker? Couldn't find one on the website (or something a 
developer introduction...). I'm new to psycopg2 development and would 
like to try to follow your process.

Cheers,
Jan

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
0001-Set-bytea_output-to-escape-for-PostgreSQL-9.0.patch (text/x-diff, 1.6 KB)
From 8592337cac4aa48e4cd160c12d388426633f02aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Urba=C5=84ski?= <[email protected]>
Date: Tue, 23 Mar 2010 01:01:14 +0100
Subject: [PATCH 1/2] Set bytea_output to 'escape' for PostgreSQL 9.0+

---
 tests/test_quote.py  |    6 ++++++
 tests/types_basic.py |    6 ++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tests/test_quote.py b/tests/test_quote.py
index 2076d8c..f26a5a8 100755
--- a/tests/test_quote.py
+++ b/tests/test_quote.py
@@ -56,6 +56,12 @@ class QuotingTestCase(unittest.TestCase):
         data += list2bytes(range(256))
 
         curs = self.conn.cursor()
+        try:
+            # PostgreSQL 9.0+ defaults to a hex encoded bytea output
+            curs.execute("SET LOCAL bytea_output TO 'escape';")
+        except psycopg2.ProgrammingError:
+            # that GUC does not exist in PG <9.0
+            pass
         curs.execute("SELECT %s::bytea;", (psycopg2.Binary(data),))
         res = asbytes(curs.fetchone()[0])
 
diff --git a/tests/types_basic.py b/tests/types_basic.py
index e73cf95..010c314 100755
--- a/tests/types_basic.py
+++ b/tests/types_basic.py
@@ -36,6 +36,12 @@ class TypesBasicTests(unittest.TestCase):
 
     def setUp(self):
         self.conn = psycopg2.connect(tests.dsn)
+        try:
+            # PostgreSQL 9.0+ defaults to a hex encoded bytea output
+            self.conn.cursor().execute("SET SESSION bytea_output TO 'escape';")
+        except psycopg2.ProgrammingError:
+            # that GUC does not exist in PG <9.0
+            pass
 
     def execute(self, *args):
         curs = self.conn.cursor()
-- 
1.7.0