[pypy-commit] pypy default: test and fix for _sqlite3.Cursor.__init__ check
bdkearns
noreply at buildbot.pypy.org
Tue Mar 5 02:16:24 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r62033:d085b86816f2
Date: 2013-03-04 20:00 -0500
http://bitbucket.org/pypy/pypy/changeset/d085b86816f2/
Log: test and fix for _sqlite3.Cursor.__init__ check
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -742,6 +742,8 @@
class Cursor(object):
+ initialized = False
+
def __init__(self, con):
if not isinstance(con, Connection):
raise TypeError
@@ -756,8 +758,11 @@
self.statement = None
self.reset = False
self.locked = False
+ self.initialized = True
def _check_closed(self):
+ if not self.initialized:
+ raise ProgrammingError("Base Cursor.__init__ not called.")
if not getattr(self, 'connection', None):
raise ProgrammingError("Cannot operate on a closed cursor.")
self.connection._check_thread()
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -35,6 +35,16 @@
e = pytest.raises(_sqlite3.ProgrammingError, "con.cursor()")
assert '__init__' in e.value.message
+def test_cursor_check_init():
+ class Cursor(_sqlite3.Cursor):
+ def __init__(self, name):
+ pass
+
+ con = _sqlite3.connect(":memory:")
+ cur = Cursor(con)
+ e = pytest.raises(_sqlite3.ProgrammingError, "cur.execute('select 1')")
+ assert '__init__' in e.value.message
+
@pytest.mark.skipif("not hasattr(sys, 'pypy_translation_info')")
def test_connection_del(tmpdir):
"""For issue1325."""
More information about the pypy-commit
mailing list