Fixed exception handling in disconnection test

OperationalError is DatabaseError's subclass.
This commit is contained in:
Daniele Varrazzo 2013-03-16 21:42:41 +00:00
parent c5de7b5ac6
commit af18c29f0b

View File

@ -75,12 +75,14 @@ class ConnectionTests(unittest.TestCase):
cur = conn.cursor() cur = conn.cursor()
try: try:
cur.execute("select pg_terminate_backend(pg_backend_pid())") cur.execute("select pg_terminate_backend(pg_backend_pid())")
except psycopg2.DatabaseError, e:
# curiously in green mode we get a DatabaseError without pgcode
pass
except psycopg2.OperationalError, e: except psycopg2.OperationalError, e:
if e.pgcode != psycopg2.errorcodes.ADMIN_SHUTDOWN: if e.pgcode != psycopg2.errorcodes.ADMIN_SHUTDOWN:
raise raise
except psycopg2.DatabaseError, e:
# curiously when disconnected in green mode we get a DatabaseError
# without pgcode.
if e.pgcode is not None:
raise
self.assertEqual(conn.closed, 2) self.assertEqual(conn.closed, 2)
conn.close() conn.close()