Skip to content

Commit fa1d5d0

Browse files
committed
test_wal_preservation: fix test on Darwin (MacOS and iPhone)
1 parent 5ddea3b commit fa1d5d0

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,11 @@ def test_database_keyword(self):
728728
with contextlib.closing(sqlite.connect(database=":memory:")) as cx:
729729
self.assertEqual(type(cx), sqlite.Connection)
730730

731-
# @hashbrowncipher skipped this test on mac, don't know why, rerunning to test it
732731
def test_wal_preservation(self):
733732
with tempfile.TemporaryDirectory() as dirname:
734733
path = os.path.join(dirname, "db.sqlite")
734+
735+
# Set flag to 1, check that WAL file is not deleted on close:
735736
with contextlib.closing(sqlite.connect(path)) as cx:
736737
cx.file_control(sqlite.SQLITE_FCNTL_PERSIST_WAL, 1)
737738
# Check that it was set successfully:
@@ -746,10 +747,20 @@ def test_wal_preservation(self):
746747
self.assertTrue(os.path.exists(path + "-wal"))
747748
self.assertTrue(os.path.exists(path + "-wal"))
748749

750+
# Set flag to 0, check that WAL file is deleted on close:
749751
with contextlib.closing(sqlite.connect(path)) as cx:
750752
# Check that we can read the default value when we didn't set it explicitly:
751753
rc = cx.file_control(sqlite.SQLITE_FCNTL_PERSIST_WAL, -1)
752-
assert rc == 0, f"SQLITE_FCNTL_PERSIST_WAL should be 0 by default, not {rc}"
754+
755+
# The default value should be 0, but on MacOS when compiling with the SDK (not a
756+
# custom build of SQLite) it defaults to 0, perhaps customised by Apple?
757+
default_value = (1 if sys.platform == "darwin" else 0)
758+
assert rc == default_value, f"SQLITE_FCNTL_PERSIST_WAL should be {default_value} " \
759+
"by default, not {rc}"
760+
761+
# Set it to 0 explicitly so that this test passes on Darwin too:
762+
rc = cx.file_control(sqlite.SQLITE_FCNTL_PERSIST_WAL, 0)
763+
assert rc == 0, f"cx.file_control(SQLITE_FCNTL_PERSIST_WAL) failed to set flag"
753764

754765
cu = cx.cursor()
755766
self.assertTrue(os.path.exists(path + "-wal"))

0 commit comments

Comments
 (0)