Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b23df1

Browse files
author
Erlend E. Aasland
committed
Add tests that exercise stuff against a closed database
1 parent 7d8014a commit 1b23df1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/sqlite3/test/dbapi.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ def test_failed_open(self):
135135
def test_close(self):
136136
self.cx.close()
137137

138+
def test_use_after_close(self):
139+
sql = "select 1"
140+
cu = self.cx.cursor()
141+
res = cu.execute(sql)
142+
self.cx.close()
143+
self.assertRaises(sqlite.ProgrammingError, res.fetchall)
144+
self.assertRaises(sqlite.ProgrammingError, cu.execute, sql)
145+
self.assertRaises(sqlite.ProgrammingError, cu.executemany, sql, [])
146+
self.assertRaises(sqlite.ProgrammingError, cu.executescript, sql)
147+
self.assertRaises(sqlite.ProgrammingError, self.cx.execute, sql)
148+
self.assertRaises(sqlite.ProgrammingError,
149+
self.cx.executemany, sql, [])
150+
self.assertRaises(sqlite.ProgrammingError, self.cx.executescript, sql)
151+
self.assertRaises(sqlite.ProgrammingError,
152+
self.cx.create_function, "t", 1, lambda x: x)
153+
with self.assertRaises(sqlite.ProgrammingError):
154+
with self.cx:
155+
pass
156+
138157
def test_exceptions(self):
139158
# Optional DB-API extension.
140159
self.assertEqual(self.cx.Warning, sqlite.Warning)

0 commit comments

Comments
 (0)