summaryrefslogtreecommitdiff
path: root/Lib/test/test_dbm_dumb.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2017-02-01 22:37:49 +0300
committerBerker Peksag <berker.peksag@gmail.com>2017-02-01 22:37:49 +0300
commita706118dafc16edfed490c53db02c08aefe7b097 (patch)
tree6416a9ea3398ea769857b79a8036f9ffe098c95e /Lib/test/test_dbm_dumb.py
parent1966772d17f49c740be143d9d4622be13e850f15 (diff)
parentba5a055a00d91a449a23ae14dd468e9b769a6b74 (diff)
downloadcpython-a706118dafc16edfed490c53db02c08aefe7b097.tar.gz
Issue #29407: Merge from 3.5
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: