diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-02-16 17:30:34 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-02-16 18:12:52 +0100 |
commit | 7c7bbb9742734d1a1c0bc808d9730113249be4eb (patch) | |
tree | 4aa13292ba8a052db7a867c7b5a69deecde88da8 /tests/testutils.py | |
parent | 1dd8c7435f6ff3643261478ab281e72b2fd425d4 (diff) | |
download | psycopg2-7c7bbb9742734d1a1c0bc808d9730113249be4eb.tar.gz |
Added connection.pgconn_ptr and cursor.pgresult_ptr
Allow interacting with libpq in Python via ctypes.
See #782.
Diffstat (limited to 'tests/testutils.py')
-rw-r--r-- | tests/testutils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/testutils.py b/tests/testutils.py index e4b6843..5f41789 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -26,10 +26,12 @@ import re import os import sys import types +import ctypes import select import platform import unittest from functools import wraps +from ctypes.util import find_library from .testconfig import dsn, repl_dsn from psycopg2.compat import text_type @@ -174,6 +176,18 @@ class ConnectingTestCase(unittest.TestCase): else: raise Exception("Unexpected result from poll: %r", state) + _libpq = None + + @property + def libpq(self): + """Return a ctypes wrapper for the libpq library""" + if ConnectingTestCase._libpq is not None: + return ConnectingTestCase._libpq + + libname = find_library('pq') + rv = ConnectingTestCase._libpq = ctypes.pydll.LoadLibrary(libname) + return rv + def decorate_all_tests(obj, *decorators): """ |