mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-07-31 02:20:02 +03:00
Always close connection objects in tests
This commit is contained in:
parent
e9ae67ff07
commit
6b63fae20a
|
@ -232,6 +232,7 @@ class DatabaseAPI20Test(unittest.TestCase):
|
|||
self.failUnless(con.InternalError is drv.InternalError)
|
||||
self.failUnless(con.ProgrammingError is drv.ProgrammingError)
|
||||
self.failUnless(con.NotSupportedError is drv.NotSupportedError)
|
||||
con.close()
|
||||
|
||||
|
||||
def test_commit(self):
|
||||
|
@ -251,6 +252,7 @@ class DatabaseAPI20Test(unittest.TestCase):
|
|||
con.rollback()
|
||||
except self.driver.NotSupportedError:
|
||||
pass
|
||||
con.close()
|
||||
|
||||
def test_cursor(self):
|
||||
con = self._connect()
|
||||
|
|
|
@ -24,19 +24,22 @@ class TwoPhaseCommitTests(unittest.TestCase):
|
|||
def test_xid(self):
|
||||
con = self.connect()
|
||||
try:
|
||||
xid = con.xid(42, "global", "bqual")
|
||||
except self.driver.NotSupportedError:
|
||||
self.fail("Driver does not support transaction IDs.")
|
||||
try:
|
||||
xid = con.xid(42, "global", "bqual")
|
||||
except self.driver.NotSupportedError:
|
||||
self.fail("Driver does not support transaction IDs.")
|
||||
|
||||
self.assertEquals(xid[0], 42)
|
||||
self.assertEquals(xid[1], "global")
|
||||
self.assertEquals(xid[2], "bqual")
|
||||
self.assertEquals(xid[0], 42)
|
||||
self.assertEquals(xid[1], "global")
|
||||
self.assertEquals(xid[2], "bqual")
|
||||
|
||||
# Try some extremes for the transaction ID:
|
||||
xid = con.xid(0, "", "")
|
||||
self.assertEquals(tuple(xid), (0, "", ""))
|
||||
xid = con.xid(0x7fffffff, "a" * 64, "b" * 64)
|
||||
self.assertEquals(tuple(xid), (0x7fffffff, "a" * 64, "b" * 64))
|
||||
# Try some extremes for the transaction ID:
|
||||
xid = con.xid(0, "", "")
|
||||
self.assertEquals(tuple(xid), (0, "", ""))
|
||||
xid = con.xid(0x7fffffff, "a" * 64, "b" * 64)
|
||||
self.assertEquals(tuple(xid), (0x7fffffff, "a" * 64, "b" * 64))
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def test_tpc_begin(self):
|
||||
con = self.connect()
|
||||
|
|
|
@ -451,14 +451,16 @@ class AsyncTests(ConnectingTestCase):
|
|||
self.assertEqual(cur.fetchone(), (42,))
|
||||
|
||||
def test_async_connection_error_message(self):
|
||||
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async_=True)
|
||||
try:
|
||||
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async_=True)
|
||||
self.wait(cnn)
|
||||
except psycopg2.Error as e:
|
||||
self.assertNotEqual(str(e), "asynchronous connection failed",
|
||||
"connection error reason lost")
|
||||
else:
|
||||
self.fail("no exception raised")
|
||||
finally:
|
||||
cnn.close()
|
||||
|
||||
@skip_before_postgres(8, 2)
|
||||
def test_copy_no_hang(self):
|
||||
|
|
|
@ -89,6 +89,8 @@ class AsyncTests(ConnectingTestCase):
|
|||
"connection error reason lost")
|
||||
else:
|
||||
self.fail("no exception raised")
|
||||
finally:
|
||||
cnn.close()
|
||||
|
||||
|
||||
class CancelTests(ConnectingTestCase):
|
||||
|
@ -118,6 +120,7 @@ class CancelTests(ConnectingTestCase):
|
|||
cur.execute("select 1")
|
||||
extras.wait_select(async_conn)
|
||||
self.assertEqual(cur.fetchall(), [(1, )])
|
||||
async_conn.close()
|
||||
|
||||
def test_async_connection_cancel(self):
|
||||
async_conn = psycopg2.connect(dsn, async=True)
|
||||
|
|
|
@ -105,6 +105,7 @@ class CancelTests(ConnectingTestCase):
|
|||
cur.execute("select 1")
|
||||
extras.wait_select(async_conn)
|
||||
self.assertEqual(cur.fetchall(), [(1, )])
|
||||
async_conn.close()
|
||||
|
||||
def test_async_connection_cancel(self):
|
||||
async_conn = psycopg2.connect(dsn, async_=True)
|
||||
|
|
|
@ -248,15 +248,17 @@ def skip_if_tpc_disabled(f):
|
|||
@wraps(f)
|
||||
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()
|
||||
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])
|
||||
finally:
|
||||
cnn.close()
|
||||
|
||||
if not mtp:
|
||||
return self.skipTest(
|
||||
|
|
Loading…
Reference in New Issue
Block a user