mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-09 18:14:09 +02:00
Database(..., execute_plugins=False) mechanism, refs #575
This commit is contained in:
parent
3f80a02698
commit
374a816c72
3 changed files with 24 additions and 15 deletions
|
|
@ -49,10 +49,16 @@ def test_prepare_connection():
|
|||
conn.create_function("hello", 1, lambda name: f"Hello, {name}!")
|
||||
|
||||
db = Database(memory=True)
|
||||
functions = db.execute(
|
||||
"select distinct name from pragma_function_list order by 1"
|
||||
).fetchall()
|
||||
assert "hello" not in functions
|
||||
|
||||
def _functions(db):
|
||||
return [
|
||||
row[0]
|
||||
for row in db.execute(
|
||||
"select distinct name from pragma_function_list order by 1"
|
||||
).fetchall()
|
||||
]
|
||||
|
||||
assert "hello" not in _functions(db)
|
||||
|
||||
try:
|
||||
plugins.pm.register(HelloFunctionPlugin(), name="HelloFunctionPlugin")
|
||||
|
|
@ -62,18 +68,14 @@ def test_prepare_connection():
|
|||
]
|
||||
|
||||
db = Database(memory=True)
|
||||
|
||||
functions = [
|
||||
row[0]
|
||||
for row in db.execute(
|
||||
"select distinct name from pragma_function_list order by 1"
|
||||
).fetchall()
|
||||
]
|
||||
assert "hello" in functions
|
||||
|
||||
assert "hello" in _functions(db)
|
||||
result = db.execute('select hello("world")').fetchone()[0]
|
||||
assert result == "Hello, world!"
|
||||
|
||||
# Test execute_plugins=False
|
||||
db2 = Database(memory=True, execute_plugins=False)
|
||||
assert "hello" not in _functions(db2)
|
||||
|
||||
finally:
|
||||
plugins.pm.unregister(name="HelloFunctionPlugin")
|
||||
assert plugins.get_plugins() == []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue