diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-10-06 13:52:19 +0300 |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-10-06 13:52:19 +0300 |
commit | 9a6ec11c5bce87f27559debad03bcd6a7885e591 (patch) | |
tree | 90e68debc375bb6ef38053e7050dfa06e7e83651 /Lib/test/test_shelve.py | |
parent | 1001d405459b222d52ece207c285122b5a12885b (diff) | |
download | cpython-9a6ec11c5bce87f27559debad03bcd6a7885e591.tar.gz |
Issue #13896: Make shelf instances work with 'with' as context managers.
Original patch by Filip Gruszczy?ski.
Diffstat (limited to 'Lib/test/test_shelve.py')
-rw-r--r-- | Lib/test/test_shelve.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_shelve.py b/Lib/test/test_shelve.py index 13c126566d..bd51d868fe 100644 --- a/Lib/test/test_shelve.py +++ b/Lib/test/test_shelve.py @@ -148,6 +148,19 @@ class TestCase(unittest.TestCase): p2 = d[encodedkey] self.assertNotEqual(p1, p2) # Write creates new object in store + def test_with(self): + d1 = {} + with shelve.Shelf(d1, protocol=2, writeback=False) as s: + s['key1'] = [1,2,3,4] + self.assertEqual(s['key1'], [1,2,3,4]) + self.assertEqual(len(s), 1) + self.assertRaises(ValueError, len, s) + try: + s['key1'] + except ValueError: + pass + else: + self.fail('Closed shelf should not find a key') from test import mapping_tests |