diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2015-09-30 12:15:35 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2015-09-30 12:28:07 +0100 |
| commit | 6803341f21e71bf1c77470b1a5b262503f5b7a39 (patch) | |
| tree | 72a5d4b4894024e2da324a19756264dc368cf3de /tests/testutils.py | |
| parent | 0e3f5214c5f292212e10b1d87b68069c9ab3ce22 (diff) | |
| download | psycopg2-6803341f21e71bf1c77470b1a5b262503f5b7a39.tar.gz | |
Report NotSupportedError for PGRES_COPY_BOTH and PGRES_SINGLE_TUPLE
Fixes #352.
Diffstat (limited to 'tests/testutils.py')
| -rw-r--r-- | tests/testutils.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/tests/testutils.py b/tests/testutils.py index 987bd7b..76671d9 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -28,7 +28,7 @@ import os import platform import sys from functools import wraps -from testconfig import dsn +from testconfig import dsn, repl_dsn try: import unittest2 @@ -103,11 +103,35 @@ class ConnectingTestCase(unittest.TestCase): "%s (did you remember calling ConnectingTestCase.setUp()?)" % e) + if 'dsn' in kwargs: + conninfo = kwargs.pop('dsn') + else: + conninfo = dsn import psycopg2 - conn = psycopg2.connect(dsn, **kwargs) + conn = psycopg2.connect(conninfo, **kwargs) self._conns.append(conn) return conn + def repl_connect(self, **kwargs): + """Return a connection set up for replication + + The connection is on "PSYCOPG2_TEST_REPL_DSN" unless overridden by + a *dsn* kwarg. + + Should raise a skip test if not available, but guard for None on + old Python versions. + """ + if 'dsn' not in kwargs: + kwargs['dsn'] = repl_dsn + import psycopg2 + try: + conn = self.connect(**kwargs) + except psycopg2.OperationalError, e: + return self.skipTest("replication db not configured: %s" % e) + + conn.autocommit = True + return conn + def _get_conn(self): if not hasattr(self, '_the_conn'): self._the_conn = self.connect() @@ -388,4 +412,3 @@ class py3_raises_typeerror(object): if sys.version_info[0] >= 3: assert type is TypeError return True - |
