diff options
-rw-r--r-- | NEWS-2.3 | 2 | ||||
-rw-r--r-- | psycopg/lobject_int.c | 15 | ||||
-rw-r--r-- | psycopg/pqpath.c | 2 | ||||
-rwxr-xr-x | tests/__init__.py | 23 | ||||
-rwxr-xr-x | tests/bugX000.py | 22 | ||||
-rwxr-xr-x | tests/bug_gc.py | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/extras_dictcursor.py | 0 | ||||
-rwxr-xr-x | tests/test_async.py | 24 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_cancel.py | 23 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_connection.py | 48 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_copy.py | 23 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_cursor.py | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_dates.py | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_green.py | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/test_lobject.py | 60 | ||||
-rwxr-xr-x | tests/test_notify.py | 23 | ||||
-rwxr-xr-x | tests/test_psycopg2_dbapi20.py | 25 | ||||
-rwxr-xr-x | tests/test_quote.py | 23 | ||||
-rwxr-xr-x | tests/test_transaction.py | 23 | ||||
-rw-r--r-- | tests/testutils.py | 51 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/types_extras.py | 0 |
21 files changed, 445 insertions, 30 deletions
@@ -18,6 +18,8 @@ What's new in psycopg 2.3.3 - Fixed adaptation of None in composite types (ticket #26). Bug report by Karsten Hilbert. - Fixed several reference leaks in less common code paths. + - Fixed segfault when a large object is closed and its connection no more + available. What's new in psycopg 2.3.2 diff --git a/psycopg/lobject_int.c b/psycopg/lobject_int.c index b78b4a9..6ee3ecf 100644 --- a/psycopg/lobject_int.c +++ b/psycopg/lobject_int.c @@ -127,6 +127,21 @@ lobject_close_locked(lobjectObject *self, char **error) { int retvalue; + Dprintf("lobject_close_locked: conn->closed %ld", self->conn->closed); + switch (self->conn->closed) { + case 0: + /* Connection is open, go ahead */ + break; + case 1: + /* Connection is closed, return a success */ + return 0; + break; + default: + PyErr_SetString(OperationalError, "the connection is broken"); + return -1; + break; + } + if (self->conn->isolation_level == ISOLATION_LEVEL_AUTOCOMMIT || self->conn->mark != self->mark || self->fd == -1) diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 1474cbf..76e7c24 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -606,6 +606,8 @@ pq_tpc_command_locked(connectionObject *conn, const char *cmd, const char *tid, Dprintf("_pq_tpc_command: pgconn = %p, command = %s", conn->pgconn, cmd); + conn->mark += 1; + /* convert the xid into the postgres transaction_id and quote it. */ if (!(etid = psycopg_escape_string((PyObject *)conn, tid, 0, NULL, NULL))) { goto exit; } diff --git a/tests/__init__.py b/tests/__init__.py index 2bdfdd8..2eaf6ce 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,28 @@ #!/usr/bin/env python +# psycopg2 test suite +# +# Copyright (C) 2007-2011 Federico Di Gregorio <fog@debian.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + +import os import sys from testconfig import dsn from testutils import unittest diff --git a/tests/bugX000.py b/tests/bugX000.py index e3e9a99..efa593e 100755 --- a/tests/bugX000.py +++ b/tests/bugX000.py @@ -1,5 +1,27 @@ #!/usr/bin/env python +# bugX000.py - test for DateTime object allocation bug +# +# Copyright (C) 2007-2011 Federico Di Gregorio <fog@debian.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import psycopg2 import time import unittest diff --git a/tests/bug_gc.py b/tests/bug_gc.py index 3cdcc6a..fa69a90 100755 --- a/tests/bug_gc.py +++ b/tests/bug_gc.py @@ -1,5 +1,27 @@ #!/usr/bin/env python +# bug_gc.py - test for refcounting/GC bug +# +# Copyright (C) 2010-2011 Federico Di Gregorio <fog@debian.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import psycopg2 import psycopg2.extensions import time diff --git a/tests/extras_dictcursor.py b/tests/extras_dictcursor.py index 1bb44ad..1bb44ad 100644..100755 --- a/tests/extras_dictcursor.py +++ b/tests/extras_dictcursor.py diff --git a/tests/test_async.py b/tests/test_async.py index 8c25177..ea5f1f1 100755 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -1,4 +1,28 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- + +# test_async.py - unit test for asynchronous API +# +# Copyright (C) 2010-2011 Jan Urbański <wulczer@wulczer.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + from testutils import unittest, skip_if_no_pg_sleep import psycopg2 diff --git a/tests/test_cancel.py b/tests/test_cancel.py index 6f9295d..dcdbf41 100644..100755 --- a/tests/test_cancel.py +++ b/tests/test_cancel.py @@ -1,4 +1,27 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- + +# test_cancel.py - unit test for query cancellation +# +# Copyright (C) 2010-2011 Jan Urbański <wulczer@wulczer.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. import time import threading diff --git a/tests/test_connection.py b/tests/test_connection.py index d049ce1..d92391d 100644..100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1,5 +1,27 @@ #!/usr/bin/env python +# test_connection.py - unit test for connection attributes +# +# Copyright (C) 2008-2011 James Henstridge <james@jamesh.id.au> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import time import threading from testutils import unittest, decorate_all_tests, skip_if_no_pg_sleep @@ -293,30 +315,6 @@ class IsolationLevelsTestCase(unittest.TestCase): self.assertEqual(2, cur2.fetchone()[0]) -def skip_if_tpc_disabled(f): - """Skip a test if the server has tpc support disabled.""" - def skip_if_tpc_disabled_(self): - cnn = self.connect() - cur = cnn.cursor() - try: - cur.execute("SHOW max_prepared_transactions;") - except psycopg2.ProgrammingError: - return self.skipTest( - "server too old: two phase transactions not supported.") - else: - mtp = int(cur.fetchone()[0]) - cnn.close() - - if not mtp: - return self.skipTest( - "server not configured for two phase transactions. " - "set max_prepared_transactions to > 0 to run the test") - return f(self) - - skip_if_tpc_disabled_.__name__ = f.__name__ - return skip_if_tpc_disabled_ - - class ConnectionTwoPhaseTests(unittest.TestCase): def setUp(self): self._conns = [] @@ -332,7 +330,6 @@ class ConnectionTwoPhaseTests(unittest.TestCase): if not conn.closed: conn.close() - def clear_test_xacts(self): """Rollback all the prepared transaction in the testing db.""" cnn = self.connect() @@ -686,6 +683,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): cnn.tpc_prepare() self.assertRaises(psycopg2.ProgrammingError, cnn.cancel) +from testutils import skip_if_tpc_disabled decorate_all_tests(ConnectionTwoPhaseTests, skip_if_tpc_disabled) diff --git a/tests/test_copy.py b/tests/test_copy.py index 39f99ca..877c63c 100644..100755 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -1,4 +1,27 @@ #!/usr/bin/env python + +# test_copy.py - unit test for COPY support +# +# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import os import string from testutils import unittest, decorate_all_tests diff --git a/tests/test_cursor.py b/tests/test_cursor.py index cf703c2..ecaadc1 100644..100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -1,5 +1,27 @@ #!/usr/bin/env python +# test_cursor.py - unit test for cursor attributes +# +# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import unittest import psycopg2 import psycopg2.extensions diff --git a/tests/test_dates.py b/tests/test_dates.py index 44b1bc5..db2050a 100644..100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -1,5 +1,27 @@ #!/usr/bin/env python +# test_dates.py - unit test for dates handling +# +# Copyright (C) 2008-2011 James Henstridge <james@jamesh.id.au> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import math import unittest import psycopg2 diff --git a/tests/test_green.py b/tests/test_green.py index bb9acf2..d641d18 100644..100755 --- a/tests/test_green.py +++ b/tests/test_green.py @@ -1,5 +1,27 @@ #!/usr/bin/env python +# test_green.py - unit test for async wait callback +# +# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import unittest import psycopg2 import psycopg2.extensions diff --git a/tests/test_lobject.py b/tests/test_lobject.py index cc6621e..b5d5d63 100644..100755 --- a/tests/test_lobject.py +++ b/tests/test_lobject.py @@ -1,7 +1,31 @@ #!/usr/bin/env python + +# test_lobject.py - unit test for large objects support +# +# Copyright (C) 2008-2011 James Henstridge <james@jamesh.id.au> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import os import shutil import tempfile +from testutils import unittest, decorate_all_tests, skip_if_tpc_disabled import psycopg2 import psycopg2.extensions @@ -31,13 +55,17 @@ def skip_if_green(f): class LargeObjectMixin(object): # doesn't derive from TestCase to avoid repeating tests twice. def setUp(self): - self.conn = psycopg2.connect(dsn) + self.conn = self.connect() self.lo_oid = None self.tmpdir = None def tearDown(self): if self.tmpdir: shutil.rmtree(self.tmpdir, ignore_errors=True) + + if self.conn.closed: + return + if self.lo_oid is not None: self.conn.rollback() try: @@ -48,6 +76,9 @@ class LargeObjectMixin(object): lo.unlink() self.conn.close() + def connect(self): + return psycopg2.connect(dsn) + class LargeObjectTests(LargeObjectMixin, unittest.TestCase): def test_create(self): @@ -84,6 +115,11 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase): self.assertEqual(lo2.oid, lo.oid) self.assertEqual(lo2.closed, True) + def test_close_connection_gone(self): + lo = self.conn.lobject() + self.conn.close() + lo.close() + def test_create_with_oid(self): # Create and delete a large object to get an unused Oid. lo = self.conn.lobject() @@ -293,6 +329,28 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase): finally: f.close() + @skip_if_tpc_disabled + def test_read_after_tpc_commit(self): + self.conn.tpc_begin('test_lobject') + lo = self.conn.lobject() + self.lo_oid = lo.oid + self.conn.tpc_commit() + + self.assertRaises(psycopg2.ProgrammingError, lo.read, 5) + + @skip_if_tpc_disabled + def test_read_after_tpc_prepare(self): + self.conn.tpc_begin('test_lobject') + lo = self.conn.lobject() + self.lo_oid = lo.oid + self.conn.tpc_prepare() + + try: + self.assertRaises(psycopg2.ProgrammingError, lo.read, 5) + finally: + self.conn.tpc_commit() + + decorate_all_tests(LargeObjectTests, skip_if_no_lo) decorate_all_tests(LargeObjectTests, skip_if_green) diff --git a/tests/test_notify.py b/tests/test_notify.py index 683d21d..ea6b7e0 100755 --- a/tests/test_notify.py +++ b/tests/test_notify.py @@ -1,4 +1,27 @@ #!/usr/bin/env python + +# test_notify.py - unit test for async notifications +# +# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + from testutils import unittest import psycopg2 diff --git a/tests/test_psycopg2_dbapi20.py b/tests/test_psycopg2_dbapi20.py index dfe8f53..744d322 100755 --- a/tests/test_psycopg2_dbapi20.py +++ b/tests/test_psycopg2_dbapi20.py @@ -1,7 +1,30 @@ #!/usr/bin/env python + +# test_psycopg2_dbapi20.py - DB API conformance test for psycopg2 +# +# Copyright (C) 2006-2011 Federico Di Gregorio <fog@debian.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import dbapi20 import dbapi20_tpc -from test_connection import skip_if_tpc_disabled +from testutils import skip_if_tpc_disabled from testutils import unittest, decorate_all_tests import psycopg2 diff --git a/tests/test_quote.py b/tests/test_quote.py index 19bfe4b..23bc61f 100755 --- a/tests/test_quote.py +++ b/tests/test_quote.py @@ -1,4 +1,27 @@ #!/usr/bin/env python + +# test_quote.py - unit test for strings quoting +# +# Copyright (C) 2007-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import sys from testutils import unittest from testconfig import dsn diff --git a/tests/test_transaction.py b/tests/test_transaction.py index 53ddf85..cab9c45 100755 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -1,4 +1,27 @@ #!/usr/bin/env python + +# test_transaction - unit test on transaction behaviour +# +# Copyright (C) 2007-2011 Federico Di Gregorio <fog@debian.org> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + import threading from testutils import unittest, skip_if_no_pg_sleep diff --git a/tests/testutils.py b/tests/testutils.py index cd034e5..6de3a4b 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -1,6 +1,25 @@ -# Utility module for psycopg2 testing. -# -# Copyright (C) 2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# testutils.py - utility module for psycopg2 testing. +# +# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com> +# +# psycopg2 is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# In addition, as a special exception, the copyright holders give +# permission to link this program with the OpenSSL library (or with +# modified versions of OpenSSL that use the same license as OpenSSL), +# and distribute linked combinations including the two. +# +# You must obey the GNU Lesser General Public License in all respects for +# all of the code used other than OpenSSL. +# +# psycopg2 is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + # Use unittest2 if available. Otherwise mock a skip facility with warnings. @@ -83,6 +102,32 @@ def skip_if_no_pg_sleep(name): return skip_if_no_pg_sleep_ + +def skip_if_tpc_disabled(f): + """Skip a test if the server has tpc support disabled.""" + def skip_if_tpc_disabled_(self): + from psycopg2 import ProgrammingError + cnn = self.connect() + cur = cnn.cursor() + try: + cur.execute("SHOW max_prepared_transactions;") + except ProgrammingError: + return self.skipTest( + "server too old: two phase transactions not supported.") + else: + mtp = int(cur.fetchone()[0]) + cnn.close() + + if not mtp: + return self.skipTest( + "server not configured for two phase transactions. " + "set max_prepared_transactions to > 0 to run the test") + return f(self) + + skip_if_tpc_disabled_.__name__ = f.__name__ + return skip_if_tpc_disabled_ + + def skip_on_python2(f): """Skip a test on Python 3 and following.""" def skip_on_python2_(self): diff --git a/tests/types_extras.py b/tests/types_extras.py index 501a754..501a754 100644..100755 --- a/tests/types_extras.py +++ b/tests/types_extras.py |