mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Close #19282: Native context management in dbm
This commit is contained in:
parent
eb8ea265ba
commit
c610aba1ed
8 changed files with 101 additions and 16 deletions
|
@ -37,5 +37,18 @@ class DbmTestCase(unittest.TestCase):
|
|||
except error:
|
||||
self.fail()
|
||||
|
||||
def test_context_manager(self):
|
||||
with dbm.ndbm.open(self.filename, 'c') as db:
|
||||
db["ndbm context manager"] = "context manager"
|
||||
|
||||
with dbm.ndbm.open(self.filename, 'r') as db:
|
||||
self.assertEqual(list(db.keys()), [b"ndbm context manager"])
|
||||
|
||||
with self.assertRaises(dbm.ndbm.error) as cm:
|
||||
db.keys()
|
||||
self.assertEqual(str(cm.exception),
|
||||
"DBM object has already been closed")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue