summaryrefslogtreecommitdiff
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.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py
index 235ab11b61..df531d64e4 100644
--- a/Lib/test/test_dbm_dumb.py
+++ b/Lib/test/test_dbm_dumb.py
@@ -7,6 +7,7 @@ import operator
import os
import stat
import unittest
+import warnings
import dbm.dumb as dumbdbm
from test import support
from functools import partial
@@ -79,6 +80,12 @@ class DumbDBMTestCase(unittest.TestCase):
self.init_db()
f = dumbdbm.open(_fname, 'r')
self.read_helper(f)
+ with self.assertWarnsRegex(DeprecationWarning,
+ 'The database is opened for reading only'):
+ f[b'g'] = b'x'
+ with self.assertWarnsRegex(DeprecationWarning,
+ 'The database is opened for reading only'):
+ del f[b'a']
f.close()
def test_dumbdbm_keys(self):
@@ -149,7 +156,7 @@ class DumbDBMTestCase(unittest.TestCase):
self.assertEqual(self._dict[key], f[key])
def init_db(self):
- f = dumbdbm.open(_fname, 'w')
+ f = dumbdbm.open(_fname, 'n')
for k in self._dict:
f[k] = self._dict[k]
f.close()
@@ -235,6 +242,24 @@ class DumbDBMTestCase(unittest.TestCase):
pass
self.assertEqual(stdout.getvalue(), '')
+ def test_warn_on_ignored_flags(self):
+ for value in ('r', 'w'):
+ _delete_files()
+ with self.assertWarnsRegex(DeprecationWarning,
+ "The database file is missing, the "
+ "semantics of the 'c' flag will "
+ "be used."):
+ f = dumbdbm.open(_fname, value)
+ f.close()
+
+ def test_invalid_flag(self):
+ for flag in ('x', 'rf', None):
+ with self.assertWarnsRegex(DeprecationWarning,
+ "Flag must be one of "
+ "'r', 'w', 'c', or 'n'"):
+ 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: