From c44906429735e9c23774404dc105913f3ff90b7c Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 7 Sep 2020 13:46:12 -0700 Subject: [PATCH] Additional tests for WAL mode This should have been included in 2d2d724e32824095b0bf267a38d9c6fd628cc706 Refs #132 --- tests/test_wal.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/test_wal.py diff --git a/tests/test_wal.py b/tests/test_wal.py new file mode 100644 index 0000000..1303eed --- /dev/null +++ b/tests/test_wal.py @@ -0,0 +1,24 @@ +import pytest +from sqlite_utils import Database +import sqlite3 + + +@pytest.fixture +def db_path_tmpdir(tmpdir): + path = tmpdir / "test.db" + db = Database(str(path)) + return db, path, tmpdir + + +def test_enable_disable_wal(db_path_tmpdir): + db, path, tmpdir = db_path_tmpdir + assert len(tmpdir.listdir()) == 1 + assert "delete" == db.journal_mode + assert "test.db-wal" not in [f.basename for f in tmpdir.listdir()] + db.enable_wal() + assert "wal" == db.journal_mode + db["test"].insert({"foo": "bar"}) + assert "test.db-wal" in [f.basename for f in tmpdir.listdir()] + db.disable_wal() + assert "delete" == db.journal_mode + assert "test.db-wal" not in [f.basename for f in tmpdir.listdir()]