Skip to content

Commit 8db2828

Browse files
author
Erlend E. Aasland
committed
Add test for extended error codes
1 parent 9c08365 commit 8db2828

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/sqlite3/test/dbapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ def test_error_code_on_exception(self):
277277
self.assertEqual(e.sqlite_errorcode, sqlite.SQLITE_CANTOPEN)
278278
self.assertEqual(e.sqlite_errorname, "SQLITE_CANTOPEN")
279279

280+
@unittest.skipIf(sqlite.sqlite_version_info <= (3, 10, 0),
281+
"Requires SQLite 3.10.0 or newer")
282+
def test_extended_error_code_on_exception(self):
283+
con = sqlite.connect(":memory:")
284+
with con:
285+
con.execute("create table t(t integer check(t > 0))")
286+
errmsg = "CHECK constraint failed"
287+
with self.assertRaisesRegex(sqlite.IntegrityError, errmsg) as cm:
288+
con.execute("insert into t values(-1)")
289+
exc = cm.exception
290+
self.assertEqual(exc.sqlite_errorcode, sqlite.SQLITE_CONSTRAINT_CHECK)
291+
self.assertEqual(exc.sqlite_errorname, "SQLITE_CONSTRAINT_CHECK")
292+
280293
# sqlite3_enable_shared_cache() is deprecated on macOS and calling it may raise
281294
# OperationalError on some buildbots.
282295
@unittest.skipIf(sys.platform == "darwin", "shared cache is deprecated on macOS")

0 commit comments

Comments
 (0)