[loop-cycle-50] refactor: replace bare sqlite3.connect() with context managers batch 2 (#157) (#180)
All checks were successful
Tests / lint (push) Successful in 4s
Tests / test (push) Successful in 1m55s

This commit was merged in pull request #180.
This commit is contained in:
2026-03-15 11:58:43 -04:00
parent bea2749158
commit bcd6d7e321
16 changed files with 512 additions and 510 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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