Allow tests to be ignored if dynamic binding failed

This commit is contained in:
Daniele Varrazzo 2019-03-18 19:49:16 +00:00
parent 5b4caadd23
commit 953bc66ca6
2 changed files with 22 additions and 13 deletions

View File

@ -350,14 +350,19 @@ class ConnectionTests(ConnectingTestCase):
conn = self.connect()
self.assert_(conn.pgconn_ptr is not None)
f = self.libpq.PQserverVersion
f.argtypes = [ctypes.c_void_p]
f.restype = ctypes.c_int
ver = f(conn.pgconn_ptr)
if ver == 0 and sys.platform == 'darwin':
return self.skipTest("I don't know why this func returns 0 on OSX")
try:
f = self.libpq.PQserverVersion
except AttributeError:
pass
else:
f.argtypes = [ctypes.c_void_p]
f.restype = ctypes.c_int
ver = f(conn.pgconn_ptr)
if ver == 0 and sys.platform == 'darwin':
return self.skipTest(
"I don't know why this func returns 0 on OSX")
self.assertEqual(ver, conn.server_version)
self.assertEqual(ver, conn.server_version)
conn.close()
self.assert_(conn.pgconn_ptr is None)

View File

@ -654,14 +654,18 @@ class CursorTests(ConnectingTestCase):
curs = self.conn.cursor()
self.assert_(curs.pgresult_ptr is None)
f = self.libpq.PQcmdStatus
f.argtypes = [ctypes.c_void_p]
f.restype = ctypes.c_char_p
curs.execute("select 'x'")
self.assert_(curs.pgresult_ptr is not None)
status = f(curs.pgresult_ptr)
self.assertEqual(status, b'SELECT 1')
try:
f = self.libpq.PQcmdStatus
except AttributeError:
pass
else:
f.argtypes = [ctypes.c_void_p]
f.restype = ctypes.c_char_p
status = f(curs.pgresult_ptr)
self.assertEqual(status, b'SELECT 1')
curs.close()
self.assert_(curs.pgresult_ptr is None)