Issue #28847: dubmdbm no longer writes the index file in when it is not
changed and supports reading read-only files.
diff --git a/Lib/test/test_dumbdbm.py b/Lib/test/test_dumbdbm.py
index 6520efd..024ddda 100644
--- a/Lib/test/test_dumbdbm.py
+++ b/Lib/test/test_dumbdbm.py
@@ -3,6 +3,7 @@
"""
import os
+import stat
import unittest
import dumbdbm
from test import test_support
@@ -168,6 +169,26 @@
dumbdbm.open(_fname).close()
self.assertEqual(stdout.getvalue(), '')
+ @unittest.skipUnless(hasattr(os, 'chmod'), 'test needs os.chmod()')
+ def test_readonly_files(self):
+ dir = _fname
+ os.mkdir(dir)
+ try:
+ fname = os.path.join(dir, 'db')
+ f = dumbdbm.open(fname, 'n')
+ self.assertEqual(list(f.keys()), [])
+ for key in self._dict:
+ f[key] = self._dict[key]
+ f.close()
+ os.chmod(fname + ".dir", stat.S_IRUSR)
+ os.chmod(fname + ".dat", stat.S_IRUSR)
+ os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
+ f = dumbdbm.open(fname, 'r')
+ self.assertEqual(sorted(f.keys()), sorted(self._dict))
+ f.close() # don't write
+ finally:
+ test_support.rmtree(dir)
+
def tearDown(self):
_delete_files()