Close #19282: Native context management in dbm

This commit is contained in:
Nick Coghlan 2013-11-17 15:59:51 +10:00
parent eb8ea265ba
commit c610aba1ed
8 changed files with 101 additions and 16 deletions

View file

@ -184,6 +184,19 @@ class DumbDBMTestCase(unittest.TestCase):
self.assertEqual(expected, got)
f.close()
def test_context_manager(self):
with dumbdbm.open(_fname, 'c') as db:
db["dumbdbm context manager"] = "context manager"
with dumbdbm.open(_fname, 'r') as db:
self.assertEqual(list(db.keys()), [b"dumbdbm context manager"])
# This currently just raises AttributeError rather than a specific
# exception like the GNU or NDBM based implementations. See
# http://bugs.python.org/issue19385 for details.
with self.assertRaises(Exception):
db.keys()
def tearDown(self):
_delete_files()