summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dbm_dumb.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_dbm_dumb.py')
-rw-r--r--Lib/test/test_dbm_dumb.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py
index 2d77f07..df531d6 100644
--- a/Lib/test/test_dbm_dumb.py
+++ b/Lib/test/test_dbm_dumb.py
@@ -5,6 +5,7 @@
import io
import operator
import os
+import stat
import unittest
import warnings
import dbm.dumb as dumbdbm
@@ -259,6 +260,21 @@ class DumbDBMTestCase(unittest.TestCase):
f = dumbdbm.open(_fname, flag)
f.close()
+ @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()