8000 gh-135386: Fix "unable to open database file" errors on readonly DB by GeneralK1ng · Pull Request #135566 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135386: Fix "unable to open database file" errors on readonly DB #135566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test: make read-only dbm.sqlite3 test compatible with Windows
  • Loading branch information
GeneralK1ng committed Jun 23, 2025
commit 4561075b3acab2506d34b7c769336a6fb513a5d7
21 changes: 14 additions & 7 deletions Lib/test/test_dbm_sqlite3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import stat
import os
import sys
import unittest
Expand Down Expand Up @@ -90,22 +91,28 @@ def test_readonly_keys(self):
def test_readonly_iter(self):
self.assertEqual([k for k in self.db], [b"key1", b"key2"])

@unittest.skipIf(sys.platform.startswith("win"), "incompatible with Windows file locking")
def test_readonly_open_without_wal_shm(self):
wal_path = self.filename + "-wal"
shm_path = self.filename + "-shm"

for suffix in wal_path, shm_path:
try:
os.remove(suffix)
except FileNotFoundError:
pass
os_helper.unlink(suffix)

os.chmod(self.filename, 0o444)
try:
self.db.close()
except Exception:
pass

with dbm_sqlite3.open(self.filename, "r") as db:
os.chmod(self.filename, stat.S_IREAD)

db = dbm_sqlite3.open(self.filename, "r")
try:
self.assertEqual(db[b"key1"], b"value1")
self.assertEqual(db[b"key2"], b"value2")
finally:
db.close()

os.chmod(self.filename, stat.S_IWRITE)


class ReadWrite(_SQLiteDbmTests):
Expand Down
Loading
0