mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 18:33:44 +03:00
Added tests to verify the new Diagnostics properties
diag can be used on exceptions raised without cursor and is independent from the cursor. Docs updated to reflect the changes.
This commit is contained in:
parent
7177f815a6
commit
114c62fac8
|
@ -165,9 +165,9 @@ functionalities defined by the |DBAPI|_.
|
|||
table_name
|
||||
|
||||
A string with the error field if available; `!None` if not available.
|
||||
The attribute value is available only if the error sent by the server
|
||||
includes the specified field and should remain available until the
|
||||
cursor that generated the exception executes another query.
|
||||
The attribute value is available only if the error sent by the server:
|
||||
not all the fields are available for all the errors and for all the
|
||||
server versions.
|
||||
|
||||
|
||||
.. autofunction:: set_wait_callback(f)
|
||||
|
|
|
@ -221,6 +221,38 @@ class ExceptionsTestCase(unittest.TestCase):
|
|||
|
||||
self.assertEqual(diag.sqlstate, '42P01')
|
||||
|
||||
def test_diagnostics_independent(self):
|
||||
cur = self.conn.cursor()
|
||||
try:
|
||||
cur.execute("l'acqua e' poca e 'a papera nun galleggia")
|
||||
except Exception, exc:
|
||||
diag1 = exc.diag
|
||||
|
||||
self.conn.rollback()
|
||||
|
||||
try:
|
||||
cur.execute("select level from water where ducks > 1")
|
||||
except psycopg2.Error, exc:
|
||||
diag2 = exc.diag
|
||||
|
||||
self.assertEqual(diag1.sqlstate, '42601')
|
||||
self.assertEqual(diag2.sqlstate, '42P01')
|
||||
|
||||
def test_diagnostics_from_commit(self):
|
||||
cur = self.conn.cursor()
|
||||
cur.execute("""
|
||||
create temp table test_deferred (
|
||||
data int primary key,
|
||||
ref int references test_deferred (data)
|
||||
deferrable initially deferred)
|
||||
""")
|
||||
cur.execute("insert into test_deferred values (1,2)")
|
||||
try:
|
||||
self.conn.commit()
|
||||
except psycopg2.Error, exc:
|
||||
e = exc
|
||||
self.assertEqual(e.diag.sqlstate, '23503')
|
||||
|
||||
@skip_before_postgres(9, 3)
|
||||
def test_9_3_diagnostics(self):
|
||||
cur = self.conn.cursor()
|
||||
|
|
Loading…
Reference in New Issue
Block a user