Skip to content

Commit 4561075

Browse files
committed
Test: make read-only dbm.sqlite3 test compatible with Windows
1 parent 66899ff commit 4561075

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Lib/test/test_dbm_sqlite3.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import stat
12
import os
23
import sys
34
import unittest
@@ -90,22 +91,28 @@ def test_readonly_keys(self):
9091
def test_readonly_iter(self):
9192
self.assertEqual([k for k in self.db], [b"key1", b"key2"])
9293

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

9898
for suffix in wal_path, shm_path:
99-
try:
100-
os.remove(suffix)
101-
except FileNotFoundError:
102-
pass
99+
os_helper.unlink(suffix)
103100

104-
os.chmod(self.filename, 0o444)
101+
try:
102+
self.db.close()
103+
except Exception:
104+
pass
105105

106-
with dbm_sqlite3.open(self.filename, "r") as db:
106+
os.chmod(self.filename, stat.S_IREAD)
107+
108+
db = dbm_sqlite3.open(self.filename, "r")
109+
try:
107110
self.assertEqual(db[b"key1"], b"value1")
108111
self.assertEqual(db[b"key2"], b"value2")
112+
finally:
113+
db.close()
114+
115+
os.chmod(self.filename, stat.S_IWRITE)
109116

110117

111118
class ReadWrite(_SQLiteDbmTests):

0 commit comments

Comments
 (0)