mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
db.close() method, closes #504
This commit is contained in:
parent
ba7242b1f2
commit
05e2bb85fc
2 changed files with 18 additions and 0 deletions
|
|
@ -336,6 +336,10 @@ class Database:
|
|||
self._registered_functions: set = set()
|
||||
self.use_counts_table = use_counts_table
|
||||
|
||||
def close(self):
|
||||
"Close the SQLite connection, and the underlying database file"
|
||||
self.conn.close()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tracer(self, tracer: Callable = None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
from sqlite_utils import Database
|
||||
from sqlite_utils.utils import sqlite3
|
||||
import pytest
|
||||
|
||||
|
||||
def test_recursive_triggers():
|
||||
|
|
@ -25,3 +27,15 @@ def test_sqlite_version():
|
|||
as_string = ".".join(map(str, version))
|
||||
actual = next(db.query("select sqlite_version() as v"))["v"]
|
||||
assert actual == as_string
|
||||
|
||||
|
||||
@pytest.mark.parametrize("memory", [True, False])
|
||||
def test_database_close(tmpdir, memory):
|
||||
if memory:
|
||||
db = Database(memory=True)
|
||||
else:
|
||||
db = Database(str(tmpdir / "test.db"))
|
||||
assert db.execute("select 1 + 1").fetchone()[0] == 2
|
||||
db.close()
|
||||
with pytest.raises(sqlite3.ProgrammingError):
|
||||
db.execute("select 1 + 1")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue