mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Issue #21708: Deprecated dbm.dumb behavior that differs from common dbm
behavior: creating a database in 'r' and 'w' modes and modifying a database in 'r' mode.
This commit is contained in:
parent
9862b5194d
commit
0122ae9ac8
5 changed files with 57 additions and 1 deletions
|
@ -6,6 +6,7 @@ import io
|
|||
import operator
|
||||
import os
|
||||
import unittest
|
||||
import warnings
|
||||
import dbm.dumb as dumbdbm
|
||||
from test import support
|
||||
from functools import partial
|
||||
|
@ -78,6 +79,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):
|
||||
|
@ -148,7 +155,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()
|
||||
|
@ -234,6 +241,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()
|
||||
|
||||
def tearDown(self):
|
||||
_delete_files()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue