summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dbm_gnu.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-11-17 05:59:51 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-11-17 05:59:51 (GMT)
commitc610aba1ed57a30104a254ccd1f9fe07d02b1334 (patch)
treede690ad2f0b0f9cda831d66f026e5494a77882c5 /Lib/test/test_dbm_gnu.py
parenteb8ea265bac16844efebe4f42d3c674527a66988 (diff)
downloadcpython-c610aba1ed57a30104a254ccd1f9fe07d02b1334.zip
cpython-c610aba1ed57a30104a254ccd1f9fe07d02b1334.tar.gz
cpython-c610aba1ed57a30104a254ccd1f9fe07d02b1334.tar.bz2
Close #19282: Native context management in dbm
Diffstat (limited to 'Lib/test/test_dbm_gnu.py')
-rwxr-xr-xLib/test/test_dbm_gnu.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_dbm_gnu.py b/Lib/test/test_dbm_gnu.py
index 4fb66c5..a7808f5 100755
--- a/Lib/test/test_dbm_gnu.py
+++ b/Lib/test/test_dbm_gnu.py
@@ -81,6 +81,17 @@ class TestGdbm(unittest.TestCase):
size2 = os.path.getsize(filename)
self.assertTrue(size1 > size2 >= size0)
+ def test_context_manager(self):
+ with gdbm.open(filename, 'c') as db:
+ db["gdbm context manager"] = "context manager"
+
+ with gdbm.open(filename, 'r') as db:
+ self.assertEqual(list(db.keys()), [b"gdbm context manager"])
+
+ with self.assertRaises(gdbm.error) as cm:
+ db.keys()
+ self.assertEqual(str(cm.exception),
+ "GDBM object has already been closed")
if __name__ == '__main__':
unittest.main()