Skip to content
Prev Previous commit
Next Next commit
simplify tests
  • Loading branch information
picnixz committed Dec 29, 2025
commit 80058035011c3edaaa9a49cd81d453d57e1f326a
51 changes: 21 additions & 30 deletions Lib/test/test_sqlite3/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,25 @@ def test_authorizer_invalid_signature(self):
def test_authorizer_concurrent_mutation_in_call(self):
self.cx.execute("create table if not exists test(a number)")

class Handler:
cx = self.cx
def __call__(self, *a, **kw):
self.cx.set_authorizer(None)
raise ZeroDivisionError("hello world")
def handler(*a, **kw):
self.cx.set_authorizer(None)
raise ZeroDivisionError("hello world")

self.cx.set_authorizer(Handler())
self.cx.set_authorizer(handler)
self.assert_not_authorized(self.cx.execute, "select * from test")

@with_tracebacks(OverflowError)
def test_authorizer_concurrent_mutation_with_overflown_value(self):
_testcapi = import_helper.import_module("_testcapi")
self.cx.execute("create table if not exists test(a number)")

class Handler:
cx = self.cx
def __call__(self, *a, **kw):
self.cx.set_authorizer(None)
# We expect 'int' at the C level, so this one will raise
# when converting via PyLong_Int().
return _testcapi.INT_MAX + 1

self.cx.set_authorizer(Handler())
def handler(*a, **kw):
self.cx.set_authorizer(None)
# We expect 'int' at the C level, so this one will raise
# when converting via PyLong_Int().
return _testcapi.INT_MAX + 1

self.cx.set_authorizer(handler)
self.assert_not_authorized(self.cx.execute, "select * from test")


Expand Down Expand Up @@ -294,21 +290,18 @@ def test_progress_handler_invalid_signature(self):
def test_progress_handler_concurrent_mutation_in_call(self):
self.cx.execute("create table if not exists test(a number)")

class Handler:
cx = self.cx
def __call__(self, *a, **kw):
self.cx.set_progress_handler(None, 1)
raise ZeroDivisionError("hello world")
def handler(*a, **kw):
self.cx.set_progress_handler(None, 1)
raise ZeroDivisionError("hello world")

self.cx.set_progress_handler(Handler(), 1)
self.cx.set_progress_handler(handler, 1)
self.assert_interrupted(self.cx.execute, "select * from test")

def test_progress_handler_concurrent_mutation_in_conversion(self):
self.cx.execute("create table if not exists test(a number)")

class Handler:
cx = self.cx
def __bool__(self):
def __bool__(_):
# clear the progress handler
self.cx.set_progress_handler(None, 1)
raise ValueError # force PyObject_True() to fail
Expand Down Expand Up @@ -466,14 +459,12 @@ def test_trace_handler_invalid_signature(self):
def test_trace_callback_concurrent_mutation_in_call(self):
self.cx.execute("create table if not exists test(a number)")

class Handler:
cx = self.cx
def __call__(self, statement):
# clear the progress handler
self.cx.set_trace_callback(None)
raise ZeroDivisionError("hello world")
def handler(statement):
# clear the progress handler
self.cx.set_trace_callback(None)
raise ZeroDivisionError("hello world")

self.cx.set_trace_callback(Handler())
self.cx.set_trace_callback(handler)
self.cx.execute("select * from test")


Expand Down
Loading