aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-08-29 15:11:52 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-08-29 15:11:52 +0300
commit8631da64bb1f163026b7be82884f8e5b506e0e66 (patch)
tree8e038d5acc352dfa2d74fa8f476e3017d0c98c97 /Lib/sqlite3
parentIssue #26027: Fix test_path_t_converter on Windows (diff)
parentIssue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory (diff)
downloadcpython-8631da64bb1f163026b7be82884f8e5b506e0e66.tar.gz
cpython-8631da64bb1f163026b7be82884f8e5b506e0e66.tar.bz2
cpython-8631da64bb1f163026b7be82884f8e5b506e0e66.zip
Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
creates not a cursor. Patch by Xiang Zhang.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/test/factory.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py
index f587596f644..ced8445536e 100644
--- a/Lib/sqlite3/test/factory.py
+++ b/Lib/sqlite3/test/factory.py
@@ -58,9 +58,21 @@ class CursorFactoryTests(unittest.TestCase):
self.con.close()
def CheckIsInstance(self):
- cur = self.con.cursor(factory=MyCursor)
+ cur = self.con.cursor()
+ self.assertIsInstance(cur, sqlite.Cursor)
+ cur = self.con.cursor(MyCursor)
+ self.assertIsInstance(cur, MyCursor)
+ cur = self.con.cursor(factory=lambda con: MyCursor(con))
self.assertIsInstance(cur, MyCursor)
+ def CheckInvalidFactory(self):
+ # not a callable at all
+ self.assertRaises(TypeError, self.con.cursor, None)
+ # invalid callable with not exact one argument
+ self.assertRaises(TypeError, self.con.cursor, lambda: None)
+ # invalid callable returning non-cursor
+ self.assertRaises(TypeError, self.con.cursor, lambda con: None)
+
class RowFactoryTestsBackwardsCompat(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:")
@@ -183,10 +195,12 @@ class RowFactoryTests(unittest.TestCase):
def CheckFakeCursorClass(self):
# Issue #24257: Incorrect use of PyObject_IsInstance() caused
# segmentation fault.
+ # Issue #27861: Also applies for cursor factory.
class FakeCursor(str):
__class__ = sqlite.Cursor
- cur = self.con.cursor(factory=FakeCursor)
- self.assertRaises(TypeError, sqlite.Row, cur, ())
+ self.con.row_factory = sqlite.Row
+ self.assertRaises(TypeError, self.con.cursor, FakeCursor)
+ self.assertRaises(TypeError, sqlite.Row, FakeCursor(), ())
def tearDown(self):
self.con.close()