2011-01-07 04:44:19 +03:00
|
|
|
# testutils.py - utility module for psycopg2 testing.
|
2011-02-12 03:40:23 +03:00
|
|
|
|
2011-01-07 04:44:19 +03:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2010-11-19 06:55:37 +03:00
|
|
|
|
2017-02-06 21:43:39 +03:00
|
|
|
import re
|
2011-02-11 01:59:31 +03:00
|
|
|
import os
|
|
|
|
import sys
|
2018-10-30 03:23:56 +03:00
|
|
|
import types
|
2015-10-15 19:01:43 +03:00
|
|
|
import select
|
2017-02-06 21:43:39 +03:00
|
|
|
import platform
|
2017-03-01 23:44:04 +03:00
|
|
|
import unittest
|
2013-03-20 21:17:10 +04:00
|
|
|
from functools import wraps
|
2017-12-04 05:47:19 +03:00
|
|
|
from .testconfig import dsn, repl_dsn
|
2017-12-12 07:08:18 +03:00
|
|
|
from psycopg2.compat import text_type
|
2011-02-11 01:59:31 +03:00
|
|
|
|
2017-12-04 05:47:19 +03:00
|
|
|
# Python 2/3 compatibility
|
|
|
|
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
# Python 2
|
|
|
|
from StringIO import StringIO
|
|
|
|
long = long
|
|
|
|
reload = reload
|
|
|
|
unichr = unichr
|
|
|
|
else:
|
|
|
|
# Python 3
|
2018-10-23 02:39:14 +03:00
|
|
|
from io import StringIO # noqa
|
|
|
|
from importlib import reload # noqa
|
2017-12-04 05:47:19 +03:00
|
|
|
long = int
|
|
|
|
unichr = chr
|
|
|
|
|
2010-11-19 06:55:37 +03:00
|
|
|
|
2015-03-16 11:50:20 +03:00
|
|
|
# Silence warnings caused by the stubbornness of the Python unittest
|
|
|
|
# maintainers
|
2018-09-23 04:54:55 +03:00
|
|
|
# https://bugs.python.org/issue9424
|
2016-10-11 02:10:53 +03:00
|
|
|
if (not hasattr(unittest.TestCase, 'assert_')
|
|
|
|
or unittest.TestCase.assert_ is not unittest.TestCase.assertTrue):
|
2011-02-11 01:59:31 +03:00
|
|
|
# mavaff...
|
|
|
|
unittest.TestCase.assert_ = unittest.TestCase.assertTrue
|
|
|
|
unittest.TestCase.failUnless = unittest.TestCase.assertTrue
|
|
|
|
unittest.TestCase.assertEquals = unittest.TestCase.assertEqual
|
|
|
|
unittest.TestCase.failUnlessEqual = unittest.TestCase.assertEqual
|
|
|
|
|
2010-11-19 06:55:37 +03:00
|
|
|
|
2017-02-06 21:56:50 +03:00
|
|
|
def assertDsnEqual(self, dsn1, dsn2, msg=None):
|
|
|
|
"""Check that two conninfo string have the same content"""
|
|
|
|
self.assertEqual(set(dsn1.split()), set(dsn2.split()), msg)
|
|
|
|
|
2018-10-23 02:39:14 +03:00
|
|
|
|
2017-02-06 21:56:50 +03:00
|
|
|
unittest.TestCase.assertDsnEqual = assertDsnEqual
|
|
|
|
|
|
|
|
|
2013-04-07 03:23:30 +04:00
|
|
|
class ConnectingTestCase(unittest.TestCase):
|
|
|
|
"""A test case providing connections for tests.
|
|
|
|
|
|
|
|
A connection for the test is always available as `self.conn`. Others can be
|
|
|
|
created with `self.connect()`. All are closed on tearDown.
|
|
|
|
|
|
|
|
Subclasses needing to customize setUp and tearDown should remember to call
|
|
|
|
the base class implementations.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
self._conns = []
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
# close the connections used in the test
|
|
|
|
for conn in self._conns:
|
|
|
|
if not conn.closed:
|
|
|
|
conn.close()
|
|
|
|
|
2017-02-06 21:43:39 +03:00
|
|
|
def assertQuotedEqual(self, first, second, msg=None):
|
|
|
|
"""Compare two quoted strings disregarding eventual E'' quotes"""
|
|
|
|
def f(s):
|
2017-12-12 07:08:18 +03:00
|
|
|
if isinstance(s, text_type):
|
2017-02-06 21:43:39 +03:00
|
|
|
return re.sub(r"\bE'", "'", s)
|
|
|
|
elif isinstance(first, bytes):
|
|
|
|
return re.sub(br"\bE'", b"'", s)
|
|
|
|
else:
|
|
|
|
return s
|
|
|
|
|
|
|
|
return self.assertEqual(f(first), f(second), msg)
|
|
|
|
|
2013-04-07 03:23:30 +04:00
|
|
|
def connect(self, **kwargs):
|
|
|
|
try:
|
|
|
|
self._conns
|
2017-11-21 07:00:35 +03:00
|
|
|
except AttributeError as e:
|
2013-04-07 03:23:30 +04:00
|
|
|
raise AttributeError(
|
2016-06-29 01:14:57 +03:00
|
|
|
"%s (did you forget to call ConnectingTestCase.setUp()?)"
|
2013-04-07 03:23:30 +04:00
|
|
|
% e)
|
|
|
|
|
2015-09-30 14:15:35 +03:00
|
|
|
if 'dsn' in kwargs:
|
|
|
|
conninfo = kwargs.pop('dsn')
|
|
|
|
else:
|
|
|
|
conninfo = dsn
|
2013-04-07 03:23:30 +04:00
|
|
|
import psycopg2
|
2015-09-30 14:15:35 +03:00
|
|
|
conn = psycopg2.connect(conninfo, **kwargs)
|
2013-04-07 03:23:30 +04:00
|
|
|
self._conns.append(conn)
|
|
|
|
return conn
|
|
|
|
|
2015-09-30 14:15:35 +03:00
|
|
|
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.
|
|
|
|
"""
|
2016-12-24 02:18:22 +03:00
|
|
|
if repl_dsn is None:
|
|
|
|
return self.skipTest("replication tests disabled by default")
|
|
|
|
|
2015-09-30 14:15:35 +03:00
|
|
|
if 'dsn' not in kwargs:
|
|
|
|
kwargs['dsn'] = repl_dsn
|
|
|
|
import psycopg2
|
|
|
|
try:
|
|
|
|
conn = self.connect(**kwargs)
|
2017-02-03 07:28:27 +03:00
|
|
|
if conn.async_ == 1:
|
2016-12-25 19:46:11 +03:00
|
|
|
self.wait(conn)
|
2017-11-21 07:00:35 +03:00
|
|
|
except psycopg2.OperationalError as e:
|
2016-12-25 19:46:11 +03:00
|
|
|
# If pgcode is not set it is a genuine connection error
|
|
|
|
# Otherwise we tried to run some bad operation in the connection
|
|
|
|
# (e.g. bug #482) and we'd rather know that.
|
|
|
|
if e.pgcode is None:
|
|
|
|
return self.skipTest("replication db not configured: %s" % e)
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
2015-09-30 14:15:35 +03:00
|
|
|
return conn
|
|
|
|
|
2013-04-07 03:23:30 +04:00
|
|
|
def _get_conn(self):
|
|
|
|
if not hasattr(self, '_the_conn'):
|
|
|
|
self._the_conn = self.connect()
|
|
|
|
|
|
|
|
return self._the_conn
|
|
|
|
|
|
|
|
def _set_conn(self, conn):
|
|
|
|
self._the_conn = conn
|
|
|
|
|
|
|
|
conn = property(_get_conn, _set_conn)
|
|
|
|
|
2015-10-15 19:01:43 +03:00
|
|
|
# for use with async connections only
|
|
|
|
def wait(self, cur_or_conn):
|
|
|
|
import psycopg2.extensions
|
|
|
|
pollable = cur_or_conn
|
|
|
|
if not hasattr(pollable, 'poll'):
|
|
|
|
pollable = cur_or_conn.connection
|
|
|
|
while True:
|
|
|
|
state = pollable.poll()
|
|
|
|
if state == psycopg2.extensions.POLL_OK:
|
|
|
|
break
|
|
|
|
elif state == psycopg2.extensions.POLL_READ:
|
|
|
|
select.select([pollable], [], [], 10)
|
|
|
|
elif state == psycopg2.extensions.POLL_WRITE:
|
|
|
|
select.select([], [pollable], [], 10)
|
|
|
|
else:
|
|
|
|
raise Exception("Unexpected result from poll: %r", state)
|
|
|
|
|
2013-04-07 03:23:30 +04:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
def decorate_all_tests(obj, *decorators):
|
2013-04-07 03:23:30 +04:00
|
|
|
"""
|
2018-10-30 03:23:56 +03:00
|
|
|
Apply all the *decorators* to all the tests defined in the TestCase *obj*.
|
|
|
|
|
|
|
|
The decorator can also be applied to a decorator: if *obj* is a function,
|
|
|
|
return a new decorator which can be applied either to a method or to a
|
|
|
|
class, in which case it will decorate all the tests.
|
2013-04-07 03:23:30 +04:00
|
|
|
"""
|
2018-10-30 03:23:56 +03:00
|
|
|
if isinstance(obj, types.FunctionType):
|
|
|
|
def decorator(func_or_cls):
|
|
|
|
if isinstance(func_or_cls, types.FunctionType):
|
|
|
|
return obj(func_or_cls)
|
|
|
|
else:
|
|
|
|
decorate_all_tests(func_or_cls, obj)
|
|
|
|
return func_or_cls
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
for n in dir(obj):
|
2010-11-19 06:55:37 +03:00
|
|
|
if n.startswith('test'):
|
2013-04-07 03:23:30 +04:00
|
|
|
for d in decorators:
|
2018-10-30 03:23:56 +03:00
|
|
|
setattr(obj, n, d(getattr(obj, n)))
|
2010-11-28 18:03:34 +03:00
|
|
|
|
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2011-01-18 04:46:10 +03:00
|
|
|
def skip_if_no_uuid(f):
|
|
|
|
"""Decorator to skip a test if uuid is not supported by Py/PG."""
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2011-01-18 04:46:10 +03:00
|
|
|
def skip_if_no_uuid_(self):
|
|
|
|
try:
|
|
|
|
cur = self.conn.cursor()
|
|
|
|
cur.execute("select typname from pg_type where typname = 'uuid'")
|
|
|
|
has = cur.fetchone()
|
|
|
|
finally:
|
|
|
|
self.conn.rollback()
|
|
|
|
|
|
|
|
if has:
|
|
|
|
return f(self)
|
|
|
|
else:
|
|
|
|
return self.skipTest("uuid type not available on the server")
|
|
|
|
|
|
|
|
return skip_if_no_uuid_
|
|
|
|
|
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2011-01-10 02:44:58 +03:00
|
|
|
def skip_if_tpc_disabled(f):
|
|
|
|
"""Skip a test if the server has tpc support disabled."""
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2011-01-10 02:44:58 +03:00
|
|
|
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)
|
|
|
|
|
|
|
|
return skip_if_tpc_disabled_
|
|
|
|
|
|
|
|
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_before_postgres(*ver):
|
|
|
|
"""Skip a test on PostgreSQL before a certain version."""
|
2018-10-30 03:23:56 +03:00
|
|
|
reason = None
|
|
|
|
if isinstance(ver[-1], str):
|
|
|
|
ver, reason = ver[:-1], ver[-1]
|
|
|
|
|
2011-02-15 20:11:07 +03:00
|
|
|
ver = ver + (0,) * (3 - len(ver))
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_before_postgres_(f):
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_before_postgres__(self):
|
2018-10-13 05:28:42 +03:00
|
|
|
if self.conn.info.server_version < int("%d%02d%02d" % ver):
|
2018-10-30 03:23:56 +03:00
|
|
|
return self.skipTest(
|
|
|
|
reason or "skipped because PostgreSQL %s"
|
2018-10-13 05:28:42 +03:00
|
|
|
% self.conn.info.server_version)
|
2011-02-15 20:11:07 +03:00
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
|
|
|
|
return skip_before_postgres__
|
|
|
|
return skip_before_postgres_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_after_postgres(*ver):
|
|
|
|
"""Skip a test on PostgreSQL after (including) a certain version."""
|
|
|
|
ver = ver + (0,) * (3 - len(ver))
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_after_postgres_(f):
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_after_postgres__(self):
|
2018-10-13 05:28:42 +03:00
|
|
|
if self.conn.info.server_version >= int("%d%02d%02d" % ver):
|
2011-02-15 20:11:07 +03:00
|
|
|
return self.skipTest("skipped because PostgreSQL %s"
|
2018-10-13 05:28:42 +03:00
|
|
|
% self.conn.info.server_version)
|
2011-02-15 20:11:07 +03:00
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
|
|
|
|
return skip_after_postgres__
|
|
|
|
return skip_after_postgres_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2015-06-01 19:05:11 +03:00
|
|
|
def libpq_version():
|
|
|
|
import psycopg2
|
|
|
|
v = psycopg2.__libpq_version__
|
|
|
|
if v >= 90100:
|
2017-03-02 20:52:29 +03:00
|
|
|
v = min(v, psycopg2.extensions.libpq_version())
|
2015-06-01 19:05:11 +03:00
|
|
|
return v
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2015-06-01 19:05:11 +03:00
|
|
|
def skip_before_libpq(*ver):
|
|
|
|
"""Skip a test if libpq we're linked to is older than a certain version."""
|
|
|
|
ver = ver + (0,) * (3 - len(ver))
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2015-06-01 19:05:11 +03:00
|
|
|
def skip_before_libpq_(f):
|
|
|
|
@wraps(f)
|
|
|
|
def skip_before_libpq__(self):
|
|
|
|
v = libpq_version()
|
|
|
|
if v < int("%d%02d%02d" % ver):
|
|
|
|
return self.skipTest("skipped because libpq %d" % v)
|
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
|
|
|
|
return skip_before_libpq__
|
|
|
|
return skip_before_libpq_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2015-06-01 19:05:11 +03:00
|
|
|
def skip_after_libpq(*ver):
|
|
|
|
"""Skip a test if libpq we're linked to is newer than a certain version."""
|
|
|
|
ver = ver + (0,) * (3 - len(ver))
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2015-06-01 19:05:11 +03:00
|
|
|
def skip_after_libpq_(f):
|
|
|
|
@wraps(f)
|
|
|
|
def skip_after_libpq__(self):
|
|
|
|
v = libpq_version()
|
|
|
|
if v >= int("%d%02d%02d" % ver):
|
|
|
|
return self.skipTest("skipped because libpq %s" % v)
|
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
|
|
|
|
return skip_after_libpq__
|
|
|
|
return skip_after_libpq_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_before_python(*ver):
|
|
|
|
"""Skip a test on Python before a certain version."""
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_before_python_(f):
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_before_python__(self):
|
|
|
|
if sys.version_info[:len(ver)] < ver:
|
|
|
|
return self.skipTest("skipped because Python %s"
|
|
|
|
% ".".join(map(str, sys.version_info[:len(ver)])))
|
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
|
|
|
|
return skip_before_python__
|
|
|
|
return skip_before_python_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_from_python(*ver):
|
|
|
|
"""Skip a test on Python after (including) a certain version."""
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_from_python_(f):
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2011-02-15 20:11:07 +03:00
|
|
|
def skip_from_python__(self):
|
|
|
|
if sys.version_info[:len(ver)] >= ver:
|
|
|
|
return self.skipTest("skipped because Python %s"
|
|
|
|
% ".".join(map(str, sys.version_info[:len(ver)])))
|
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
|
|
|
|
return skip_from_python__
|
|
|
|
return skip_from_python_
|
2011-02-11 01:59:31 +03:00
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2013-03-16 15:56:38 +04:00
|
|
|
def skip_if_no_superuser(f):
|
|
|
|
"""Skip a test if the database user running the test is not a superuser"""
|
2013-03-20 21:17:10 +04:00
|
|
|
@wraps(f)
|
2013-03-16 15:56:38 +04:00
|
|
|
def skip_if_no_superuser_(self):
|
|
|
|
from psycopg2 import ProgrammingError
|
|
|
|
try:
|
|
|
|
return f(self)
|
2017-11-21 07:00:35 +03:00
|
|
|
except ProgrammingError as e:
|
2013-03-16 15:56:38 +04:00
|
|
|
import psycopg2.errorcodes
|
|
|
|
if e.pgcode == psycopg2.errorcodes.INSUFFICIENT_PRIVILEGE:
|
|
|
|
self.skipTest("skipped because not superuser")
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
return skip_if_no_superuser_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2013-03-20 21:17:10 +04:00
|
|
|
def skip_if_green(reason):
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2013-03-20 21:17:10 +04:00
|
|
|
def skip_if_green_(f):
|
|
|
|
@wraps(f)
|
|
|
|
def skip_if_green__(self):
|
2017-12-04 05:47:19 +03:00
|
|
|
from .testconfig import green
|
2013-03-20 21:17:10 +04:00
|
|
|
if green:
|
|
|
|
return self.skipTest(reason)
|
|
|
|
else:
|
|
|
|
return f(self)
|
2013-03-18 14:06:07 +04:00
|
|
|
|
2013-03-20 21:17:10 +04:00
|
|
|
return skip_if_green__
|
|
|
|
return skip_if_green_
|
2013-03-18 14:06:07 +04:00
|
|
|
|
2018-10-23 02:39:14 +03:00
|
|
|
|
2013-03-20 21:17:10 +04:00
|
|
|
skip_copy_if_green = skip_if_green("copy in async mode currently not supported")
|
2011-02-11 01:59:31 +03:00
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2013-05-06 13:39:24 +04:00
|
|
|
def skip_if_no_getrefcount(f):
|
|
|
|
@wraps(f)
|
|
|
|
def skip_if_no_getrefcount_(self):
|
|
|
|
if not hasattr(sys, 'getrefcount'):
|
|
|
|
return self.skipTest('skipped, no sys.getrefcount()')
|
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
return skip_if_no_getrefcount_
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2018-10-30 03:23:56 +03:00
|
|
|
@decorate_all_tests
|
2014-05-13 02:12:50 +04:00
|
|
|
def skip_if_windows(f):
|
|
|
|
"""Skip a test if run on windows"""
|
|
|
|
@wraps(f)
|
|
|
|
def skip_if_windows_(self):
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
return self.skipTest("Not supported on Windows")
|
|
|
|
else:
|
|
|
|
return f(self)
|
|
|
|
return skip_if_windows_
|
|
|
|
|
|
|
|
|
2014-02-19 00:55:00 +04:00
|
|
|
class py3_raises_typeerror(object):
|
|
|
|
def __enter__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __exit__(self, type, exc, tb):
|
|
|
|
if sys.version_info[0] >= 3:
|
|
|
|
assert type is TypeError
|
|
|
|
return True
|
2017-02-02 04:53:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
def slow(f):
|
2017-02-02 05:09:59 +03:00
|
|
|
"""Decorator to mark slow tests we may want to skip
|
|
|
|
|
|
|
|
Note: in order to find slow tests you can run:
|
|
|
|
|
|
|
|
make check 2>&1 | ts -i "%.s" | sort -n
|
|
|
|
"""
|
2017-02-02 04:53:50 +03:00
|
|
|
@wraps(f)
|
|
|
|
def slow_(self):
|
|
|
|
if os.environ.get('PSYCOPG2_TEST_FAST'):
|
|
|
|
return self.skipTest("slow test")
|
|
|
|
return f(self)
|
|
|
|
return slow_
|