diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-07 11:00:06 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-12-07 11:00:06 +0200 |
commit | 3e1d42acbdcfaf69778453a2a0ad47729963fcee (patch) | |
tree | d799235462b0950b93b8ea95235cccc2f42070da /Lib/test | |
parent | 4526abdc73ceda08bd5f1b6fa04d0f1cad973bff (diff) | |
parent | 63b87a4f7a5e98f1e9a388128e2a5af7de199ce4 (diff) | |
download | cpython-3e1d42acbdcfaf69778453a2a0ad47729963fcee.tar.gz |
Issue #28847: dbm.dumb now supports reading read-only files and no longer
writes the index file when it is not changed.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/support/__init__.py | 4 | ||||
-rw-r--r-- | Lib/test/test_dbm_dumb.py | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 52c908e028..1e27777517 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -360,9 +360,9 @@ if sys.platform.startswith("win"): mode = 0 if stat.S_ISDIR(mode): _waitfor(_rmtree_inner, fullname, waitall=True) - _force_run(path, os.rmdir, fullname) + _force_run(fullname, os.rmdir, fullname) else: - _force_run(path, os.unlink, fullname) + _force_run(fullname, os.unlink, fullname) _waitfor(_rmtree_inner, path, waitall=True) _waitfor(lambda p: _force_run(p, os.rmdir, p), path) else: diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py index 2d77f078b7..df531d64e4 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() |