diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-10-06 10:52:19 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-10-06 10:52:19 (GMT) |
commit | ef08fb1f040cb51e752c6b1322008714262fbf3e (patch) | |
tree | a4617bbf91a1a2ca34304e63824838de777fca2e /Lib/test | |
parent | dc22587df2a577cdcdd21f3aec629e22b07f4263 (diff) | |
download | cpython-ef08fb1f040cb51e752c6b1322008714262fbf3e.zip cpython-ef08fb1f040cb51e752c6b1322008714262fbf3e.tar.gz cpython-ef08fb1f040cb51e752c6b1322008714262fbf3e.tar.bz2 |
Issue #13896: Make shelf instances work with 'with' as context managers.
Original patch by Filip GruszczyĆski.
Diffstat (limited to 'Lib/test')
-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 13c1265..bd51d86 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 |