diff options
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_dbm_dumb.py | 27 | 
1 files changed, 26 insertions, 1 deletions
| diff --git a/Lib/test/test_dbm_dumb.py b/Lib/test/test_dbm_dumb.py index ff63c88..2d77f07 100644 --- a/Lib/test/test_dbm_dumb.py +++ b/Lib/test/test_dbm_dumb.py @@ -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() | 
