mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #28847: dbm.dumb now supports reading read-only files and no longer
writes the index file when it is not changed.
This commit is contained in:
parent
e503126074
commit
028ace1ccb
4 changed files with 28 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
|||
import io
|
||||
import operator
|
||||
import os
|
||||
import stat
|
||||
import unittest
|
||||
import dbm.dumb as dumbdbm
|
||||
from test import support
|
||||
|
@ -234,6 +235,21 @@ class DumbDBMTestCase(unittest.TestCase):
|
|||
pass
|
||||
self.assertEqual(stdout.getvalue(), '')
|
||||
|
||||
@unittest.skipUnless(hasattr(os, 'chmod'), 'test needs os.chmod()')
|
||||
def test_readonly_files(self):
|
||||
with support.temp_dir() as dir:
|
||||
fname = os.path.join(dir, 'db')
|
||||
with dumbdbm.open(fname, 'n') as f:
|
||||
self.assertEqual(list(f.keys()), [])
|
||||
for key in self._dict:
|
||||
f[key] = self._dict[key]
|
||||
os.chmod(fname + ".dir", stat.S_IRUSR)
|
||||
os.chmod(fname + ".dat", stat.S_IRUSR)
|
||||
os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
|
||||
with dumbdbm.open(fname, 'r') as f:
|
||||
self.assertEqual(sorted(f.keys()), sorted(self._dict))
|
||||
f.close() # don't write
|
||||
|
||||
def tearDown(self):
|
||||
_delete_files()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue