[loop-cycle-50] refactor: replace bare sqlite3.connect() with context managers batch 2 (#157) (#180)
This commit was merged in pull request #180.
This commit is contained in:
@@ -216,21 +216,15 @@ class TestWALMode:
|
||||
with patch("infrastructure.models.registry.DB_PATH", db):
|
||||
from infrastructure.models.registry import _get_conn
|
||||
|
||||
conn = _get_conn()
|
||||
try:
|
||||
with _get_conn() as conn:
|
||||
mode = conn.execute("PRAGMA journal_mode").fetchone()[0]
|
||||
assert mode == "wal"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def test_registry_db_busy_timeout(self, tmp_path):
|
||||
db = tmp_path / "wal_test.db"
|
||||
with patch("infrastructure.models.registry.DB_PATH", db):
|
||||
from infrastructure.models.registry import _get_conn
|
||||
|
||||
conn = _get_conn()
|
||||
try:
|
||||
with _get_conn() as conn:
|
||||
timeout = conn.execute("PRAGMA busy_timeout").fetchone()[0]
|
||||
assert timeout == 5000
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -481,29 +481,20 @@ class TestWALMode:
|
||||
def test_spark_memory_uses_wal(self):
|
||||
from spark.memory import _get_conn
|
||||
|
||||
conn = _get_conn()
|
||||
try:
|
||||
with _get_conn() as conn:
|
||||
mode = conn.execute("PRAGMA journal_mode").fetchone()[0]
|
||||
assert mode == "wal", f"Expected WAL mode, got {mode}"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def test_spark_eidos_uses_wal(self):
|
||||
from spark.eidos import _get_conn
|
||||
|
||||
conn = _get_conn()
|
||||
try:
|
||||
with _get_conn() as conn:
|
||||
mode = conn.execute("PRAGMA journal_mode").fetchone()[0]
|
||||
assert mode == "wal", f"Expected WAL mode, got {mode}"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def test_spark_memory_busy_timeout(self):
|
||||
from spark.memory import _get_conn
|
||||
|
||||
conn = _get_conn()
|
||||
try:
|
||||
with _get_conn() as conn:
|
||||
timeout = conn.execute("PRAGMA busy_timeout").fetchone()[0]
|
||||
assert timeout == 5000
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -142,14 +142,13 @@ class TestExpireOld:
|
||||
# Create item and manually backdate it
|
||||
item = create_item("Old", "D", "A", db_path=db_path)
|
||||
|
||||
conn = _get_conn(db_path)
|
||||
old_date = (datetime.now(UTC) - timedelta(days=30)).isoformat()
|
||||
conn.execute(
|
||||
"UPDATE approval_items SET created_at = ? WHERE id = ?",
|
||||
(old_date, item.id),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
with _get_conn(db_path) as conn:
|
||||
conn.execute(
|
||||
"UPDATE approval_items SET created_at = ? WHERE id = ?",
|
||||
(old_date, item.id),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
count = expire_old(db_path)
|
||||
assert count == 1
|
||||
@@ -169,14 +168,13 @@ class TestExpireOld:
|
||||
approve(item.id, db_path)
|
||||
|
||||
# Backdate it
|
||||
conn = _get_conn(db_path)
|
||||
old_date = (datetime.now(UTC) - timedelta(days=30)).isoformat()
|
||||
conn.execute(
|
||||
"UPDATE approval_items SET created_at = ? WHERE id = ?",
|
||||
(old_date, item.id),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
with _get_conn(db_path) as conn:
|
||||
conn.execute(
|
||||
"UPDATE approval_items SET created_at = ? WHERE id = ?",
|
||||
(old_date, item.id),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
count = expire_old(db_path)
|
||||
assert count == 0 # approved items not expired
|
||||
|
||||
Reference in New Issue
Block a user